Swappinessis a property of the Linux kernel that changes the balance between swapping out runtime memory, as opposed to dropping pages from the system page cache. Swappiness can be set to values between 0 and 100 inclusive. A low value means the kernel will try to avoid swapping as much as possible where a higher value instead will make the kernel aggressively try to use swap space. The default value is60, and for most desktop systems, setting it to 100 may affect the overall performance, whereas setting it lower (even 0) may improve interactivity (by decreasing response latency.)[1]

vm.swappiness=0The kernel will swap only to avoid an out of memory condition.
vm.swappiness=60The default value.
vm.swappiness=100The kernel will swap aggressively which may affect over all performance.



if (!reclaim_mapped ||
(total_swap_pages == 0 && PageAnon(page)) ||
page_referenced(page, 0)) {
list_add(&page->lru, &l_active);

if (zone_is_near_oom(zone))
goto force_reclaim_mapped;
if (swap_tendency >= 100)
reclaim_mapped = 1;


static inline int zone_is_near_oom(struct zone *zone)
return zone->pages_scanned >= (zone->nr_active + zone->nr_inactive)*4;



 * `distress' is a measure of how much trouble we're having
 * reclaiming pages.  0 -> no problems.  100 -> great trouble.
 */distress = 100 >> zone->prev_priority;

 * The point of this algorithm is to decide when to start
 * reclaiming mapped memory instead of just pagecache.  Work out
 * how much memory
 * is mapped.
 */mapped_ratio = ((sc->nr_mapped+sc->nr_anon) * 100) / total_memory;

 * Now decide how much we really want to unmap some pages.  The
 * mapped ratio is downgraded - just because there's a lot of
 * mapped memory doesn't necessarily mean that page reclaim
 * isn't succeeding.
 * The distress ratio is important - we don't want to start
 * going oom.
 * A 100% value of vm_swappiness overrides this algorithm
 * altogether.
 */swap_tendency = mapped_ratio / 2 + distress + vm_swappiness;

 * If there's huge imbalance between active and inactive
 * (think active 100 times larger than inactive) we should
 * become more permissive, or the system will take too much
 * cpu before it start swapping during memory pressure.
 * Distress is about avoiding early-oom, this is about
 * making swappiness graceful despite setting it to low
 * values.
 * Avoid div by zero with nr_inactive+1, and max resulting
 * value is vm_total_pages.
 */imbalance  = zone->nr_active;
imbalance /= zone->nr_inactive + 1;

 * Reduce the effect of imbalance if swappiness is low,
 * this means for a swappiness very low, the imbalance
 * must be much higher than 100 for this logic to make
 * the difference.
 * Max temporary value is vm_total_pages*100.
 */imbalance *= vm_swappiness + 1;
imbalance /= 100;

 * If not much of the ram is mapped, makes the imbalance
 * less relevant, it's high priority we refill the inactive
 * list with mapped pages only in presence of high ratio of
 * mapped pages.
 * Max temporary value is vm_total_pages*100.
 */imbalance *= mapped_ratio;
imbalance /= 100;

/* apply imbalance feedback to swap_tendency */swap_tendency += imbalance;

 * Now use this metric to decide whether to start moving mapped
 * memory onto the inactive list.
 */if (swap_tendency >= 100)
reclaim_mapped = 1;