From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 1E726C531C9 for ; Sat, 25 Jul 2026 17:22:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=Xn80PDrPoYmVE/gZZcSr6poxbSgIZJJhbmexI8e3Z+M=; b=lZNHreGZj5kYHtwHi0F0/Kobi1 T6ObpqBMo3H3npbe1bySpVzSIXAKJAn9ZPzbFx7ocsQfgRyQRbLJkDPu15eiNN1fsdQgFR8zoJ9pu vuMwR4tbbxG0S6RnXmZqt4zl1syS4JH06wgrfBQq8z92SJa+KqTIJEkQ+krGISxuT1/wBBrYldSIU CdiQ2DyCWDkuxubpxcvS4Dpuw/Nir19uyWgcM9rAGVzDgBmC++ix6xpal89ObQyCdU13GV4ODxRXk ML1FG/LrfgkLrC4xuPfG8hbLKKW2pCBh+njxyWWwsPoXRkEc2tP/yUCaUB9bf6bllgbZ6GlwBLSMw PKWTjjyw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.99.1 #2 (Red Hat Linux)) id 1wng4y-00000000ajR-1Mid; Sat, 25 Jul 2026 17:22:28 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.99.1 #2 (Red Hat Linux)) id 1wng4x-00000000aiM-0eqg for kexec@lists.infradead.org; Sat, 25 Jul 2026 17:22:27 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id E516F40539; Sat, 25 Jul 2026 17:22:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D1A61F000E9; Sat, 25 Jul 2026 17:22:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785000146; bh=Xn80PDrPoYmVE/gZZcSr6poxbSgIZJJhbmexI8e3Z+M=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=k9ADnvgRLAT1SUxTsKF9d4LF/AfjHAhp30CKZZ4xHx/Mty3O2gf470bETOgQV8lEL ucbqWEP7u1bb6Zcoc4N6TPD0Fqti7oUcarFYgVeYXEZ5fXsEstM+oDIDWQ1nygxwGq Cyo7/J1SYH1iVZO/13GH5gG9By97d9K075yfTkqdkGN+3LAhEMQKZzsUOVAr7rnZzX PVGsVzveaGUBGQwagw2O5641eKCu6gipE9cy/nMxdZhNP8L7bD2kxHH/vkboMceREN 6FkK9fGOzKJGjWGpfTIZvJ+r0x9tDNa1Tf+keK2NHb5RK8LUCFkZx+Z5pDaAAZaGtg v2USjYoRLnaRg== 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, Muchun Song Subject: [PATCH v4 16/21] mm/mm_init: simplify deferred_free_pages() migratetype init Date: Sat, 25 Jul 2026 19:21:16 +0200 Message-ID: <20260725172133.4018491-17-pratyush@kernel.org> X-Mailer: git-send-email 2.55.0.229.g6434b31f56-goog In-Reply-To: <20260725172133.4018491-1-pratyush@kernel.org> References: <20260725172133.4018491-1-pratyush@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: kexec@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "kexec" Errors-To: kexec-bounces+kexec=archiver.kernel.org@lists.infradead.org From: Muchun Song deferred_free_pages() open-codes two loops to initialize the pageblock migratetype for a range of pages. Replace them with pageblock_migratetype_init_range() to remove the duplication and make the code clearer (Note that deferred_free_pages() may be called from atomic context). Link: https://lore.kernel.org/20260612035903.2468601-6-songmuchun@bytedance.com Signed-off-by: Muchun Song Acked-by: Mike Rapoport (Microsoft) Acked-by: Oscar Salvador Signed-off-by: Pratyush Yadav (Google) --- Notes: This patch is taken from Muchun's series [0]. The patch as of today is in mm-unstable. [0] https://lore.kernel.org/linux-mm/20260612035903.2468601-6-songmuchun@bytedance.com/ mm/mm_init.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index 84d4b1c997bc..30355effe1f2 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -674,15 +674,15 @@ static inline void fixup_hashdist(void) static inline void fixup_hashdist(void) {} #endif /* CONFIG_NUMA */ -#ifdef CONFIG_ZONE_DEVICE +#if defined(CONFIG_ZONE_DEVICE) || defined(CONFIG_DEFERRED_STRUCT_PAGE_INIT) static __meminit void pageblock_migratetype_init_range(unsigned long pfn, - unsigned long nr_pages, int migratetype) + unsigned long nr_pages, int migratetype, bool atomic) { const unsigned long end = pfn + nr_pages; for (pfn = pageblock_align(pfn); pfn < end; pfn += pageblock_nr_pages) { init_pageblock_migratetype(pfn_to_page(pfn), migratetype, false); - if (IS_ALIGNED(pfn, PAGES_PER_SECTION)) + if (!atomic && IS_ALIGNED(pfn, PAGES_PER_SECTION)) cond_resched(); } } @@ -1142,7 +1142,7 @@ void __ref memmap_init_zone_device(struct zone *zone, compound_nr_pages(pfn, altmap, pgmap)); } - pageblock_migratetype_init_range(start_pfn, nr_pages, MIGRATE_MOVABLE); + pageblock_migratetype_init_range(start_pfn, nr_pages, MIGRATE_MOVABLE, false); pr_debug("%s initialised %lu pages in %ums\n", __func__, nr_pages, jiffies_to_msecs(jiffies - start)); @@ -1981,12 +1981,12 @@ static void __init deferred_free_pages(unsigned long pfn, if (!nr_pages) return; + pageblock_migratetype_init_range(pfn, nr_pages, mt, true); + page = pfn_to_page(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 +1994,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); - __free_pages_core(page, 0, MEMINIT_EARLY); - } + for (i = 0; i < nr_pages; i++) + __free_pages_core(page + i, 0, MEMINIT_EARLY); } /* Completion tracking for deferred_init_memmap() threads */ -- 2.55.0.229.g6434b31f56-goog