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 49657424D47 for ; Sat, 1 Aug 2026 08:49:33 +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=1785574175; cv=none; b=ZMPtk96KXdHk8vCxCUBzRTN/6vKqP/ZVneQltG2tS7kl7uZwLbEKzwWIKGLHv1i4k9FTOnEINqH/e1D4sc64yDNAf5qqjkFHAouldjnJOxKSa3Ev2tDWU9BN66slJJKM9nrIFtOlqxqiyZNlJuEgl/PubvjmSR3k4cM/+wuQBfw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785574175; c=relaxed/simple; bh=tSkmKXgfbj1g4uW8+F0ASLiaVAWVaGRHZnI/uT2YAW8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=B6McG4UPBz+TPgOaLR0sJy0XFiLkMEg6M0/lYKfM/2QH3HfkxdTbq3MgBOBhvYHmC59lCE+V7pu6uC14nJsZRg5y9U2ZQBAWb/52WKte+Jy8wZHaYH3yGvwxWUVatRxSsCmX3+SG0ocm2O9KdiMo8LrCKFt0wZRsluFVwb7hz3s= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=IygCmeR7; 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="IygCmeR7" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 87BF81F00ADF; Sat, 1 Aug 2026 08:49:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1785574172; bh=DcIy9f09G7AFfaW0m/xEV6z6X9TFYUkoxNnVWt25+18=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=IygCmeR712ERaVNGY3E7VqhV3DY/W14mNeAS42TBhexbvQmzSwMxzK5hayLtEpm98 rGuTR741l4DbCb0rk9Dz+cyeSO2r3AkYhm1lT2gDC42bUav8jn5KR43bxs35SBEw4L 1+qcCZN2Vb2kUgL9rp+VA8/tT63HG+mEg1G1GDQW0iqdm1essHXttw/dmf6padVHhR 5R9PvjgA+dM+ilQI/DySB7jm6Z0rzcS6w1jjQOrHe54G3rQSCwS6RbU62gmBKWfdBL iLcmhKAVEbZcOmAvQ45vZpJluIuWWnxpzx2IMEh/W5aGfPJ8+MBNiIpUFEYUFgzWcN CdAKM6EFcRWJQ== 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 v6 16/22] mm/mm_init: simplify deferred_free_pages() migratetype init Date: Sat, 1 Aug 2026 10:48:25 +0200 Message-ID: <20260801084833.1897543-17-pratyush@kernel.org> X-Mailer: git-send-email 2.55.0.571.g244d577d93-goog In-Reply-To: <20260801084833.1897543-1-pratyush@kernel.org> References: <20260801084833.1897543-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: 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.571.g244d577d93-goog