Is the amount of virtual memory that remains in physical memory dependent on physical memory size?
Let's assume I have a swappiness parameter of 60, and 4GB of my 8GB are filled with application data, and the other 4GB are filled with the file cache.
Will, under the same workload with the same swappiness parameter, but only 4GB physical memory, all 4GB be filled with application data or less than that?

1 Answer 1


It's proportional and not based on memory size at all. The code is in mm/vmscan.c. After checking for some pathological conditions, such as being completely out of swap space (then only file-backed pages will be scanned as candidates for being evicted from memory), being almost out of memory (file-backed and anonymous memory will be scanned equally), or the page cache has become very large and filled with inactive pages (only file-backed pages will be scanned), we hit this:

 * With swappiness at 100, anonymous and file have the same priority.
 * This scanning priority is essentially the inverse of IO cost.
anon_prio = swappiness;
file_prio = 200 - anon_prio;

These priorities get further adjusted based on the success the memory scanner has recently had in freeing memory of each type. Then memory of each type is scanned proportionally, and pages that have not been recently used will be evicted.

Bottom line, it all depends on the workload. The swappiness value tells the system what priority to assign to trying to swap out anonymous memory, but memory access patterns will determine what actually happens.

  • So if I understood that correctly swappiness does not at all control how hard the system tries to swap (and it might only appear that way to some because file-backed memory shows as available (but not free)), but instead only whether to prefer file-backed vs anonymous pages?
    – hyperfekt
    Commented Aug 25, 2017 at 8:48
  • Yes, that's basically it. Swappiness controls how much the system will try to actually use the swap file(s). Pages that are already on disk can just be removed from memory and reloaded when needed. That includes parts of executable files as well as page cache.
    – Chuck E
    Commented Aug 26, 2017 at 23:57

You must log in to answer this question.

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