lkml.org 
[lkml]   [2018]   [Aug]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 12/13] proc: convert /proc/*/statm to _print_integer()
Date
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@gmail.com>
---
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
\
 
 \ /
  Last update: 2018-08-28 01:16    [W:0.116 / U:1.200 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site