Skip to contentSkip to conversation

mm/vmscan.c: avoid scanning the whole targets[*] when scan_balance equals SCAN_FILE/SCAN_ANON

PATCH In review Chen Yucong 2 participants 3 messages Jun 6, 2014

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

PATCH 1/1 mm/vmscan.c: avoid scanning the whole targets[*] when scan_balance equals SCAN_FILE/SCAN_ANON

If (scan_balance == SCAN_FILE) is true for shrink_lruvec, then the value of targets[LRU_INACTIVE_ANON] and targets[LRU_ACTIVE_ANON] will be zero. As a result, the value of 'percentage' will also be zero, and the *whole* targets[LRU_INACTIVE_FILE] and targets[LRU_ACTIVE_FILE] will be scanned.

For (scan_balance == SCAN_ANON), there is the same conditions stated above.

But via https://lkml.org/lkml/2013/4/10/334, we can find that the kernel does not prefer reclaiming too many pages from the other LRU. So before recalculating the other LRU scan count based on its original scan targets and the percentage scanning already complete, we should need to check whether 'scan_balance' equals SCAN_FILE/SCAN_ANON.

---
 mm/vmscan.c |    3 +++
 1 file changed, 3 insertions(+)
mm/vmscan.c +3 -0
index d51f7e0..ca3f5f1 100644
@@ -2120,6 +2120,9 @@ static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
 			percentage = nr_file * 100 / scan_target;
 		}
 
+		if (targets[lru] == 0 && targets[lru + LRU_ACTIVE] == 0)
+			break;
+
 		/* Stop scanning the smaller of the LRU */
 		nr[lru] = 0;
 		nr[lru + LRU_ACTIVE] = 0;
Signature · 7 lines
1.7.10.4

--
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>
maintainer
#1 lore raw

Hi Chen,

Quoted 22 lines · Chen Yucong

If (scan_balance == SCAN_FILE) is true for shrink_lruvec, then the value of targets[LRU_INACTIVE_ANON] and targets[LRU_ACTIVE_ANON] will be zero. As a result, the value of 'percentage' will also be zero, and the *whole* targets[LRU_INACTIVE_FILE] and targets[LRU_ACTIVE_FILE] will be scanned.

For (scan_balance == SCAN_ANON), there is the same conditions stated above.

But via https://lkml.org/lkml/2013/4/10/334, we can find that the kernel does not prefer reclaiming too many pages from the other LRU. So before recalculating the other LRU scan count based on its original scan targets and the percentage scanning already complete, we should need to check whether 'scan_balance' equals SCAN_FILE/SCAN_ANON.

---
 mm/vmscan.c |    3 +++
 1 file changed, 3 insertions(+)
mm/vmscan.c +0 -0
index d51f7e0..ca3f5f1 100644

mm/vmscan.c static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) · line 2124

Quoted 5 lines
mm/vmscan.c +2 -0
@@ -2120,6 +2120,9 @@ static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
 			percentage = nr_file * 100 / scan_target;
 		}
 
+		if (targets[lru] == 0 && targets[lru + LRU_ACTIVE] == 0)
+			break;

We have meanwhile included a change that bails out if nr_anon or nr_file are zero, right before that percentage calculation, that should cover the scenario you're describing. It's called:

mm: vmscan: use proportional scanning during direct reclaim and full scan at DEF_PRIORITY

--
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 28 lines · Johannes Weiner

Hi Chen,

Quoted 25 lines · Chen Yucong

If (scan_balance == SCAN_FILE) is true for shrink_lruvec, then the value of targets[LRU_INACTIVE_ANON] and targets[LRU_ACTIVE_ANON] will be zero. As a result, the value of 'percentage' will also be zero, and the *whole* targets[LRU_INACTIVE_FILE] and targets[LRU_ACTIVE_FILE] will be scanned.

For (scan_balance == SCAN_ANON), there is the same conditions stated above.

But via https://lkml.org/lkml/2013/4/10/334, we can find that the kernel does not prefer reclaiming too many pages from the other LRU. So before recalculating the other LRU scan count based on its original scan targets and the percentage scanning already complete, we should need to check whether 'scan_balance' equals SCAN_FILE/SCAN_ANON.

---
 mm/vmscan.c |    3 +++
 1 file changed, 3 insertions(+)
mm/vmscan.c +0 -0
index d51f7e0..ca3f5f1 100644
@@ -2120,6 +2120,9 @@ static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc)
 			percentage = nr_file * 100 / scan_target;
 		}
 
Quoted 8 lines

mm/vmscan.c static void shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) · line 2124

Quoted 2 lines
mm/vmscan.c +2 -0
+		if (targets[lru] == 0 && targets[lru + LRU_ACTIVE] == 0)
+			break;

We have meanwhile included a change that bails out if nr_anon or nr_file are zero, right before that percentage calculation, that should cover the scenario you're describing. It's called:

mm: vmscan: use proportional scanning during direct reclaim and full scan at DEF_PRIORITY

Thanks very much for your reply. Indeed, your patch is more comprehensive and perfect. I think I need to update my local git-repository timely.

thx!
cyc

--
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>