简体   繁体   English

如何清理Linux内核使用的缓存

[英]How to clean caches used by the Linux kernel

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'). 我想强制Linux内核在缓存开始占用太多内存后为应用程序分配更多内存(可以通过'free'的输出看到)。

I've run 我跑了

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

(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. (为了释放光盘dentry / inode缓存和页面缓存),我发现只有大约一半的已用缓存被释放 - 其余的仍然存在。 How can I tell what is taking up the rest of the cache and force it to be freed? 如何判断占用缓存的其余部分并强制释放?

You may want to increase vfs_cache_pressure as well as set swappiness to 0 . 您可能希望增加vfs_cache_pressure以及将swappiness设置为0

Doing that will make the kernel reclaim cache faster, while giving processes equal or more favor when deciding what gets paged out. 这样做会使内核更快地回收缓存,同时在决定被调出的内容时给予进程相同或更多的优势。

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. 如果网络I / O绑定进程必须交换来处理请求,那就是一个问题,真正的解决方案是将它放在竞争力较弱的服务器上。

With the default swappiness setting, the kernel is almost always going to favour keeping FS related cache in real memory. 使用默认的swappiness设置,内核几乎总是倾向于将FS相关的缓存保留在实际内存中。

As such, if you increase the cache pressure, be sure to equally adjust swappiness . 因此,如果您增加缓存压力,请务必同样调整swappiness

The contents of /proc/meminfo tell you what the kernel uses RAM for. / proc / meminfo的内容告诉你内核使用RAM的内容。

You can use /proc/sys/vm/vfs_cache_pressure to force the kernel to reclaim memory that is used for filesystem-related caches more lazily or eagerly. 您可以使用/ proc / sys / vm / vfs_cache_pressure强制内核更懒惰地或急切地回收用于与文件系统相关的缓存的内存。

Note that your application may only benefit from tuning this parameter if it does little or no disk I/O. 请注意,如果您的应用程序很少或没有磁盘I / O,那么您的应用程序可能只会受益于调整此参数。

You might find John Nilsson's answer to my Question useful for purging the cache in order to test whether that is related to your problem: 您可能会发现John Nilsson对我的问题的回答对于清除缓存很有用,以便测试它是否与您的问题有关:

sync && echo 1 > /proc/sys/vm/drop_caches

Though I'm guessing the only real difference is 1 vs 3 虽然我猜测唯一真正的区别是1 vs 3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM