From 2a5cda5ca5fc8b031bd10df6ba360d1b10b1e1d0 Mon Sep 17 00:00:00 2001 From: Liu Shixin Date: Fri, 28 May 2021 13:09:04 +0800 Subject: [PATCH] mm/page_alloc: fix counting of managed_pages hulk inclusion category: bugfix bugzilla: 51887 CVE: NA ------------------------------------------------- The commit f63661566fad (mm/page_alloc.c: clear out zone->lowmem_reserve[] if the zone is empty) clear 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 lowmen_reserve, so fix it. Fixes: f63661566fad ("mm/page_alloc.c: clear out zone->lowmem_reserve[] if the zone is empty") Reported-by: yangerkun Signed-off-by: Liu Shixin Reviewed-by: Kefeng Wang Signed-off-by: Zheng Zengkai --- mm/page_alloc.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 97ca7c18d9d4..67ab4c8fd6cb 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -7796,14 +7796,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; - } } } } -- GitLab