0

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

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.

| improve this answer | |
  • 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 Aug 25 '17 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 Aug 26 '17 at 23:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.