blob: 9c6b30548fadded13bc1f7771e451731066950c6 [file] [log] [blame]
From: Oscar Salvador <osalvador@suse.de>
Subject: mm/page_alloc: do not calculate node's total pages and memmap pages when empty
Patch series "A minor hotplug refactoring".
This patch (of 3):
free_area_init_node() calls calculate_node_totalpages() and
free_area_init_core(). The former to get node's {spanned,present}_pages,
and the latter to calculate, among other things, how many pages per zone
we spent on memmap_pages, which is used to subtract zone's free pages.
On memoryless nodes, it is pointless to perform such a bunch of work, so
make sure we skip the calculations when having a node or empty zone.
Link: https://lkml.kernel.org/r/20220307150725.6810-1-osalvador@suse.de
Link: https://lkml.kernel.org/r/20220307150725.6810-2-osalvador@suse.de
Signed-off-by: Oscar Salvador <osalvador@suse.de>
Cc: David Hildenbrand <david@redhat.com>
Cc: Michal Hocko <mhocko@kernel.org>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
---
mm/page_alloc.c | 10 ++++++++++
1 file changed, 10 insertions(+)
--- a/mm/page_alloc.c~mm-page_alloc-do-not-calculate-nodes-total-pages-and-memmap-pages-when-empty
+++ a/mm/page_alloc.c
@@ -7291,6 +7291,10 @@ static void __init calculate_node_totalp
unsigned long realtotalpages = 0, totalpages = 0;
enum zone_type i;
+ /* Skip calculation for memoryless nodes */
+ if (node_start_pfn == node_end_pfn)
+ goto no_pages;
+
for (i = 0; i < MAX_NR_ZONES; i++) {
struct zone *zone = pgdat->node_zones + i;
unsigned long zone_start_pfn, zone_end_pfn;
@@ -7323,6 +7327,7 @@ static void __init calculate_node_totalp
realtotalpages += real_size;
}
+no_pages:
pgdat->node_spanned_pages = totalpages;
pgdat->node_present_pages = realtotalpages;
pr_debug("On node %d totalpages: %lu\n", pgdat->node_id, realtotalpages);
@@ -7540,6 +7545,10 @@ static void __init free_area_init_core(s
size = zone->spanned_pages;
freesize = zone->present_pages;
+ /* No pages? Nothing to calculate then. */
+ if (!size)
+ goto no_pages;
+
/*
* Adjust freesize so that it accounts for how much memory
* is used by this zone for memmap. This affects the watermark
@@ -7575,6 +7584,7 @@ static void __init free_area_init_core(s
* when the bootmem allocator frees pages into the buddy system.
* And all highmem pages will be managed by the buddy system.
*/
+no_pages:
zone_init_internals(zone, j, nid, freesize);
if (!size)
_