鍍金池/ 問答/Linux  網(wǎng)絡安全/ Ubuntu 使用free命令used != total - free

Ubuntu 使用free命令used != total - free

使用free -m命令:

              total        used        free      shared  buff/cache   available
Mem:            992         425          90          15         476         363
Swap:          2047           7        2040

可用內(nèi)存=系統(tǒng)free memory+buffers+cached
這里不滿足:
used=total-free 即 total=used+free
??

回答
編輯回答
詆毀你

找了一些內(nèi)容來:

3.14內(nèi)核新增了一個內(nèi)存信息MemAvailable , 當調(diào)用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是被程序之間可以(已經(jīng)被)共享使用的
  • buffers是指用來給塊設備做的緩沖大小,它只記錄文件系統(tǒng)的metadata以及 tracking in-flight pages
  • cached是用來給文件做緩沖

也就是 buffers是用來存儲目錄里面有什么內(nèi)容,權(quán)限等等。而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才是你的"可用內(nèi)存" , 而不是像過去那樣簡單的把free和buffer加起來

available 小于 free+buffer 是一定的了

2018年8月13日 10:58
編輯回答
亮瞎她

計算公式應該是 used = total - free - buffers - cache
man free就可以看到了

2018年4月16日 13:32