[PATCH 12/13] proc: convert /proc/*/statm to _print_integer()

From: Alexey Dobriyan
Date: Mon Aug 27 2018 - 19:15:48 EST


Benchmark pread("/proc/self/statm") 2^23 times:

6.135596793 seconds time elapsed ( +- 0.11% )
5.685442773 seconds time elapsed ( +- 0.11% )

-7.3%

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

diff --git a/fs/proc/array.c b/fs/proc/array.c
index 5016e03a4dba..d0565527166a 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -627,27 +627,27 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
{
unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
struct mm_struct *mm = get_task_mm(task);
+ /* "%lu %lu %lu %lu 0 %lu 0\n" */
+ char buf[5 * ((sizeof(long) * 5 / 2) + 1) + 2 + 2];
+ char *p = buf + sizeof(buf);

if (mm) {
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');

- return 0;
+ p = memcpy(p - 3, " 0\n", 3);
+ p = _print_integer_ul(p, data);
+ p = memcpy(p - 3, " 0 ", 3);
+ 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);
+
+ return seq_write(m, p, buf + sizeof(buf) - p);
}

#ifdef CONFIG_PROC_CHILDREN
--
2.16.4