Since kernel version 2.6.28, Linux uses a Split Least Recently Used (LRU) page replacement strategy. Pages with a filesystem source, such as program text or shared libraries belong to the file cache. Pages without filesystem backing are called anonymous pages, and consist of runtime data such as the stack space reserved for applications etc. Typically pages belonging to the file cache are cheaper to evict from memory (as these can simple be read back from disk when needed). Since anonymous pages have no filesystem backing, they must remain in memory as long as they are needed by a program unless there is swap space to store them to.
vm.swappiness option comes into play in
get_scan_count() defined in
get_scan_count() determines how aggressively the anonymous and file LRU lists should be scanned when looking for pages to evict. The value of each case is is determined by the floating average of recently rotated and recently scanned ratios where more recent references have more weight than older ones in order take into account the changing workload of the system.
vm.swappiness is a modifier that changes the balance between swapping out file cache pages in favour of anonymous pages.
vm.swappiness is the priority value given to anonymous pages, by default set to 60. The file cache is given an priority value of 200 from which the
vm.swappiness modifier is deducted (
file_prio=200-anon_prio). This means that, by default, the priority weights stand moderately in favour of anonymous pages (
file_prio=200-60=140). However, when the system is close to an out-of-memory condition, the both anonymous and file LRU lists are scanned equally, unless
vm.swappiness is set to zero.
vm.swappiness is set to 100, the priorities would be equal (
vm.swappiness to zero will prevent the kernel from evicting anonymous pages in favour of pages from the file cache.