lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180827231503.26899-12-adobriyan@gmail.com>
Date:   Tue, 28 Aug 2018 02:15:02 +0300
From:   Alexey Dobriyan <adobriyan@...il.com>
To:     akpm@...ux-foundation.org
Cc:     linux-kernel@...r.kernel.org, Alexey Dobriyan <adobriyan@...il.com>
Subject: [PATCH 12/13] proc: convert /proc/*/statm to _print_integer()

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@...il.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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ