From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (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 EDB723290C9 for ; Wed, 13 May 2026 13:08:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778677700; cv=none; b=HK5vLcC69waKkMm86rXGc86oJlEKV0pElCxXijIV1ED8rjiF4r2mAI3m/HzmGFp3YDLZoyFIfhoE6scdFUspOpimNmCizjiVTf3c3hjLbFBw3Y3GtitcX44N3m0LLepH9HJH1JpwfBRmtptjMc4oeJqbyyQVrzd2yJZVCnqJiXg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778677700; c=relaxed/simple; bh=lC7wUV5IK5dRjzUC6k68pGfvPCvjhy/7t7i3ha5PGFg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fQiu4eaHpd5eQ5iqe2gqND5kjLrQ56C59JdxOloHIhmBTj3ByJ2N/TKr9cVzNrDo57bveZTKkCcUmo2hxHVdEyhdH4shP6nqt92bI2tNsu/A2xB5IiVXMz2urb9tT3WpQVPwyQRpzA6flwomT24ORvRTEiF0anHpxqI0Clsr+Yk= 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=D2bDuLmc; arc=none smtp.client-ip=209.85.216.48 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="D2bDuLmc" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-366330b6751so4494682a91.1 for ; Wed, 13 May 2026 06:08:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1778677698; x=1779282498; 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=DYuPvzchRBegO13WUUAUtcrTx/HN+dPBsLEtJBVtJ7M=; b=D2bDuLmc3a813eWKKTJaQHVXJN6mqCbBGE1YGs/eRaz165xE8T0tRkksC2ZXWJnV9b jGhjCjwoQiodF4Ik32Kcq6wnUTYfZp50tCBFJxeZgp2vWfmxWcFwRE5y8ylVCCLExlUn 0aZxG4Pq4IxQI3bmtXfw5cy1H+WLb3dmY4q45jw/gogD17OBg7mot0SmoOPUTEHCF/x9 oxzqkR5tH/1BT+NdqAAmuKDms6v6dcsBlGez6FWBM3F/8UgtiJY/w/GgWTWIW4x2GBj1 fqAcfSh2acrpIH++TGo4Lpd7HSc7PShu1aJbSXbns3qu3ogSgDFoMO9lG0YdONh1xUC9 Vj5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778677698; x=1779282498; 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=DYuPvzchRBegO13WUUAUtcrTx/HN+dPBsLEtJBVtJ7M=; b=dmsjeBeQvK3sjrkyw1VNCkB/RVBCGq8xMRxS+f2viZ++9g8BbE6bsiS2vbIcaYJviY 2x/Zyf+MbBkMX+Szj+Mx8XacJ0A/3eX0BuDuYws0a56C8w3ChP8nh45P9JoGlfH6r1IT H+F0EDnSTKvzWaXDAjEk460kjfp7FDpxd8kMMY3HRpPz+5+aNtuBEnxV95UIg2GrHiaf Rn6hKZ4kCigmEokPJ7teoo9H2PZXYffUbhmEjL4OOEBmiVIMMCy9bayusyK+XlVlVjT7 D+0TG+ZVaWJnSUPgUb4Ei1J1BHZ/E7bsyIn31efZz4Jd13Ly688cmYSi0JQ/o9xGy0cl jVWg== X-Forwarded-Encrypted: i=1; AFNElJ/f+xCBr13sBnqWHwjscE9I/EK5X6okZfbOVLZsClt3k+Ju2u0/TQOCdqbv9uAiFpZlRtnJjwGJ44s3WOM=@vger.kernel.org X-Gm-Message-State: AOJu0YxKbFEaZbhr0GaRs4bl/jJAz1J9G+L2rK1JBVXtyymd5cA1pzJ0 VdA1OLxHG2AC6Cw1D2q5xvOKsNND35qfToeUP4vXk30TIE0My1lBGwxg5saPIIbwPq8= X-Gm-Gg: Acq92OF8sHEtZnwQvkGKU5/pxUIeY9kTpJZm8ucaGIYv1EJRJ6K+1Upgo935TTjbpzd 3voqJrvfHY5j/VcsPwr09eSUKxoaNvSTBfD6x/ZHKOGJb4HfYzJ2BV0nIXnwa1PDG+9BpOjVfrV yGcxs9dGH3+H7UICzNi35LP8qJoQ7hlycGUDqsyeWNdTmMUAZdZe2t9aGloMc/78v1wNPq7OUNw kk889O2TUpsk8/cJOazkrFZ8OQEqTxKKGCQmAeG6fasRE4Ikpps1zbVUvkMuhmA4ao/cPtjtrSy RBTGQ8GZZRyq2qENQK8K8e4S+XMqkZSshagpulgUjCasAJBpFl7CkiWB6C332tJ8lZVmx2c+V14 VveAqaBu833icVXaRCMV+MdMcNnLsZy4PCoiuJVo6J/LVuDvmLKuy5PFHpQfUm9Z5iYvKk6ChT5 gvsL4DND9PZI27sb5UuYQdPa+Rr13BuTHYDmQA3197lUT7UAQWBc/wZ4bagag= X-Received: by 2002:a17:903:46c4:b0:2bd:2de3:51ad with SMTP id d9443c01a7336-2bd3043ca95mr32656455ad.34.1778677697132; Wed, 13 May 2026 06:08:17 -0700 (PDT) Received: from PXLDJ45XCM.bytedance.net ([61.213.176.6]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2baf1e90854sm166641925ad.66.2026.05.13.06.08.12 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 13 May 2026 06:08:16 -0700 (PDT) From: Muchun Song To: Andrew Morton , David Hildenbrand , Muchun Song , Oscar Salvador , Michael Ellerman , Madhavan Srinivasan Cc: Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Nicholas Piggin , Christophe Leroy , Ackerley Tng , Frank van der Linden , aneesh.kumar@linux.ibm.com, joao.m.martins@oracle.com, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, Muchun Song Subject: [PATCH v2 08/69] mm/mm_init: Defer sparse_init() until after zone initialization Date: Wed, 13 May 2026 21:04:36 +0800 Message-ID: <20260513130542.35604-9-songmuchun@bytedance.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260513130542.35604-1-songmuchun@bytedance.com> References: <20260513130542.35604-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 free_area_init() is responsible for initializing pgdat and zone state. Calling sparse_init() from there mixes in later vmemmap and struct page setup, which makes the initialization flow less clear. Defer sparse_init(), sparse_vmemmap_init_nid_late(), and memmap_init() until after free_area_init() completes, when zone initialization is fully done. This keeps free_area_init() focused on zone setup and ensures that sparse_init() runs with the relevant zone state already available. This is also a prerequisite for later hugetlb vmemmap changes that need zone information during early sparse vmemmap setup. Signed-off-by: Muchun Song Reviewed-by: Mike Rapoport (Microsoft) --- v1->v2: - Restore the set_pageblock_order() change suggested by Mike Rapoport - Add Mike Rapoport's Reviewed-by --- mm/mm_init.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/mm/mm_init.c b/mm/mm_init.c index 12fe21c4e26c..c14491c2dad3 100644 --- a/mm/mm_init.c +++ b/mm/mm_init.c @@ -1826,7 +1826,6 @@ static void __init free_area_init(void) bool descending; arch_zone_limits_init(max_zone_pfn); - sparse_init(); start_pfn = PHYS_PFN(memblock_start_of_DRAM()); descending = arch_has_descending_max_zone_pfns(); @@ -1915,11 +1914,7 @@ static void __init free_area_init(void) } } - for_each_node_state(nid, N_MEMORY) - sparse_vmemmap_init_nid_late(nid); - calc_nr_kernel_pages(); - memmap_init(); /* disable hash distribution for systems with a single node */ fixup_hashdist(); @@ -2691,10 +2686,17 @@ void __init __weak mem_init(void) void __init mm_core_init_early(void) { + int nid; + hugetlb_cma_reserve(); hugetlb_bootmem_alloc(); free_area_init(); + + sparse_init(); + for_each_node_state(nid, N_MEMORY) + sparse_vmemmap_init_nid_late(nid); + memmap_init(); } /* -- 2.54.0