]> granicus.if.org Git - procps-ng/commit
library: properly handle memory used by tmpfs
authorJakob Unterwurzacher <jakobunt@gmail.com>
Tue, 18 Feb 2014 21:12:21 +0000 (22:12 +0100)
committerJaromir Capik <jcapik@redhat.com>
Thu, 27 Feb 2014 13:07:10 +0000 (14:07 +0100)
commit3569c0351fae7797e8d62feae7229d2d6d2aa0a1
treedede8d415ced816d91d725390d21ab94590b7f0f
parent24f1fbd9d051353dd8ebde048f1903d68834af74
library: properly handle memory used by tmpfs

tmpfs has become much more widely used since distributions use it for
/tmp (Fedora 18+). In /proc/meminfo, memory used by tmpfs is accounted
into "Cached" (aka "NR_FILE_PAGES",
 http://lxr.free-electrons.com/source/mm/shmem.c#L301 ).

The tools just pass it on, so what top, free and vmstat report as
"cached" is the sum of page cache and tmpfs.

free has the extremely useful "-/+ buffers/cache" output. However, now
that tmpfs is accounted into "cached", those numbers are way off once
you have big files in /tmp.

Fortunately, kernel 2.6.32 introduces "Shmem", which makes tmpfs memory
usage accessible from userspace (
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=4b02108ac1b3354a22b0d83c684797692efdc395 ).

This patch substracts Shmem from Cached to get the actual page cache
memory. This makes both issues mentioned above disappear. For older
kernels, Shmem is not available (hence zero) and this patch is no-op.

Additionally:
* Update the man pages of free and vmstat to explain what is happening
* Finally drop "MemShared" from the /proc/meminfo parser, it has been
  dead for 10+ years and is only causing confusion ( removed in kernel
  2.5.54, see
  https://git.kernel.org/cgit/linux/kernel/git/tglx/history.git/commit/?id=fe04e9451e5a159247cf9f03c615a4273ac0c571 )
free.1
proc/sysinfo.c
proc/sysinfo.h
vmstat.8