There are two commands and two files.
]# free -V; vmstat -V
free from procps-ng 3.3.15
vmstat from procps-ng 3.3.15
Proc-Files: meminfo
and vmstat
Free's manpage explains about meminfo fields. Some of these fields are also calculated indirectly.
vmstat
only adds some /proc/vmstat fields.
/proc/vmstat
has a more systematic (and longer) structure. Here are four lines where that mysterious pagecache is mentioned
nr_anon_pages 212687
nr_mapped 70247
nr_file_pages 887005
nr_dirty 64
Now these strings are very weak compared to the enum list in mmzone.h, with comments:
NR_ANON_MAPPED, /* Mapped anonymous pages */
NR_FILE_MAPPED, /* pagecache pages mapped into pagetables. only modified from process context */
NR_FILE_PAGES,
NR_FILE_DIRTY,
(In first place come the 4 lines ANON and FILES combined with ACTIVE and INACTIVE)
So your second one is not a command, but the contents of the proc file the commands rely on.
fs/proc/meminfo.c
:
cached = global_node_page_state(NR_FILE_PAGES) -
total_swapcache_pages() - i.bufferram;
if (cached < 0)
cached = 0;
This illustrates there is no own "cached" counter, and it has to be sanity checked. It is basically all the "file pages", active or inactive, with some corrections.
i.buffers
is added back in the 'buff/cache' field of free
This part (/proc/meminfo contents) shows how the values are collected together. i
is a struct sysinfo. cached and available are calculated right before. The pages[] array is very like /proc/vmstat, also Mlocked with that zone page call.
show_val_kb(m, "MemTotal: ", i.totalram);
show_val_kb(m, "MemFree: ", i.freeram);
show_val_kb(m, "MemAvailable: ", available);
show_val_kb(m, "Buffers: ", i.bufferram);
show_val_kb(m, "Cached: ", cached);
show_val_kb(m, "SwapCached: ", total_swapcache_pages());
show_val_kb(m, "Active: ", pages[LRU_ACTIVE_ANON] +
pages[LRU_ACTIVE_FILE]);
show_val_kb(m, "Inactive: ", pages[LRU_INACTIVE_ANON] +
pages[LRU_INACTIVE_FILE]);
show_val_kb(m, "Active(anon): ", pages[LRU_ACTIVE_ANON]);
show_val_kb(m, "Inactive(anon): ", pages[LRU_INACTIVE_ANON]);
show_val_kb(m, "Active(file): ", pages[LRU_ACTIVE_FILE]);
show_val_kb(m, "Inactive(file): ", pages[LRU_INACTIVE_FILE]);
show_val_kb(m, "Unevictable: ", pages[LRU_UNEVICTABLE]);
show_val_kb(m, "Mlocked: ", global_zone_page_state(NR_MLOCK));
swap cache is what man free calls cache:
cache: Memory used by the page cache and slabs (Cached and SReclaimable in /proc/meminfo)
Because of (simplified, see above):
cached = NR_FILE_PAGES - total_swapcache_pages()
...there is a interesting relationship with SwapCached. If only the names were less confusing.
What swap cache is for files on disk, SwapCached is for ANON pages on a swap device. (I hope this makes sense/is not totally wrong)