Commit 5c5ab971 authored by Alexey Dobriyan's avatar Alexey Dobriyan Committed by Linus Torvalds

proc: speed up /proc/*/statm

top(1) reads all /proc/*/statm files but kernel threads will always have
zeros.  Print those zeroes directly without going through
seq_put_decimal_ull().

Speed up reading /proc/2/statm (which is kthreadd) is like 3%.

My system has more kernel threads than normal processes after booting KDE.
Signed-off-by: default avatarAlexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Link: http://lkml.kernel.org/r/20200307154435.GA2788@avx2Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent d919b33d
...@@ -635,13 +635,18 @@ int proc_tgid_stat(struct seq_file *m, struct pid_namespace *ns, ...@@ -635,13 +635,18 @@ int proc_tgid_stat(struct seq_file *m, struct pid_namespace *ns,
int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns, int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
struct pid *pid, struct task_struct *task) struct pid *pid, struct task_struct *task)
{ {
unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
struct mm_struct *mm = get_task_mm(task); struct mm_struct *mm = get_task_mm(task);
if (mm) { if (mm) {
unsigned long size;
unsigned long resident = 0;
unsigned long shared = 0;
unsigned long text = 0;
unsigned long data = 0;
size = task_statm(mm, &shared, &text, &data, &resident); size = task_statm(mm, &shared, &text, &data, &resident);
mmput(mm); mmput(mm);
}
/* /*
* For quick read, open code by putting numbers directly * For quick read, open code by putting numbers directly
* expected format is * expected format is
...@@ -656,7 +661,9 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns, ...@@ -656,7 +661,9 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
seq_put_decimal_ull(m, " ", data); seq_put_decimal_ull(m, " ", data);
seq_put_decimal_ull(m, " ", 0); seq_put_decimal_ull(m, " ", 0);
seq_putc(m, '\n'); seq_putc(m, '\n');
} else {
seq_write(m, "0 0 0 0 0 0 0\n", 14);
}
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment