Skip to contentSkip to conversation

OOM kills if swappiness set to 0, swap storms otherwise

DISCUSSION Shantanu Goel 1 participant 1 message Apr 6, 2006

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

Charles,

Can you please try the attached patch against 2.6.16.1 which I use on my desktop since I encountered the same issues when running GNOME/Firefox etc. After booting the patched kernel, leave swappiness unchanged but do the following:

echo 1 > /proc/sys/vm/mapped_bias

This should allow mapped memory to stay pretty close to 80% as implied by the default swappiness value of 60 and prevent the swap storms.

Andrew et al, details on the patch are as follows.

1. Unmapped pages are kept the inactive list as much as possible.

2. Only partially written pages are marked as referenced so kswapd can initiate writeback on the first scan for sequentially written files.

3. The scanner will set PG_reclaim for pages found in writeback.

4. The scanner will scan the LRU twice. On the first pass, the distress logic is disabled while on the second pass, it is applied as before. This permits a full scan of the inactive list before distress swapping begins.

5. The slab scanner only takes into account the size of the inactive list and scans the slab at 1/2 the rate of the inactive list for DEFAULT_SEEKS. This prevents spurious pageouts during heavy slab usage such as when running updatedb.

6. reclaim_mapped is made part of scan_control so it can be used by shrink_list() in addition to refill_inactive_zone() to prevent mapped memory reclamation and staying within the bounds dictated by swappiness.

Thanks,
Shantanu

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

include/linux/swap.h +1 -0
@@ -175,6 +175,7 @@
 extern int try_to_free_pages(struct zone **, gfp_t);
 extern int shrink_all_memory(int);
 extern int vm_swappiness;
+extern int vm_mapped_bias;
 
 #ifdef CONFIG_NUMA
 extern int zone_reclaim_mode;
include/linux/sysctl.h +1 -0
@@ -186,6 +186,7 @@
 	VM_PERCPU_PAGELIST_FRACTION=30,/* int: fraction of pages in each percpu_pagelist */
 	VM_ZONE_RECLAIM_MODE=31, /* reclaim local zone memory before going off node */
 	VM_ZONE_RECLAIM_INTERVAL=32, /* time period to wait after reclaim failure */
+	VM_MAPPED_BIAS=33,	/* bias reclaim towards preserving mapped memory */
 };
 
 
kernel/sysctl.c +10 -0
@@ -916,6 +916,16 @@
 		.strategy	= &sysctl_jiffies,
 	},
 #endif
+	{
+		.ctl_name	= VM_MAPPED_BIAS,
+		.procname	= "mapped_bias",
+		.data		= &vm_mapped_bias,
+		.maxlen		= sizeof(vm_mapped_bias),
+		.mode		= 0644,
+		.proc_handler	= &proc_dointvec,
+		.strategy	= &sysctl_intvec,
+		.extra1		= &zero,
+	},
 	{ .ctl_name = 0 }
 };
 
mm/filemap.c +8 -1
@@ -2020,7 +2020,14 @@
 			if (status >= 0)
 				status = -EFAULT;
 		unlock_page(page);
-		mark_page_accessed(page);
+
+		/*
+		 * Only mark page accessed for partial write
+		 * when mapped bias is in effect.
+		 */
+		if (!vm_mapped_bias || offset + bytes != PAGE_CACHE_SIZE)
+			mark_page_accessed(page);
+
 		page_cache_release(page);
 		if (status < 0)
 			break;
mm/page_alloc.c +2 -3
@@ -360,7 +360,6 @@
 			1 << PG_private |
 			1 << PG_locked	|
 			1 << PG_active	|
-			1 << PG_reclaim	|
 			1 << PG_slab	|
 			1 << PG_swapcache |
 			1 << PG_writeback |
@@ -518,7 +517,6 @@
 			1 << PG_locked	|
 			1 << PG_active	|
 			1 << PG_dirty	|
-			1 << PG_reclaim	|
 			1 << PG_slab    |
 			1 << PG_swapcache |
 			1 << PG_writeback |
@@ -534,7 +532,8 @@
 
 	page->flags &= ~(1 << PG_uptodate | 1 << PG_error |
 			1 << PG_referenced | 1 << PG_arch_1 |
-			1 << PG_checked | 1 << PG_mappedtodisk);
+			1 << PG_checked | 1 << PG_mappedtodisk |
+			1 << PG_reclaim);
 	set_page_private(page, 0);
 	set_page_refs(page, order);
 	kernel_map_pages(page, 1 << order, 1);
mm/swap.c +17 -4
@@ -103,12 +103,23 @@
 {
 	struct zone *zone = page_zone(page);
 
+	if (unlikely(PageReclaim(page)))
+		ClearPageReclaim(page);
+
 	spin_lock_irq(&zone->lru_lock);
 	if (PageLRU(page) && !PageActive(page)) {
-		del_page_from_inactive_list(zone, page);
-		SetPageActive(page);
-		add_page_to_active_list(zone, page);
-		inc_page_state(pgactivate);
+		/*
+		 * Never activate an unmapped page when
+		 * mapped bias is in effect.
+		 */
+		if (!vm_mapped_bias || page_mapped(page)) {
+			del_page_from_inactive_list(zone, page);
+			SetPageActive(page);
+			add_page_to_active_list(zone, page);
+			inc_page_state(pgactivate);
+		} else if (page->lru.prev != &zone->inactive_list) {
+			list_move(&page->lru, &zone->inactive_list);
+		}
 	}
 	spin_unlock_irq(&zone->lru_lock);
 }
@@ -127,6 +138,8 @@
 		ClearPageReferenced(page);
 	} else if (!PageReferenced(page)) {
 		SetPageReferenced(page);
+		if (PageReclaim(page))
+			ClearPageReclaim(page);
 	}
 }
 
mm/vmscan.c +164 -58

385 lines not on this page · raw message