In order to speed up operations and reduce disk I/O, the kernel usually does as much caching as it has memory. By design, pages containing cached data can be repurposed on-demand for other uses (e.g., apps). Repurposing memory for use in this way is no slower than claiming pristine untouched pages.

为了加速操作和减少磁盘输入输出,内核通常会尽可能多地缓存内存。根据设计,包含缓存数据的页面可以按需重新用于其他用途(例如,应用程序)。以这种方式重新调整内存的用途并不比要求原始的未接触页面慢。

Writing to /proc/sys/vm/drop_caches allows one to request the kernel immediately drop as much clean cached data as possible. "Clean" cached data is eligible for dropping. "Dirty" cached data needs to be written somewhere. Using vm.drop_caches will never trigger the kernel to drop dirty cache.

写入/proc/sys/VM/drop_caches允许用户请求内核立即丢弃尽可能多的干净缓存数据。

“干净”的缓存数据有资格删除。

“脏”缓存数据需要写入某个地方。

使用vm.drop _ caches永远不会触发内核丢弃脏缓存.

那么,如何通过操作将缓存写入disk?

从sync命令开始,让内核将尽可能多的脏缓存页写入磁盘(以最大化可以丢弃的数据缓存页的数量)。

亦或通过使用sysctl-w vm.drop_cache = < number >或通过直接写入/proc/sys/VM/drop_cache来触发缓存删除,如下所示:

释放页面缓存、数据区和信息节点(一般使用3 或者sync即可)

echo 3 >/proc/sys/vm/drop_caches

释放数据区和信息节点

echo 2 >/proc/sys/vm/drop_caches

释放页面缓存

echo 1 >/proc/sys/vm/drop_caches
Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐