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 -
环境
- 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

本文介绍在Red Hat Enterprise Linux 5和6中如何使用blockdev命令按设备刷新缓存,而非整个系统。通过对比sync命令,阐述了blockdev --flushbufs命令的用法及其与内存管理的关系。
673

被折叠的 条评论
为什么被折叠?



