From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3855B4F7978 for ; Thu, 9 Jul 2026 17:39:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783618754; cv=none; b=lEWL1QThQWduS2WqLLhYERm8TjCCtGEhUVUYj3djZQQjWyoU41+ErDmutehsaEcVE2yI15U0jIDEKL/pVMWE9uQ8M7mbIw+CzdpF9SG6BXG0+dw1c/AJU0AjCT1XUtwLifuRshcbF57lYbP6UBUnmZxck20zpL97d0M/wlgp3Aw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783618754; c=relaxed/simple; bh=x4LnskUTm8nKmRk9S2IOpBRHInZVp+BHYiYiSIoRBUo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZkqP+PoRrT8/s1nETTvEp94SdP09DT1B/5umeNI4TKLA0Lc8ek7PGp8si+Rr2+bC0NJgysYdux68C4K3BpIT2kpTOOGUFNKWCSr+WSmQkvmCntLdMjlgvSDSvfMT30gbo5AWgetX3083s/2mimpGEr+dMyRY9DwN2qC0/9wKkA4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=NgYUfxJC; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="NgYUfxJC" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE1111F00A3E; Thu, 9 Jul 2026 17:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1783618753; bh=s0TyfHDGp9MFMmZhGlGKvQfEHqtuRGyQhEAHo3riGeA=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=NgYUfxJCriwCprEgHQEZJJpPIibQJGmufQxvjuMW7DlOy9/xHqorXKwDUOzWSnDya yiHQPp3Idtq5IrWbUxyb8URxr9iTPsMQerVZwgUMEDto+TQOnX/i98EsP803g0nbVV bi3yNedZnxPX/iMhIzJFa09S1WlQpNuS7CYWP5LNGVuMFDRrk7JWe8B82WUBvhcv7b osmv5mmUmxDjJ7+kBleFRTbACSv6vSo8Pn+eN6t0zvelZHH58zIaOUedzzIQwSQgcE UgQik0N+HAdHdFyF82VDCEmbhaLC/QdJVcxa6yHicokMfyFEcBVAYR6nakKABVtZSn 1FWEwzCjzHq2A== From: Pratyush Yadav To: Mike Rapoport , Pasha Tatashin , Pratyush Yadav , Alexander Graf , Muchun Song , Oscar Salvador , David Hildenbrand , Andrew Morton , Jason Miu , Jork Loeser Cc: kexec@lists.infradead.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 16/21] mm/mm_init: init deferred page migratetype in deferred_init_pages() Date: Thu, 9 Jul 2026 19:38:05 +0200 Message-ID: <20260709173821.429921-17-pratyush@kernel.org> X-Mailer: git-send-email 2.55.0.141.g00534a21ce-goog In-Reply-To: <20260709173821.429921-1-pratyush@kernel.org> References: <20260709173821.429921-1-pratyush@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: "Pratyush Yadav (Google)" The deferred pages are initialized in deferred_init_pages(), but their migratetype is initialized later when freeing them in deferred_free_pages(). Setting the migrate type is part of initializing the pages, so move it to deferred_init_pages(). This simplifies the logic in deferred_free_pages(), which now only does the freeing. For non-max-order-aligned pages, it also drops the if (pageblock_aligned) for each freed page, which in theory should be a tiny bit faster. Another motivation for this change is that in a coming patch, KHO will need to update the migrate type for its scratch pages. Moving all the pageblock init in one place makes that simpler. Signed-off-by: Pratyush Yadav (Google) --- mm/mm_init.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index 84d4b1c997bc..bd9dc1829005 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1985,8 +1985,6 @@ static void __init deferred_free_pages(unsigned long pfn, /* Free a large naturally-aligned chunk if possible */ if (nr_pages == MAX_ORDER_NR_PAGES && IS_MAX_ORDER_ALIGNED(pfn)) { - for (i = 0; i < nr_pages; i += pageblock_nr_pages) - init_pageblock_migratetype(page + i, mt, false); __free_pages_core(page, MAX_PAGE_ORDER, MEMINIT_EARLY); return; } @@ -1994,11 +1992,8 @@ static void __init deferred_free_pages(unsigned long pfn, /* Accept chunks smaller than MAX_PAGE_ORDER upfront */ accept_memory(PFN_PHYS(pfn), nr_pages * PAGE_SIZE); - for (i = 0; i < nr_pages; i++, page++, pfn++) { - if (pageblock_aligned(pfn)) - init_pageblock_migratetype(page, mt, false); + for (i = 0; i < nr_pages; i++, page++, pfn++) __free_pages_core(page, 0, MEMINIT_EARLY); - } } /* Completion tracking for deferred_init_memmap() threads */ @@ -2017,15 +2012,23 @@ static inline void __init pgdat_init_report_one_done(void) * Return number of pages initialized. */ static unsigned long __init deferred_init_pages(struct zone *zone, - unsigned long pfn, unsigned long end_pfn) + unsigned long start_pfn, unsigned long end_pfn, + enum migratetype mt) { int nid = zone_to_nid(zone); - unsigned long nr_pages = end_pfn - pfn; + unsigned long nr_pages = end_pfn - start_pfn, pfn = start_pfn; int zid = zone_idx(zone); struct page *page = pfn_to_page(pfn); for (; pfn < end_pfn; pfn++, page++) __init_single_page(page, pfn, zid, nid); + + /* Now initialize migrate types for these pages. */ + pfn = pageblock_align(start_pfn); + page = pfn_to_page(pfn); + for (; pfn < end_pfn; pfn += pageblock_nr_pages, page += pageblock_nr_pages) + init_pageblock_migratetype(page, mt, false); + return nr_pages; } @@ -2067,7 +2070,7 @@ deferred_init_memmap_chunk(unsigned long start_pfn, unsigned long end_pfn, unsigned long mo_pfn = ALIGN(spfn + 1, MAX_ORDER_NR_PAGES); unsigned long chunk_end = min(mo_pfn, epfn); - nr_pages += deferred_init_pages(zone, spfn, chunk_end); + nr_pages += deferred_init_pages(zone, spfn, chunk_end, mt); deferred_free_pages(spfn, chunk_end - spfn, mt); spfn = chunk_end; -- 2.55.0.141.g00534a21ce-goog