fs/proc/array.c: slightly improve render_sigset_t
authorRasmus Villemoes <[email protected]>
Tue, 13 Dec 2016 00:45:25 +0000 (16:45 -0800)
committerLinus Torvalds <[email protected]>
Tue, 13 Dec 2016 02:55:09 +0000 (18:55 -0800)
format_decode and vsnprintf occasionally show up in perf top, so I went
looking for places that might not need the full printf power.  With the
help of kprobes, I gathered some statistics on which format strings we
mostly pass to vsnprintf.  On a trivial desktop workload, I hit "%x" 25%
of the time, so something apparently reads /proc/pid/status (which does
5*16 printf("%x") calls) a lot.

With this patch, reading /proc/pid/status is 30% faster according to
this microbenchmark:

char buf[4096];
int i, fd;
for (i = 0; i < 10000; ++i) {
fd = open("/proc/self/status", O_RDONLY);
read(fd, buf, sizeof(buf));
close(fd);
}

Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Rasmus Villemoes <[email protected]>
Acked-by: Andrei Vagin <[email protected]>
Acked-by: Kees Cook <[email protected]>
Cc: Alexey Dobriyan <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
fs/proc/array.c

index 082676ab4878b177cc04b5ec60add2fa98519406..51a4213afa2e26a14808634f7d3d2e7bbd804e16 100644 (file)
@@ -245,7 +245,7 @@ void render_sigset_t(struct seq_file *m, const char *header,
                if (sigismember(set, i+2)) x |= 2;
                if (sigismember(set, i+3)) x |= 4;
                if (sigismember(set, i+4)) x |= 8;
-               seq_printf(m, "%x", x);
+               seq_putc(m, hex_asc[x]);
        } while (i >= 4);
 
        seq_putc(m, '\n');