[proc/vmstat]set nr_kernel_stack in vmstat to nr_threads

From: David Wang
Date: Thu Jan 05 2023 - 09:26:05 EST


nr_kernel_stack in /proc/vmstat is very confusing, its value is now the same as KernelStack in /proc/meminfo,
indicating kernel stack memory usage in KB. It would be helpful to expose a stat about the number of kernel thread,
(the sysinfo syscall return a proc number with type U16, overflow would happen). This patch set nr_kernel_stack in /proc/vmstat
to a value defined by a global variable nr_threads.

--
diff --git a/mm/vmstat.c b/mm/vmstat.c
index 1ea6a5ce1c41..0040beaa1b24 100644
--- a/mm/vmstat.c
+++ b/mm/vmstat.c
@@ -28,6 +28,7 @@
#include <linux/mm_inline.h>
#include <linux/page_ext.h>
#include <linux/page_owner.h>
+#include <linux/sched/stat.h>

#include "internal.h"

@@ -1831,9 +1832,20 @@ static int vmstat_show(struct seq_file *m, void *arg)
{
unsigned long *l = arg;
unsigned long off = l - (unsigned long *)m->private;
-
+ static long nks_i = -1; // index for nr_kernel_stack
+ if (nks_i < 0 && nks_i > -128) {
+ if (strcmp("nr_kernel_stack", vmstat_text[off]) == 0) {
+ nks_i = off;
+ } else {
+ nks_i--;
+ }
+ }
seq_puts(m, vmstat_text[off]);
- seq_put_decimal_ull(m, " ", *l);
+ if (nks_i == off) {
+ seq_put_decimal_ull(m, " ", nr_threads);
+ } else {
+ seq_put_decimal_ull(m, " ", *l);
+ }
seq_putc(m, '\n');

if (off == NR_VMSTAT_ITEMS - 1) {

--


David