Alexey Dobriyan
90191f71d7
proc: much faster /proc/vmstat
...
commit 68ba0326b4e14988f9e0c24a6e12a85cf2acd1ca upstream.
Every current KDE system has process named ksysguardd polling files
below once in several seconds:
$ strace -e trace=open -p $(pidof ksysguardd)
Process 1812 attached
open("/etc/mtab", O_RDONLY|O_CLOEXEC) = 8
open("/etc/mtab", O_RDONLY|O_CLOEXEC) = 8
open("/proc/net/dev", O_RDONLY) = 8
open("/proc/net/wireless", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/proc/stat", O_RDONLY) = 8
open("/proc/vmstat", O_RDONLY) = 8
Hell knows what it is doing but speed up reading /proc/vmstat by 33%!
Benchmark is open+read+close 1.000.000 times.
BEFORE
$ perf stat -r 10 taskset -c 3 ./proc-vmstat
Performance counter stats for 'taskset -c 3 ./proc-vmstat' (10 runs):
13146.768464 task-clock (msec) # 0.960 CPUs utilized ( +- 0.60% )
15 context-switches # 0.001 K/sec ( +- 1.41% )
1 cpu-migrations # 0.000 K/sec ( +- 11.11% )
104 page-faults # 0.008 K/sec ( +- 0.57% )
45,489,799,349 cycles # 3.460 GHz ( +- 0.03% )
9,970,175,743 stalled-cycles-frontend # 21.92% frontend cycles idle ( +- 0.10% )
2,800,298,015 stalled-cycles-backend # 6.16% backend cycles idle ( +- 0.32% )
79,241,190,850 instructions # 1.74 insn per cycle
# 0.13 stalled cycles per insn ( +- 0.00% )
17,616,096,146 branches # 1339.956 M/sec ( +- 0.00% )
176,106,232 branch-misses # 1.00% of all branches ( +- 0.18% )
13.691078109 seconds time elapsed ( +- 0.03% )
^^^^^^^^^^^^
AFTER
$ perf stat -r 10 taskset -c 3 ./proc-vmstat
Performance counter stats for 'taskset -c 3 ./proc-vmstat' (10 runs):
8688.353749 task-clock (msec) # 0.950 CPUs utilized ( +- 1.25% )
10 context-switches # 0.001 K/sec ( +- 2.13% )
1 cpu-migrations # 0.000 K/sec
104 page-faults # 0.012 K/sec ( +- 0.56% )
30,384,010,730 cycles # 3.497 GHz ( +- 0.07% )
12,296,259,407 stalled-cycles-frontend # 40.47% frontend cycles idle ( +- 0.13% )
3,370,668,651 stalled-cycles-backend # 11.09% backend cycles idle ( +- 0.69% )
28,969,052,879 instructions # 0.95 insn per cycle
# 0.42 stalled cycles per insn ( +- 0.01% )
6,308,245,891 branches # 726.058 M/sec ( +- 0.00% )
214,685,502 branch-misses # 3.40% of all branches ( +- 0.26% )
9.146081052 seconds time elapsed ( +- 0.07% )
^^^^^^^^^^^
vsnprintf() is slow because:
1. format_decode() is busy looking for format specifier: 2 branches
per character (not in this case, but in others)
2. approximately million branches while parsing format mini language
and everywhere
3. just look at what string() does /proc/vmstat is good case because
most of its content are strings
Link: http://lkml.kernel.org/r/20160806125455.GA1187@p183.telecom.by
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: Joe Perches <joe@perches.com>
Cc: Andi Kleen <andi@firstfloor.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Mel Gorman <mgorman@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-01-10 09:27:14 +01:00
..
2017-06-17 06:39:36 +02:00
2017-02-26 11:07:51 +01:00
2016-03-03 15:07:18 -08:00
2015-09-08 15:35:28 -07:00
2015-04-14 16:49:03 -07:00
2015-07-17 16:39:54 -07:00
2016-11-10 16:36:36 +01:00
2015-08-14 15:56:32 -07:00
2016-08-10 11:49:25 +02:00
2017-11-24 11:26:29 +01:00
2015-11-06 17:50:42 -08:00
2015-11-06 17:50:42 -08:00
2015-11-05 19:34:48 -08:00
2015-06-02 08:33:35 -06:00
2015-11-06 17:50:42 -08:00
2017-03-12 06:37:25 +01:00
2015-11-05 19:34:48 -08:00
2015-06-24 17:49:45 -07:00
2017-06-26 07:13:11 +02:00
2014-08-06 18:01:22 -07:00
2017-12-16 10:33:50 +01:00
2015-11-06 17:50:42 -08:00
2017-04-08 09:53:32 +02:00
2015-09-10 13:29:01 -07:00
2017-01-06 11:16:11 +01:00
2017-08-11 09:08:50 -07:00
2015-02-10 14:30:31 -08:00
2015-11-06 17:50:42 -08:00
2015-01-08 15:10:52 -08:00
2014-10-09 22:25:50 -04:00
2014-06-06 16:08:18 -07:00
2015-11-05 19:34:48 -08:00
2016-10-07 15:23:40 +02:00
2017-07-21 07:44:56 +02:00
2015-11-05 19:34:48 -08:00
2017-12-05 11:22:50 +01:00
2015-09-11 16:42:39 -07:00
2017-06-14 13:16:26 +02:00
2017-03-18 19:09:57 +08:00
2017-02-09 08:02:47 +01:00
2017-06-26 07:13:10 +02:00
2017-08-11 09:08:50 -07:00
2017-08-24 17:02:35 -07:00
2017-08-12 19:29:09 -07:00
2015-09-08 15:35:28 -07:00
2017-08-24 17:02:36 -07:00
2015-11-05 19:34:48 -08:00
2017-06-07 12:06:01 +02:00
2015-06-30 19:44:56 -07:00
2017-07-21 07:44:58 +02:00
2017-12-25 14:22:09 +01:00
2015-09-10 13:29:01 -07:00
2015-02-11 17:06:02 -08:00
2017-08-11 09:08:50 -07:00
2017-08-11 09:08:50 -07:00
2015-11-05 19:34:48 -08:00
2015-06-30 19:44:55 -07:00
2015-11-05 19:34:48 -08:00
2015-12-12 10:15:34 -08:00
2017-11-24 08:32:25 +01:00
2015-11-05 19:34:48 -08:00
2017-11-24 08:32:25 +01:00
2015-09-10 13:29:01 -07:00
2015-08-13 12:32:00 -06:00
2016-04-20 15:41:53 +09:00
2017-11-24 08:32:25 +01:00
2016-07-27 09:47:29 -07:00
2017-11-24 08:32:25 +01:00
2014-09-02 14:46:05 -04:00
2014-09-02 14:46:02 -04:00
2017-03-26 12:13:20 +02:00
2016-02-25 12:01:23 -08:00
2016-02-25 12:01:16 -08:00
2015-11-06 17:50:42 -08:00
2017-12-25 14:22:09 +01:00
2016-07-27 09:47:40 -07:00
2017-10-21 17:09:05 +02:00
2015-11-22 11:58:44 -08:00
2015-11-22 11:58:44 -08:00
2015-11-22 11:58:44 -08:00
2017-06-07 12:06:01 +02:00
2017-07-05 14:37:15 +02:00
2015-09-08 15:35:28 -07:00
2015-11-06 17:50:42 -08:00
2016-11-18 10:48:34 +01:00
2017-06-14 13:16:24 +02:00
2015-09-04 16:54:41 -07:00
2016-09-15 08:27:46 +02:00
2015-11-05 19:34:48 -08:00
2015-11-20 16:17:32 -08:00
2017-03-12 06:37:25 +01:00
2017-07-15 11:57:44 +02:00
2018-01-10 09:27:14 +01:00
2016-10-28 03:01:34 -04:00
2015-11-06 17:50:42 -08:00
2015-11-06 17:50:42 -08:00
2016-05-18 17:06:44 -07:00
2017-02-09 08:02:45 +01:00