如何清除Linux内核使用的缓存 [英] How to clean caches used by the Linux kernel

查看:386
本文介绍了如何清除Linux内核使用的缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想强制Linux内核在缓存开始占用过多的内存后才能为应用程序分配更多的内存(如"free"的输出所示).

I want to force the Linux kernel to allocate more memory to applications after the cache starts taking up too much memory (as can be seen by the output of 'free').

我跑了

sudo sync; sudo sysctl -w vm.drop_caches=3; free

(同时释放磁盘Dentry/inode缓存和页面缓存),我看到只有大约一半的已使用缓存被释放-其余部分仍然保留.我怎么知道什么占用了缓存的其余部分并强制将其释放?

(to free both disc dentry/inode cache and page cache) and I see that only about half of the used cache was freed - the rest remains. How can I tell what is taking up the rest of the cache and force it to be freed?

推荐答案

您可能希望增加vfs_cache_pressure并将swappiness设置为0.

You may want to increase vfs_cache_pressure as well as set swappiness to 0.

这样做可以使内核回收高速缓存更快,同时在决定什么内容被分页时给予进程同等或更多的青睐.

Doing that will make the kernel reclaim cache faster, while giving processes equal or more favor when deciding what gets paged out.

如果您关心的进程执行的磁盘I/O很少,则可能要这样做.

You may only want to do this if processes you care about do very little disk I/O.

如果网络I/O绑定过程必须交换以处理请求,则这是一个问题,真正的解决方案是将其放置在竞争力较低的服务器上.

If a network I/O bound process has to swap in to serve requests, that's a problem and the real solution is to put it on a less competitive server.

使用默认的swappiness设置,内核几乎总是倾向于将FS相关的高速缓存保留在实际内存中.

With the default swappiness setting, the kernel is almost always going to favour keeping FS related cache in real memory.

因此,如果您增加缓存压力,请确保均等地调整swappiness.

As such, if you increase the cache pressure, be sure to equally adjust swappiness.

这篇关于如何清除Linux内核使用的缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆