buffer 与cache 的理解

buffer 与cache :

通过 $ 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是内核缓冲区用到的内存;cache是内核页缓存和Slab用到的内存,cache大小等于Cached +SReclaimable。

$man proc

Buffers %lu
    Relatively temporary storage for raw disk blocks that shouldn't get tremendously large (20MB or so).

Cached %lu
   In-memory cache for files read from the disk (the page cache).  Doesn't include SwapCached.
...
SReclaimable %lu (since Linux 2.6.19)
    Part of Slab, that might be reclaimed, such as caches.
    
SUnreclaim %lu (since Linux 2.6.19)
    Part of Slab, that cannot be reclaimed on memory pressure.
上面这段可以简单理解为:

CPU(写) ------> buffer ------> disk(解决CPU与硬盘性能差异,待写数据放入buffer池)

CPU(读)<------ cache <------ disk(命中缓存,不用每次去disk获取数据,命中率越高,IO读(bi)越小)

A buffer is something that has yet to be "written" to disk.
A cache is something that has been "read" from the disk and stored for later use.
 

$ free -m
             total       used       free     shared    buffers     cached
Mem:          2006       1735        270          1         39        728
-/+ buffers/cache:        967       1038
Swap:            0          0          0 

 

# total = used + free + shared

'-buffers/cache used' = 第一行used - buffers - cached - shared;

'+buffers/cache free' = 第一行free + buffers + cached + shared;

 

#内存不足,会触发缓存回收,swap机制和OOM。Swap 越高,说明内核置换cache越频繁,内存资源越紧张。

 

$  vmstat 1 3 #查看bi,bi:磁盘读,bo:磁盘写
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 0  0      0 277136  40616 745644    0    0    88   237 1188  526  7  2 91  0  0
 0  0      0 277136  40632 745636    0    0     0    64 1264  628  0  0 100  0  0
 0  0      0 277136  40632 745644    0    0     0     4 1258  607  0  0 100  0  0

#cache越大,bi越小

 


 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值