Linux內(nèi)存工作原理之Buffer/Cache定義
此文章部分內(nèi)容由(小紅書 www.xiaohongshutuiguang.cn)轉(zhuǎn)載提供 歡迎留言反饋
使用man free查看
buffers? ? Memory used by kernel buffers (Buffers in/proc/meminfo)
cache? ? ? Memory used by the page cache and slabs (Cached and SReclaimable in/proc/meminfo)
buff/cache? Sum of buffers and cache
Buffers?是內(nèi)核緩沖區(qū)用到的內(nèi)存,對應的是 /proc/meminfo 中的Buffers值
Cache?是內(nèi)核頁緩存和 Slab 用到的內(nèi)存,對應的是 /proc/meminfo 中的Cached 與 SReclaimable之和
使用man proc 查看

Buffers %lu
? ? Relatively temporary storage forraw disk blocks that shouldn't get tremendously large (20MB or so).Cached %lu
? ? In-memory cacheforfiles readfromthe disk (the page cache).? Doesn't include SwapCached.SReclaimable %lu (since Linux2.6.19)
? ? Part of Slab, that might be reclaimed, such as caches.
SUnreclaim %lu (since Linux2.6.19)
? ? Part of Slab, that cannot be reclaimed on memory pressure.

Buffers 是對原始磁盤塊的臨時存儲,也就是用來緩存磁盤的數(shù)據(jù),通常不會特別大(20MB左右)。這樣,內(nèi)核就可以把分散的寫集中起來,統(tǒng)一優(yōu)化磁盤的寫入,比如可以把多次小的寫合并成單次大的寫等。
Cached 是從磁盤讀取文件的頁緩存,也就是用來緩存從文件讀取的數(shù)據(jù)。這樣,下次訪問這些文件數(shù)據(jù)時,就可以直接從內(nèi)存中快速獲取,而不需要再次訪問緩慢的磁盤。
SReclaimable 是Slab 的一部分。Slab 包括兩個部分,其中的可回收部分用 SReclaimable 記錄;不可回收部分用 SUnreclaim 記錄