glibc/sysdeps
Rasmus Villemoes 0ce657c576 linux/getsysstats.c: use sysinfo() instead of parsing /proc/meminfo
Profiling git's test suite, Linus noted [1] that a disproportionately
large amount of time was spent reading /proc/meminfo. This is done by
the glibc functions get_phys_pages and get_avphys_pages, but they only
need the MemTotal and MemFree fields, respectively. That same
information can be obtained with a single syscall, sysinfo, instead of
six: open, fstat, mmap, read, close, munmap. While sysinfo also
provides more than necessary, it does a lot less work than what the
kernel needs to do to provide the entire /proc/meminfo. Both strace -T
and in-app microbenchmarks shows that the sysinfo() approach is
roughly an order of magnitude faster.

sysinfo() is much older than what glibc currently requires, so I don't
think there's any reason to keep the old parsing code. Moreover, this
makes get_[av]phys_pages work even in the absence of /proc.

Linus noted that something as simple as 'bash -c "echo"' would trigger
the reading of /proc/meminfo, but gdb says that many more applications
than just bash are affected:

Starting program: /bin/bash "-c" "echo"

Breakpoint 1, __get_phys_pages () at ../sysdeps/unix/sysv/linux/getsysstats.c:283
283     ../sysdeps/unix/sysv/linux/getsysstats.c: No such file or directory.
(gdb) bt

So it seems that any application that uses qsort on a moderately sized
array will incur this cost (once), which is obviously proportionately
more expensive for lots of short-lived processes (such as the git test
suite).

[1] http://thread.gmane.org/gmane.linux.kernel/2019285

Signed-off-by: Rasmus Villemoes <rv@rasmusvillemoes.dk>

	* sysdeps/unix/sysv/linux/getsysstats.c (__get_phys_pages):
	Use sysinfo system call instead of parsing /proc/meminfo.
	* sysdeps/unix/sysv/linux/getsysstats.c (__get_avphys_pages):
	Likewise.
2015-09-12 21:09:59 -04:00
..
aarch64 Move bits/atomic.h to atomic-machine.h (bug 14912). 2015-09-11 20:00:19 +00:00
alpha Move bits/atomic.h to atomic-machine.h (bug 14912). 2015-09-11 20:00:19 +00:00
arm Move bits/atomic.h to atomic-machine.h (bug 14912). 2015-09-11 20:00:19 +00:00
generic Move bits/atomic.h to atomic-machine.h (bug 14912). 2015-09-11 20:00:19 +00:00
gnu Add more TCP_* values to netinet/tcp.h. 2015-09-01 13:45:49 +00:00
hppa Rename bits/linkmap.h to linkmap.h (bug 14912). 2015-09-04 19:44:27 +00:00
i386 Add more random libm test inputs (mainly for ldbl-128). 2015-09-12 00:01:38 +00:00
ia64 Move bits/atomic.h to atomic-machine.h (bug 14912). 2015-09-11 20:00:19 +00:00
ieee754 Fix ldbl-128/ldbl-128ibm lgamma spurious "invalid", incorrect signgam (bug 18952). 2015-09-11 15:34:25 +00:00
init_array
m68k Move bits/atomic.h to atomic-machine.h (bug 14912). 2015-09-11 20:00:19 +00:00
mach Move bits/libc-lock.h and bits/libc-lockP.h out of bits/ (bug 14912). 2015-09-08 21:11:03 +00:00
microblaze Move bits/atomic.h to atomic-machine.h (bug 14912). 2015-09-11 20:00:19 +00:00
mips Add more random libm test inputs (mainly for ldbl-128). 2015-09-12 00:01:38 +00:00
nacl NaCl: Do not install <sys/mtio.h>. 2015-09-11 14:16:18 -07:00
nios2
nptl Move bits/libc-lock.h and bits/libc-lockP.h out of bits/ (bug 14912). 2015-09-08 21:11:03 +00:00
posix To fix BZ #18675, use __fstatvfs64 in __fpathconf. 2015-09-09 18:41:25 -07:00
powerpc Move bits/atomic.h to atomic-machine.h (bug 14912). 2015-09-11 20:00:19 +00:00
pthread Move bits/libc-lock.h and bits/libc-lockP.h out of bits/ (bug 14912). 2015-09-08 21:11:03 +00:00
s390 Move bits/atomic.h to atomic-machine.h (bug 14912). 2015-09-11 20:00:19 +00:00
sh Rename bits/linkmap.h to linkmap.h (bug 14912). 2015-09-04 19:44:27 +00:00
sparc Move bits/atomic.h to atomic-machine.h (bug 14912). 2015-09-11 20:00:19 +00:00
tile Move bits/atomic.h to atomic-machine.h (bug 14912). 2015-09-11 20:00:19 +00:00
unix linux/getsysstats.c: use sysinfo() instead of parsing /proc/meminfo 2015-09-12 21:09:59 -04:00
wordsize-32
wordsize-64
x86 Rename bits/linkmap.h to linkmap.h (bug 14912). 2015-09-04 19:44:27 +00:00
x86_64 Add more random libm test inputs (mainly for ldbl-128). 2015-09-12 00:01:38 +00:00