Commit 48dffbf8 authored by Andrei Vagin's avatar Andrei Vagin Committed by Linus Torvalds

proc: optimize single-symbol delimiters to spead up seq_put_decimal_ull

A delimiter is a string which is printed before a number.  A
syngle-symbol delimiters can be printed by set_putc() and this works
faster than printing by set_puts().

== test_proc.c

int main(int argc, char **argv)
{
	int n, i, fd;
	char buf[16384];

	n = atoi(argv[1]);
	for (i = 0; i < n; i++) {
		fd = open(argv[2], O_RDONLY);
		if (fd < 0)
			return 1;
		if (read(fd, buf, sizeof(buf)) <= 0)
			return 1;
		close(fd);
	}

	return 0;
}
==

$ time ./test_proc  1000000 /proc/1/stat

== Before patch ==
  real	0m3.820s
  user	0m0.337s
  sys	0m3.394s

== After patch ==
  real	0m3.110s
  user	0m0.324s
  sys	0m2.700s

Link: http://lkml.kernel.org/r/20180212074931.7227-3-avagin@openvz.orgSigned-off-by: default avatarAndrei Vagin <avagin@openvz.org>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent f6640663
...@@ -693,12 +693,12 @@ void seq_put_decimal_ull_width(struct seq_file *m, const char *delimiter, ...@@ -693,12 +693,12 @@ void seq_put_decimal_ull_width(struct seq_file *m, const char *delimiter,
if (m->count + 2 >= m->size) /* we'll write 2 bytes at least */ if (m->count + 2 >= m->size) /* we'll write 2 bytes at least */
goto overflow; goto overflow;
len = strlen(delimiter); if (delimiter && delimiter[0]) {
if (m->count + len >= m->size) if (delimiter[1] == 0)
goto overflow; seq_putc(m, delimiter[0]);
else
memcpy(m->buf + m->count, delimiter, len); seq_puts(m, delimiter);
m->count += len; }
if (!width) if (!width)
width = 1; width = 1;
...@@ -782,12 +782,12 @@ void seq_put_decimal_ll(struct seq_file *m, const char *delimiter, long long num ...@@ -782,12 +782,12 @@ void seq_put_decimal_ll(struct seq_file *m, const char *delimiter, long long num
if (m->count + 3 >= m->size) /* we'll write 2 bytes at least */ if (m->count + 3 >= m->size) /* we'll write 2 bytes at least */
goto overflow; goto overflow;
len = strlen(delimiter); if (delimiter && delimiter[0]) {
if (m->count + len >= m->size) if (delimiter[1] == 0)
goto overflow; seq_putc(m, delimiter[0]);
else
memcpy(m->buf + m->count, delimiter, len); seq_puts(m, delimiter);
m->count += len; }
if (m->count + 2 >= m->size) if (m->count + 2 >= m->size)
goto overflow; goto overflow;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment