How can I flush the cache per device and not on the entire system?

219 篇文章 2 订阅

https://access.redhat.com/solutions/149003

How can I flush the cache per device and not on the entire system?

 SOLUTION 已验证 - 已更新 2018年十二月18日22:58 - 

English 

环境

  • Red Hat Enterprise Linux 5
  • Red Hat Enterprise Linux 6

问题

  • I know it's possible to flush the device cache maintained in memory for the whole system by using the sync command, but I'd like to flush the caches on a per device basis.

决议

Yes, it's possible to flush the cache per device by using the command blockdev:

# blockdev --flushbufs /dev/<device>

诊断步骤

NOTE:The sync and blockdev --flushbufs commands only force dirty page cache out to disk. Neither does a drop cache operation such as you'd get via echo 1 > /proc/sys/vm/drop_cache. A drop cache reclaims non-dirty, non-referenced page cache and returns it to the free pool. In order for a reclaim to be effective, a sync operation to prep the page cache pool by getting all its pages into non-dirty state is needed. So, sync flushes all dirty pages in the system, blockdev --flushbufs flushes just the dirty pages for a given disk, and drop_caches reclaims, but doesn't flush, cache. For example, here we can see the differences of just flushing dirty pages out to disk vs reclaiming them:

$ vmstat 1 2
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0    240 105316  54704 822236    0    0    18    71   16   98  1  0 97  1  0
 1  0    240 105200  54708 822376    0    0     0    16 1255 2323  2  0 98  0  0
$ blockdev --flushbufs /dev/sda
$ vmstat 1 2
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    240 122260  54948 824504    0    0    18    71   16   99  1  0 97  1  0
 2  0    240 122260  54948 824572    0    0     0     0 1213 2165  1  0 99  0  0

NOTE: the in use buff page count doesn't really change, whereas if we reclaim
      non-dirty, non-referenced buff pages via a drop cache the count does 
      change.

$ echo 1 > /proc/sys/vm/drop_caches
$ vmstat 1 2
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu------
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 1  0    240 887248    264 134264    0    0    18    71   16   99  1  0 97  1  0
 1  0    240 887240    272 134492    0    0     0    36 1369 2344  1  0 99  0  0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值