[PATCH 12/15] print_integer, proc: rewrite /proc/*/statm via print_integer()

From: Alexey Dobriyan
Date: Mon Apr 20 2020 - 16:58:38 EST


Signed-off-by: Alexey Dobriyan <adobriyan@xxxxxxxxx>
---
fs/proc/array.c | 32 ++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 6986f9f68ab7..16d66538fa61 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -695,24 +695,28 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
unsigned long shared = 0;
unsigned long text = 0;
unsigned long data = 0;
+ char buf[5 * LEN_UL + 9];
+ char *p = buf + sizeof(buf);

size = task_statm(mm, &shared, &text, &data, &resident);
mmput(mm);

- /*
- * For quick read, open code by putting numbers directly
- * expected format is
- * seq_printf(m, "%lu %lu %lu %lu 0 %lu 0\n",
- * size, resident, shared, text, data);
- */
- seq_put_decimal_ull(m, "", size);
- seq_put_decimal_ull(m, " ", resident);
- seq_put_decimal_ull(m, " ", shared);
- seq_put_decimal_ull(m, " ", text);
- seq_put_decimal_ull(m, " ", 0);
- seq_put_decimal_ull(m, " ", data);
- seq_put_decimal_ull(m, " ", 0);
- seq_putc(m, '\n');
+ *--p = '\n';
+ *--p = '0';
+ *--p = ' ';
+ p = _print_integer_ul(p, data);
+ *--p = ' ';
+ *--p = '0';
+ *--p = ' ';
+ p = _print_integer_ul(p, text);
+ *--p = ' ';
+ p = _print_integer_ul(p, shared);
+ *--p = ' ';
+ p = _print_integer_ul(p, resident);
+ *--p = ' ';
+ p = _print_integer_ul(p, size);
+
+ seq_write(m, p, buf + sizeof(buf) - p);
} else {
seq_write(m, "0 0 0 0 0 0 0\n", 14);
}
--
2.24.1