[PATCH 15/15] print_integer, proc: rewrite /proc/meminfo via print_integer()
From: Alexey Dobriyan
Date: Mon Apr 20 2020 - 16:58:32 EST
This actually makes /proc/meminfo slower, I need to check what's
going on.
Signed-off-by: Alexey Dobriyan <adobriyan@xxxxxxxxx>
---
fs/proc/meminfo.c | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
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;
--
2.24.1