mm/page_alloc: fix counting of managed_pages
authorLiu Shixin <liushixin2@huawei.com>
Tue, 29 Jun 2021 02:42:33 +0000 (19:42 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 29 Jun 2021 17:53:55 +0000 (10:53 -0700)
commit f63661566fad ("mm/page_alloc.c: clear out zone->lowmem_reserve[] if
the zone is empty") clears out zone->lowmem_reserve[] if zone is empty.
But when zone is not empty and sysctl_lowmem_reserve_ratio[i] is set to
zero, zone_managed_pages(zone) is not counted in the managed_pages either.
This is inconsistent with the description of lowmem_reserve, so fix it.

Link: https://lkml.kernel.org/r/20210527125707.3760259-1-liushixin2@huawei.com
Fixes: f63661566fad ("mm/page_alloc.c: clear out zone->lowmem_reserve[] if the zone is empty")
Signed-off-by: Liu Shixin <liushixin2@huawei.com>
Reported-by: yangerkun <yangerkun@huawei.com>
Reviewed-by: Baoquan He <bhe@redhat.com>
Acked-by: David Hildenbrand <david@redhat.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/page_alloc.c

index 2a306c34fda7d29f7614a6c8f18294c2cfbb5561..fc151f6a7dbd980c3aeb1ef91190910fd7cd45d3 100644 (file)
@@ -8240,14 +8240,14 @@ static void setup_per_zone_lowmem_reserve(void)
                        unsigned long managed_pages = 0;
 
                        for (j = i + 1; j < MAX_NR_ZONES; j++) {
-                               if (clear) {
-                                       zone->lowmem_reserve[j] = 0;
-                               } else {
-                                       struct zone *upper_zone = &pgdat->node_zones[j];
+                               struct zone *upper_zone = &pgdat->node_zones[j];
+
+                               managed_pages += zone_managed_pages(upper_zone);
 
-                                       managed_pages += zone_managed_pages(upper_zone);
+                               if (clear)
+                                       zone->lowmem_reserve[j] = 0;
+                               else
                                        zone->lowmem_reserve[j] = managed_pages / ratio;
-                               }
                        }
                }
        }