Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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').

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. How can I tell what is taking up the rest of the cache and force it to be freed?

like image 340
Guss Avatar asked Mar 01 '09 12:03

Guss


People also ask

Should I clear cache on Linux?

For the most part you can delete most anything in your home directory, programs or applications that require . cache (or other dot files such as . local ) will re-create them. Most of the time, at worst, you will lose custom configurations, but no real harm to the system.


1 Answers

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.

You may only want to do this if processes you care about do very little disk 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.

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

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

like image 181
Tim Post Avatar answered Oct 06 '22 15:10

Tim Post