Looking at how the VFS cache on my Linux machine behaves, I can see that even when effectively idle (crond and most other daemons stopped, interfaces down) the amount of free memory gradually increases implying that items are being evicted from the cache.

I did a lot of googling but can't find any reference to how this is controlled (unless it's a side effect of vm_swappiness). Can anyone put me on the right path to understanding why items are being evicted from the cache when there is no demand for new memory allocation?

  • «implying that items are being evicted from the cache» — well, in that case vmstat would show caches size increasing, — are they really?
    – poige
    Apr 6, 2013 at 9:55
  • decreasing surely. Yes they are (decreasing)
    – symcbean
    Apr 7, 2013 at 0:14
  • So, you say free mem increasing and cache/buf size is decreasing at the same time, is it right?
    – poige
    Apr 7, 2013 at 9:53

2 Answers 2


swappiness only affects whether allocated application memory is swapped out to make room for the cache. vfs_cache_pressure is the sysctl that controls what you're seeing.

  • 1
    No - vfs_cache_pressure controls the ratio of meta data vs pagecache retention (at least according to the docs I've read and the experiments I've run)
    – symcbean
    Apr 2, 2013 at 9:36
  • 1
    Fair enough. I did a little more research and from what I can see everything is ordered into an LRU order list and only looked at when some threshold (artificial or physical) is met or surpassed. Given that, I'd assume something is still happening (like a kernel thread waking up or something). If it's super important to you to figure this out it looks like there's a pre-written systemtap script called "mmreclaim.stp" that track the memory manager's reclaimations. I would also made sure it's not actually going to swap using "sar -A."
    – Bratchley
    Apr 2, 2013 at 15:35

Linux flushes the data from page cache using a process called pdflush

pdflush is controlled by parameters from /proc/sys/vm

The hundredth of the second after which data will be considered to be expired from the page cache and will be written at the next opportunity.

The hundredth of a second after which the pdflush wakes up to write data to disk.

This will reclaim dentries and inodes which are also part of the cache.

You can check out the following threads for more information:

The pdflush daemon
Theory of operation and tuning for write-heavy loads
Linux Cache Memory

  • Thanks Joe, however the first 2 options specifically relate to data which needs to be written back to the filesystem (i.e. the write buffer) not data which has been read and has not been changed (the read buffer). The vfs_cache_pressure controls the preference for evicting file metadata relative to file contents.
    – symcbean
    Nov 18, 2014 at 16:27
  • @symcbean You are correct. The answer speaks more about write cache. The read cache are cleared based on LRU. However, Linux uses a Two-List Strategy based on which the read cache is being cleared. You can read more about Two-List Stragety and how linux clears the read cache here. Let me know if this makes sense. In your case I assume that after all processes are stopped, these read caches go into inactive list and are cleared
    – Joe
    Nov 18, 2014 at 16:52
  • thanks, nice article. Any idea what book the chapter comes from? However, although it explains how a particular page is prioritized for eviction, it does not really explain why pages are evicted when there is no apparent demand for memory. What controls the process "to shrink the cache to make available more RAM for other uses"? What is it replacing these with?
    – symcbean
    Nov 18, 2014 at 17:21
  • @symcbean The cache eviction does work immediately when there is a demand for memory. However, it doesn’t make sense to have it in cache when no one is actively using it. There by the active pages become inactive pages and eventually be evicted. I assume your question originates from the point that the eviction shall happen only when there is demand for memory. The linux would clear every inactive page as and when they are available. As [noted in the article][jothirams.com/linux-cached-memory/] if everything is active, you will run out of memory and OOM will be called.
    – Joe
    Nov 18, 2014 at 21:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .