All shared
memory is also counted as cached
.
shared
memory is implemented using tmpfs
internally. tmpfs
is implemented as a thin wrapper for the page cache, just without having any backing store (except that tmpfs
is swappable).
man free
does not explain this. At least on my system (provided by procps-ng, last updated 2016-06-03). Sorry. All man free
tells you is that cache
is taken from Cached
in /proc/meminfo
. If you read man proc
(from man-pages, updated 2017-09-15), it has documentation for the fields in the meminfo
file, but it still fails to inform you that Cached
includes Shmem
.
You can see this with an experiment. While you have free
memory (not available
), you can create a file in a tmpfs, for example:
dd bs=1M count=100 < /dev/zero > /dev/shm/test.tmp
The result of this is that both the shared
and cached
figures in free -m
increase by 100.
If you only have available
memory, and do not have enough free
memory to test this properly, you can create free
memory by dropping as much page cache as possible, by running echo 1 | sudo tee /proc/sys/vm/drop_caches
. Of course dropping page cache can be very bad for performance. Do not do this on a real server :-).