diff mbox series

[15/15] print_integer, proc: rewrite /proc/meminfo via print_integer()

Message ID 20200420205743.19964-15-adobriyan@gmail.com (mailing list archive)
State New, archived
Headers show
Series [01/15] sched: make nr_running() return "unsigned int" | expand

Commit Message

Alexey Dobriyan April 20, 2020, 8:57 p.m. UTC
This actually makes /proc/meminfo slower, I need to check what's
going on.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
---
 fs/proc/meminfo.c | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index 8c1f1bb1a5ce..6dff2298cc3f 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -24,12 +24,24 @@  void __attribute__((weak)) arch_report_meminfo(struct seq_file *m)
 {
 }
 
-static void show_val_kb(struct seq_file *m, const char *s, unsigned long num)
+static void _show_val_kb(struct seq_file *m, const char *s, size_t len,
+			 unsigned long num)
 {
-	seq_put_decimal_ull_width(m, s, num << (PAGE_SHIFT - 10), 8);
-	seq_write(m, " kB\n", 4);
+	char buf[64];
+	char *p = buf + sizeof(buf);
+	char *tmp;
+
+	p = memcpy(p - 4, " kB\n", 4);
+	tmp = memcpy(p - 8, "        ", 8);
+	p = _print_integer_ul(p, num << (PAGE_SHIFT - 10));
+	p = min(p, tmp);
+	p = memcpy(p - len, s, len);
+
+	seq_write(m, p, buf + sizeof(buf) - p);
 }
 
+#define show_val_kb(m, s, n) _show_val_kb((m), (s), strlen(s), (n))
+
 static int meminfo_proc_show(struct seq_file *m, void *v)
 {
 	struct sysinfo i;