From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A1F48324B33 for ; Fri, 12 Jun 2026 03:59:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781236779; cv=none; b=K1SYETZ79xDvtyI4BOZ9AYMS87QLyIghqQoMFuwL0fj42jUhq46EYsJa7HbfL7N3sWfrd7WlebFi2+k5G6ky7QOy4/tOKlZWCZ5myZKNdLD00uNMI/BqYMQ0KzhSxWJoXsC4o9zE8R2z8ldiAdLEWIY4E9pWBIK9cGCEYfIev94= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781236779; c=relaxed/simple; bh=2MpzxjLbgsJ+bxhFvnw/n258pY5XlizFDUxIBknOheU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sHY2pCj//WSADXLuZHl8bkDfMJMAl6kRNz6M89+IRW+B0iBxB7kW1EvG4tkW3697mnwFqKkrPs0nYP4X3TemA2TNTJuDMXj9p/n4lWoD1ZuDLg7qB+pZHPg9bJW7QZDAhrTNlJ48TX+8Jg2u8gqwSkUFsRKNd7zHPBwT7YCOCzA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b=QPt5sIiU; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=bytedance.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bytedance.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bytedance.com header.i=@bytedance.com header.b="QPt5sIiU" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-8423f1d8902so313548b3a.1 for ; Thu, 11 Jun 2026 20:59:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1781236777; x=1781841577; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TPNP/s8YQi9s7EHLxOTbc3dEJlnMSCHwNqhJjmE6eW0=; b=QPt5sIiU4OAOMSBXM7k0Kn4svPLpaI7Pm5bd79sVOvLn0zkTa5127hdtS8HnBs/+Og 7VDrUZ1V3XHd5wplbuOr57pKSiwkuWtdUvv6ZppAEF97secaTJz/URJgx4Xc8la3FRMD b0/bFWsT84O5aBuMoKOxt3IY3VBGgmkgD11Q7y2ibw+ZA1Pp+5GtCyJm8L9fx4mkwrnU XD/8LLENYjfpa5fLs4moYOqVtAzv8DgsMZLOxAbO/5JADpBroBKc1zvU2KqzR8SKQ6bn vFbE0fACmpXF5r39QNnNwl2iRTUy8nblQyuqYSB00vbwHKZKTIm9+kVQ6/lbe2DmPE9S C2Dg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781236777; x=1781841577; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=TPNP/s8YQi9s7EHLxOTbc3dEJlnMSCHwNqhJjmE6eW0=; b=B+Uus6ib+/6zw1gz5Xl5z0iBExEj4TGCtNDeQCsc9mKGesr1RY6QLJ2QQzC7/qppN3 scVGmGo22y9UorgZWp5xS8uY8hj/AqixqD3xK+VcClA8kTQgwJ3kgh/MDc3CxqYfF/IE BbkKlOp9yo5Vj7RH7TG3mbxQcbahxjvtJ4T2kG469vmT8Ly1+v6QBVKnPEPm8ao1I1UE nCB6oUewWqpHV3q/RydDcCzTJhQez709MKR9uDFJrhQpZ+ShOX9ujwEOmNHNDLaoDCZ1 i0SZOKlgj9Yxkji4Z0ZRW7lQVlODN/TLmFBAz4ykH/RkHROgAfXhyi+wWye84pt0Qn9i VeKg== X-Forwarded-Encrypted: i=1; AFNElJ8eckJxq8NDdP4y1ZXIuTD7oucG7Kymod2xx4cWfy+7I0GPvCgzq3GKssnEVpejxJ0ziV/SEQ0vRsM2vHI=@vger.kernel.org X-Gm-Message-State: AOJu0YwZnxPYqJ9/aZy77ja31yjDbKUPHFIqzb6dOiP49QYUceicMZOI E664QjDLyqX8YpvZ1rNEVhZSfT24XLbeaLSYsdXMxAwCxfyKezzT9meoUyU4bqyn9r0= X-Gm-Gg: Acq92OH9GKUsMEE2YZ7PGzavyPP71j8luCjMAi8XUAkFMSUAE/0ePv5+vtFDmM2gjiZ Iwd/cAwHRF7KqxkaoWjmHYqFRdB4qYojce7u6wZiCIftuG5YBjTuXTsgacy3RL32EFXk46XqHK8 0RX6JfNoBYwF0yISf3/VSTW+kxbUwL9LeEB9vJTW4pc19WIkDwzR5halHJO1686cKV+gPv+/uV4 IirN6cy9o8spje7eiIG8X7EthBpgwvFkElRIjARyimuwkZaNVBxLtuqDFRaYxjOTav4LrpLD8q2 U4A3u+ERoUCn9TVtuW1cegmPG1Yjw+quTiD9CLPSjIjRfOEjY4e4VyQEwBvYL3tGpb2kuQzEKRM vQi3D/wx3sNbpemOZO/KDEVAQc06jQG+SqscOF1ZP9X5fLsyXRogM9w4WPCnq8e9jrmmfHnAtV0 5vE2PASsKOvqXuEdnx7ZpZkfA+OMWSs0C0BDCXW3FQ3B8= X-Received: by 2002:a05:6a00:148d:b0:842:6a3b:60d8 with SMTP id d2e1a72fcca58-8434ce0d4b4mr1113011b3a.30.1781236776918; Thu, 11 Jun 2026 20:59:36 -0700 (PDT) Received: from n232-176-004.byted.org ([36.110.163.99]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8434ad03fdcsm643352b3a.24.2026.06.11.20.59.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2026 20:59:36 -0700 (PDT) From: Muchun Song To: Oscar Salvador , David Hildenbrand , Andrew Morton , Madhavan Srinivasan , Michael Ellerman Cc: Muchun Song , Mike Rapoport , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Nicholas Piggin , Christophe Leroy , Ritesh Harjani , "Aneesh Kumar K . V" , linuxppc-dev@lists.ozlabs.org, Mike Kravetz , Muchun Song Subject: [PATCH v4 05/19] mm/mm_init: Simplify deferred_free_pages() migratetype init Date: Fri, 12 Jun 2026 11:58:49 +0800 Message-ID: <20260612035903.2468601-6-songmuchun@bytedance.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260612035903.2468601-1-songmuchun@bytedance.com> References: <20260612035903.2468601-1-songmuchun@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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). Signed-off-by: Muchun Song Acked-by: Mike Rapoport (Microsoft) Acked-by: Oscar Salvador --- 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 92e88fca717f..5c7359693ba2 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.54.0