Skip to contentSkip to conversation

vmscan: fix swapout on sequential IO

RFC PATCH In review Rik van Riel 3 participants 6 messages Jul 23, 2008 – Jul 24, 2008

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

RFC PATCH 1/1 vmscan: fix swapout on sequential IO

Only force the scanning of every LRU list if we could not easily find a page to evict. This preserves the balancing done by get_scan_ratio(), while ensuring the VM will make progress when there is serious memory pressure.

---
This should fix the "dd if=/dev/sda of=/dev/null causes swapout" problem that has been seen with the new split LRU VM.

 mm/vmscan.c |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
mm/vmscan.c +10 -7
Index: linux-2.6.26-rc8-mm1/mm/vmscan.c
===================================================================
@@ -1447,24 +1447,27 @@ static unsigned long shrink_zone(int pri
 	unsigned long nr_to_scan;
 	unsigned long nr_reclaimed = 0;
 	unsigned long percent[2];	/* anon @ 0; file @ 1 */
+	unsigned int force_scan = 0;
 	enum lru_list l;
 
+	/*
+         * If we do not immediately find pages to evict, put some
+         * pressure on every LRU list to guarantee progress.
+         */
+	if (priority < DEF_PRIORITY - 2)
+		force_scan = 1;
+
 	get_scan_ratio(zone, sc, percent);
 
 	for_each_evictable_lru(l) {
 		if (scan_global_lru(sc)) {
 			int file = is_file_lru(l);
-			int scan;
-			/*
-			 * Add one to nr_to_scan just to make sure that the
-			 * kernel will slowly sift through each list.
-			 */
-			scan = zone_page_state(zone, NR_LRU_BASE + l);
+			int scan = zone_page_state(zone, NR_LRU_BASE + l);
 			if (priority) {
 				scan >>= priority;
 				scan = (scan * percent[file]) / 100;
 			}
-			zone->lru[l].nr_scan += scan + 1;
+			zone->lru[l].nr_scan += scan + force_scan;
 			nr[l] = zone->lru[l].nr_scan;
 			if (nr[l] >= sc->swap_cluster_max)
 				zone->lru[l].nr_scan = 0;

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#1 lore raw

Hi Rik,

Quoted 41 lines · Rik van Riel

From: Rik van Riel <[email protected]>

Only force the scanning of every LRU list if we could not easily find a page to evict. This preserves the balancing done by get_scan_ratio(), while ensuring the VM will make progress when there is serious memory pressure.

---
This should fix the "dd if=/dev/sda of=/dev/null causes swapout" problem that has been seen with the new split LRU VM.

 mm/vmscan.c |   17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

Index: linux-2.6.26-rc8-mm1/mm/vmscan.c
===================================================================

mm/vmscan.c +8 -3
@@ -1447,24 +1447,27 @@ static unsigned long shrink_zone(int pri
 	unsigned long nr_to_scan;
 	unsigned long nr_reclaimed = 0;
 	unsigned long percent[2];	/* anon @ 0; file @ 1 */
+	unsigned int force_scan = 0;
 	enum lru_list l;
 
+	/*
+         * If we do not immediately find pages to evict, put some
+         * pressure on every LRU list to guarantee progress.
+         */
+	if (priority < DEF_PRIORITY - 2)
+		force_scan = 1;
+
 	get_scan_ratio(zone, sc, percent);
 
 	for_each_evictable_lru(l) {
 		if (scan_global_lru(sc)) {
 			int file = is_file_lru(l);
-			int scan;
-			/*
-			 * Add one to nr_to_scan just to make sure that the

mm/vmscan.c static unsigned long shrink_zone(int pri · line 1470

Quoted 10 lines
mm/vmscan.c +2 -4
-			 * kernel will slowly sift through each list.
-			 */
-			scan = zone_page_state(zone, NR_LRU_BASE + l);
+			int scan = zone_page_state(zone, NR_LRU_BASE + l);
 			if (priority) {
 				scan >>= priority;
 				scan = (scan * percent[file]) / 100;
 			}
-			zone->lru[l].nr_scan += scan + 1;
+			zone->lru[l].nr_scan += scan + force_scan;

The accumulation aspect is not gone, though. If the system has reached the force-scan priority swap_cluster_max times, the next scan, even if long after the last scan, will scan bogus lists.

mm/vmscan.c static unsigned long shrink_zone(int pri · line 1473

Quoted 3 lines
mm/vmscan.c +0 -0
 			nr[l] = zone->lru[l].nr_scan;
 			if (nr[l] >= sc->swap_cluster_max)
 				zone->lru[l].nr_scan = 0;

Hannes

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#2 lore raw
Quoted 6 lines · On Wed, 23 Jul 2008 20:48:10 +0200 Johannes Weiner <[email protected]> wrote:

mm/vmscan.c static unsigned long shrink_zone(int pri · line 1470

Quoted 2 lines
mm/vmscan.c +1 -1
-			zone->lru[l].nr_scan += scan + 1;
+			zone->lru[l].nr_scan += scan + force_scan;

The accumulation aspect is not gone, though. If the system has reached the force-scan priority swap_cluster_max times, the next scan, even if long after the last scan, will scan bogus lists.

Which I suspect is the desired behaviour.

Better go out of balance a little, than risk an OOM kill.

Signature · 7 lines
All rights reversed.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#3 lore raw

Hi,

Quoted 10 lines · Rik van Riel
Quoted 6 lines · On Wed, 23 Jul 2008 20:48:10 +0200 Johannes Weiner <[email protected]> wrote:

mm/vmscan.c static unsigned long shrink_zone(int pri · line 1470

Quoted 2 lines
mm/vmscan.c +1 -1
-			zone->lru[l].nr_scan += scan + 1;
+			zone->lru[l].nr_scan += scan + force_scan;

The accumulation aspect is not gone, though. If the system has reached the force-scan priority swap_cluster_max times, the next scan, even if long after the last scan, will scan bogus lists.

Quoted 3 lines

Which I suspect is the desired behaviour.

Better go out of balance a little, than risk an OOM kill.

Okay, I agree with that. It will at least keep the balance for some longer :)

Hannes

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

Reviewed-by on v1 1/1
#4 lore raw
In reply to Rik van Riel

mm/vmscan.c static unsigned long shrink_zone(int pri · line 1473

Quoted 5 lines
mm/vmscan.c +1 -1
-			zone->lru[l].nr_scan += scan + 1;
+			zone->lru[l].nr_scan += scan + force_scan;
 			nr[l] = zone->lru[l].nr_scan;
 			if (nr[l] >= sc->swap_cluster_max)
 				zone->lru[l].nr_scan = 0;

looks good to me.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw
Quoted 9 lines · On Thu, 24 Jul 2008 15:26:44 +0900 KOSAKI Motohiro…

mm/vmscan.c static unsigned long shrink_zone(int pri · line 1473

Quoted 5 lines
mm/vmscan.c +1 -1
-			zone->lru[l].nr_scan += scan + 1;
+			zone->lru[l].nr_scan += scan + force_scan;
 			nr[l] = zone->lru[l].nr_scan;
 			if (nr[l] >= sc->swap_cluster_max)
 				zone->lru[l].nr_scan = 0;

looks good to me.

I'm still benchmarking it, against 2.6.26, 2.6.26-rc8-mm1 and 2.6.26-rc8-mm1 with the "evict cache first" patch.

So far the results look promising. I hope to publish the benchmark results later today, when I have a full set of all tests against all these kernels.

I have been running tests for about a week now.

Signature · 7 lines
All rights reversed.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>