[RFC PATCH 2/5] fs/proc: Introduce /proc/all/statm

From: Eugene Lubarsky
Date: Mon Aug 10 2020 - 10:59:31 EST


Returns statm lines for all visible processes with prepended PIDs.

Signed-off-by: Eugene Lubarsky <elubarsky.linux@xxxxxxxxx>
---
fs/proc/base.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index e0f60a1528b7..8396a38ba7d2 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -3884,6 +3884,18 @@ static int proc_all_stat(struct seq_file *m, void *v)
return proc_tgid_stat(m, iter->ns, iter->tgid_iter.task->thread_pid, iter->tgid_iter.task);
}

+static int proc_all_statm(struct seq_file *m, void *v)
+{
+ struct all_iter *iter = (struct all_iter *) v;
+ struct pid_namespace *ns = iter->ns;
+ struct task_struct *task = iter->tgid_iter.task;
+ struct pid *pid = task->thread_pid;
+
+ seq_put_decimal_ull(m, "", pid_nr_ns(pid, ns));
+ seq_puts(m, " ");
+ return proc_pid_statm(m, ns, pid, task);
+}
+

#define PROC_ALL_OPS(NAME) static const struct seq_operations proc_all_##NAME##_ops = { \
.start = proc_all_start, \
@@ -3893,6 +3905,7 @@ static int proc_all_stat(struct seq_file *m, void *v)
}

PROC_ALL_OPS(stat);
+PROC_ALL_OPS(statm);

#define PROC_ALL_CREATE(NAME) \
do { \
@@ -3908,4 +3921,5 @@ void __init proc_all_init(void)
return;

PROC_ALL_CREATE(stat);
+ PROC_ALL_CREATE(statm);
}
--
2.25.1