mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "David Wang" <00107082@163.com>
To: linux-kernel@vger.kernel.org
Subject: [proc/vmstat]set nr_kernel_stack in vmstat to nr_threads
Date: Thu, 5 Jan 2023 22:24:55 +0800 (CST)	[thread overview]
Message-ID: <41beab3a.4f68.1858252166b.Coremail.00107082@163.com> (raw)

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


                 reply	other threads:[~2023-01-05 14:26 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=41beab3a.4f68.1858252166b.Coremail.00107082@163.com \
    --to=00107082@163.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®