free命令的available

Submitted by Lizhe on Thu, 07/20/2017 - 10:27

3.14内核新增了一个内存信息MemAvailable , 当调用free命令时可以显示为available

之前没留意过

[root@VM_167_46_centos etc]# free -h
                         total         used             free      shared     buff/cache      available
Mem:           993M        253M        334M         39M               405M             556M
Swap:           2.0G          82M             1.9G

我们知道used + free + buff 基本等于 total

used是被使用的

free是完全没有被使用的

shared是被程序之间可以(已经被)共享使用的

buffers是指用来给块设备做的缓冲大小,它只记录文件系统的metadata以及 tracking in-flight pages

cached是用来给文件做缓冲

也就是 buffers是用来存储目录里面有什么内容,权限等等。而cached直接用来缓存我们打开的文件

available到底是什么

Many load balancing and workload placing programs check /proc/meminfo to estimate how much free memory is available. They generally do this by adding up "free" and "cached", which was fine ten years ago, but is pretty much guaranteed to be wrong today.
It is wrong because Cached includes memory that is not freeable as page cache, for example shared memory segments, tmpfs, and ramfs, and it does not include reclaimable slab memory, which can take up a large fraction of system memory on mostly idle systems with lots of files.Currently, the amount of memory that is available for a new workload,without pushing the system into swap, can be estimated from MemFree, Active(file), Inactive(file), and SReclaimable, as well as the "low"watermarks from /proc/zoneinfo.However, this may change in the future, and user space really should not be expected to know kernel internals to come up with an estimate for the amount of free memory.It is more convenient to provide such an estimate in /proc/meminfo. If things change in the future, we only have to change it in one place.

也就是说available才是你的"可用内存" , 而不是像过去那样简单的把free和buffer加起来

available 小于 free+buffer 是一定的了