mm: vmscan: fix kswapd nr_to_reclaim repeated calculation

Message ID 20230925035907.1723-1-justinjiang@vivo.com
State New
Headers
Series mm: vmscan: fix kswapd nr_to_reclaim repeated calculation |

Commit Message

Zhiguo Jiang Sept. 25, 2023, 3:59 a.m. UTC
  In kswapd recycling shrink, high watermark is fixed, meaning the 
nr_to_reclaim value is fixed, so there is no need to repeatedly
calculate the nr_to_reclaim value during each iteraton.

Signed-off-by: Zhiguo Jiang <justinjiang@vivo.com>
---
 mm/vmscan.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
 mode change 100644 => 100755 mm/vmscan.c
  

Patch

diff --git a/mm/vmscan.c b/mm/vmscan.c
index a4e44f1c97c1..1aab3549969e
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -6638,7 +6638,9 @@  static bool kswapd_shrink_node(pg_data_t *pgdat,
 	int z;
 
 	/* Reclaim a number of pages proportional to the number of zones */
-	sc->nr_to_reclaim = 0;
+	if (sc->nr_to_reclaim > 0)
+		goto shrink;
+
 	for (z = 0; z <= sc->reclaim_idx; z++) {
 		zone = pgdat->node_zones + z;
 		if (!managed_zone(zone))
@@ -6647,6 +6649,7 @@  static bool kswapd_shrink_node(pg_data_t *pgdat,
 		sc->nr_to_reclaim += max(high_wmark_pages(zone), SWAP_CLUSTER_MAX);
 	}
 
+shrink:
 	/*
 	 * Historically care was taken to put equal pressure on all zones but
 	 * now pressure is applied based on node LRU order.
@@ -6725,6 +6728,7 @@  static int balance_pgdat(pg_data_t *pgdat, int order, int highest_zoneidx)
 		.gfp_mask = GFP_KERNEL,
 		.order = order,
 		.may_unmap = 1,
+		.nr_to_reclaim = 0,
 	};
 
 	set_task_reclaim_state(current, &sc.reclaim_state);