mm/vmscan: simplify shrink_node()
authorHaifeng Xu <haifeng.xu@shopee.com>
Tue, 11 Apr 2023 06:17:57 +0000 (06:17 +0000)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 18 Apr 2023 23:30:02 +0000 (16:30 -0700)
The difference between sc->nr_reclaimed and nr_reclaimed is computed three
times.  Introduce a new variable to record the value, so it only needs to
be computed once.

Link: https://lkml.kernel.org/r/20230411061757.12041-1-haifeng.xu@shopee.com
Signed-off-by: Haifeng Xu <haifeng.xu@shopee.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
mm/vmscan.c

index 98719e72b5e2d48c1fc14b10af8ffd67f5f8a26e..7f2441d6dfb267b4d1375d55fb5f75ea269e9a6e 100644 (file)
@@ -6463,7 +6463,7 @@ static void shrink_node_memcgs(pg_data_t *pgdat, struct scan_control *sc)
 static void shrink_node(pg_data_t *pgdat, struct scan_control *sc)
 {
        struct reclaim_state *reclaim_state = current->reclaim_state;
-       unsigned long nr_reclaimed, nr_scanned;
+       unsigned long nr_reclaimed, nr_scanned, nr_node_reclaimed;
        struct lruvec *target_lruvec;
        bool reclaimable = false;
 
@@ -6489,13 +6489,14 @@ again:
                reclaim_state->reclaimed_slab = 0;
        }
 
+       nr_node_reclaimed = sc->nr_reclaimed - nr_reclaimed;
+
        /* Record the subtree's reclaim efficiency */
        if (!sc->proactive)
                vmpressure(sc->gfp_mask, sc->target_mem_cgroup, true,
-                          sc->nr_scanned - nr_scanned,
-                          sc->nr_reclaimed - nr_reclaimed);
+                          sc->nr_scanned - nr_scanned, nr_node_reclaimed);
 
-       if (sc->nr_reclaimed - nr_reclaimed)
+       if (nr_node_reclaimed)
                reclaimable = true;
 
        if (current_is_kswapd()) {
@@ -6557,8 +6558,7 @@ again:
            test_bit(LRUVEC_CONGESTED, &target_lruvec->flags))
                reclaim_throttle(pgdat, VMSCAN_THROTTLE_CONGESTED);
 
-       if (should_continue_reclaim(pgdat, sc->nr_reclaimed - nr_reclaimed,
-                                   sc))
+       if (should_continue_reclaim(pgdat, nr_node_reclaimed, sc))
                goto again;
 
        /*