linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [patch] mm, vmscan: avoid thrashing anon lru when free + file is low
@ 2017-04-18  0:06 David Rientjes
  2017-04-18  1:36 ` Minchan Kim
  2017-04-18  7:11 ` Michal Hocko
  0 siblings, 2 replies; 19+ messages in thread
From: David Rientjes @ 2017-04-18  0:06 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Johannes Weiner, Mel Gorman, linux-kernel, linux-mm

The purpose of the code that commit 623762517e23 ("revert 'mm: vmscan: do
not swap anon pages just because free+file is low'") reintroduces is to
prefer swapping anonymous memory rather than trashing the file lru.

If all anonymous memory is unevictable, however, this insistance on
SCAN_ANON ends up thrashing that lru instead.

Check that enough evictable anon memory is actually on this lruvec before
insisting on SCAN_ANON.  SWAP_CLUSTER_MAX is used as the threshold to
determine if only scanning anon is beneficial.

Otherwise, fallback to balanced reclaim so the file lru doesn't remain
untouched.

Signed-off-by: David Rientjes <rientjes@google.com>
---
 mm/vmscan.c | 41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/mm/vmscan.c b/mm/vmscan.c
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2186,26 +2186,31 @@ static void get_scan_count(struct lruvec *lruvec, struct mem_cgroup *memcg,
 	 * anon pages.  Try to detect this based on file LRU size.
 	 */
 	if (global_reclaim(sc)) {
-		unsigned long pgdatfile;
-		unsigned long pgdatfree;
-		int z;
-		unsigned long total_high_wmark = 0;
-
-		pgdatfree = sum_zone_node_page_state(pgdat->node_id, NR_FREE_PAGES);
-		pgdatfile = node_page_state(pgdat, NR_ACTIVE_FILE) +
-			   node_page_state(pgdat, NR_INACTIVE_FILE);
-
-		for (z = 0; z < MAX_NR_ZONES; z++) {
-			struct zone *zone = &pgdat->node_zones[z];
-			if (!managed_zone(zone))
-				continue;
+		anon = lruvec_lru_size(lruvec, LRU_ACTIVE_ANON, sc->reclaim_idx) +
+		       lruvec_lru_size(lruvec, LRU_INACTIVE_ANON, sc->reclaim_idx);
+		if (likely(anon >= SWAP_CLUSTER_MAX)) {
+			unsigned long total_high_wmark = 0;
+			unsigned long pgdatfile;
+			unsigned long pgdatfree;
+			int z;
+
+			pgdatfree = sum_zone_node_page_state(pgdat->node_id,
+							     NR_FREE_PAGES);
+			pgdatfile = node_page_state(pgdat, NR_ACTIVE_FILE) +
+				    node_page_state(pgdat, NR_INACTIVE_FILE);
+
+			for (z = 0; z < MAX_NR_ZONES; z++) {
+				struct zone *zone = &pgdat->node_zones[z];
+				if (!managed_zone(zone))
+					continue;
 
-			total_high_wmark += high_wmark_pages(zone);
-		}
+				total_high_wmark += high_wmark_pages(zone);
+			}
 
-		if (unlikely(pgdatfile + pgdatfree <= total_high_wmark)) {
-			scan_balance = SCAN_ANON;
-			goto out;
+			if (unlikely(pgdatfile + pgdatfree <= total_high_wmark)) {
+				scan_balance = SCAN_ANON;
+				goto out;
+			}
 		}
 	}
 

^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2017-06-04 22:28 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-18  0:06 [patch] mm, vmscan: avoid thrashing anon lru when free + file is low David Rientjes
2017-04-18  1:36 ` Minchan Kim
2017-04-18 21:32   ` David Rientjes
2017-04-19  0:14     ` Minchan Kim
2017-04-19 23:24       ` David Rientjes
2017-04-20  6:09         ` Minchan Kim
2017-05-01 21:34           ` [patch v2] " David Rientjes
2017-05-02  8:02             ` Michal Hocko
2017-05-02 20:41               ` David Rientjes
2017-05-03  6:15                 ` Michal Hocko
2017-05-03  7:06                   ` Michal Hocko
2017-05-03  8:49                     ` Michal Hocko
2017-05-03 22:52                       ` David Rientjes
2017-05-04 11:43                         ` Michal Hocko
2017-05-31 15:20             ` Michal Hocko
2017-06-02 20:36             ` Andrew Morton
2017-06-04 22:27               ` David Rientjes
2017-04-19  7:04     ` [patch] " Michal Hocko
2017-04-18  7:11 ` Michal Hocko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).