Re: [PATCH v2 1/2] mm/page_alloc: Do not calculate node's total pages and memmap pages when empty

From: David Hildenbrand
Date: Tue Jun 21 2022 - 03:45:24 EST


On 21.06.22 06:17, Oscar Salvador wrote:
> 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 substract 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.
>
> Signed-off-by: Oscar Salvador <osalvador@xxxxxxx>
> ---
> mm/page_alloc.c | 16 ++++++++++++----
> 1 file changed, 12 insertions(+), 4 deletions(-)
>
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index e008a3df0485..2b9b2422ba32 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -7361,6 +7361,10 @@ static void __init calculate_node_totalpages(struct pglist_data *pgdat,
> unsigned long realtotalpages = 0, totalpages = 0;
> enum zone_type i;
>
> + /* Skip calculation for memoryless nodes */
> + if (pgdat_is_empty(pgdat))
> + 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;
> @@ -7393,6 +7397,7 @@ static void __init calculate_node_totalpages(struct pglist_data *pgdat,
> 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);
> @@ -7610,6 +7615,12 @@ static void __init free_area_init_core(struct pglist_data *pgdat)
> size = zone->spanned_pages;
> freesize = zone->present_pages;
>
> + /* No pages? Nothing to calculate then. */
> + if (!size) {
> + zone_init_internals(zone, j, nid, 0);
> + continue;
> + }
> +
> /*
> * Adjust freesize so that it accounts for how much memory
> * is used by this zone for memmap. This affects the watermark
> @@ -7647,9 +7658,6 @@ static void __init free_area_init_core(struct pglist_data *pgdat)
> */
> zone_init_internals(zone, j, nid, freesize);
>
> - if (!size)
> - continue;
> -
> set_pageblock_order();
> setup_usemap(zone);
> init_currently_empty_zone(zone, zone->zone_start_pfn, size);
> @@ -7730,7 +7738,7 @@ static void __init free_area_init_node(int nid)
> pgdat->node_start_pfn = start_pfn;
> pgdat->per_cpu_nodestats = NULL;
>
> - if (start_pfn != end_pfn) {
> + if (!pgdat_is_empty(pgdat)) {
> pr_info("Initmem setup node %d [mem %#018Lx-%#018Lx]\n", nid,
> (u64)start_pfn << PAGE_SHIFT,
> end_pfn ? ((u64)end_pfn << PAGE_SHIFT) - 1 : 0);


It's worth noting that the check in pgdat_is_empty() is slightly
different. I *think* it doesn't matter in practice, yet I wonder if we
should simply fixup (currently unused) pgdat_is_empty().

Anyhow

Reviewed-by: David Hildenbrand <david@xxxxxxxxxx>

--
Thanks,

David / dhildenb