From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) (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 3F3FA425CE1 for ; Wed, 13 May 2026 13:10:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.169 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778677842; cv=none; b=dJL/ulgTQaZdSeYNgc7vAOY20doh5HD6INJHeip7MZC1Lie6ikOIaI9+xbYi8nWS0rTL0KiQuwBgokSEOthXtlBD1123rxjm9Fgom1b3OaHOtZEwqOA2HwS3gGnbIUkW9jIMYLtC7rxbWxuErbvWWDyOsa+F+IESP/zeTnBDPPM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778677842; c=relaxed/simple; bh=F7eDWkX60fEIXLIYmsiv0NvLkMYOs1/A8Hm9Uk+SczM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jl+dL7IGJSdOqf2EOvKCOOTxLpL8NoRrxpNelR/cffW3lK+QVq7BBjx9w9FE+SfOy8qinUTYAbv6wa2B8HkB1xturh4t1Wd0236dCUhV9j2upacfQSwYlcW7NByBuz53wXJDPyM0dK3vfapBIIQSnsMpJwH8gzqc/ZzzAft87n0= 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=XdG00aKr; arc=none smtp.client-ip=209.85.214.169 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="XdG00aKr" Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2baca4df358so41252215ad.2 for ; Wed, 13 May 2026 06:10:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1778677840; x=1779282640; 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=LjpGKbpR87QdpAXzElJEcltafcXUZyW4c5xpVY2ebxg=; b=XdG00aKrXL9Jr7jYz8aYXHzNgWIIjlfeNUJ4mkBFAUHckIp7ImO/2D+MRBsNNTjHD0 KRiSWLaYRS5H7wf5eG+xRQ8vhPLps7VPrNaJ3ba/9z+eo+rSP3gYRwVDHVq9A2hRbjWD W7lgqA3GoprdieygDa77UYtZHmPL3G2wH2m87A/69z5P5R3orRS2dCOitOHU3rssZE4t aMULCijle5CQmxZQbHBBs3PuhyHkheY58e6w3GHrwxdmpnbEB5riVoTr7dLoHFiCLVLY wTBRwXa54X45E9rPKa9RPQ5sv4qrEvpnqyygZyU6i+Edg2sqK3Nimqlo7knVI84G34aQ ZpEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778677840; x=1779282640; 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=LjpGKbpR87QdpAXzElJEcltafcXUZyW4c5xpVY2ebxg=; b=LvYzZXQuRX2gs5qjIrbrtNTWy3ZxT44Vla3D31xrhpY/hTfKrVm8w22MvOJK8Ti5hl ib3W6oO/DHVhzFLJoeoIBxGERhqC5h0evnT553eIAncWrsNbeFZ04bIg1dlcIMA4dUoC WA4dip7mjxs7tABicaLOQEHdsduNIy1D7/NKEGY1ftWD7eBBcCIeT0Tr1fzm273g8zX5 0qIyJKxmOd1DP8B25DJ6O4uIb06hBtwCD9aI44LasDMUlq2VMv8zoJLBYPXQIF7z5Vuz p8gmlvVPoJTxf3jLaMXLmC8jZFeDSPT3kF1Z488i23f9aBwGlp9xcrVGjmfdukjNwuwd J8qA== X-Forwarded-Encrypted: i=1; AFNElJ/Y2c5/CRpXEfGo2Bi5mBsDOplTIEpkcnOWKUpycsyhLCiLq5yE5HWPg+cdT1/YdCr1weuBv9kMCPyKDmo=@vger.kernel.org X-Gm-Message-State: AOJu0Yz7jdpZwbsTOfuv4OsSQsTEl5uGos2HYUr7h1sTb2Jof0R3YDdv LiPSWdZilUxH9HcN44engtkL50z+CqQohxFPTM9rCsWUPGEUl6SsxEOQUxDcdYd34Mc= X-Gm-Gg: Acq92OGTNQKD0JjXVBS5g2//mmFRquHQ7oI3cLI5gcGqk1wroaecmCUECAMvb3qYEXT n63XnMlgXAiojGHkV/ghyEAuSputGhatHqzrWSec/uqK0akPMWIC+8hfFX/FiSWEO3Vxqnpo2oN ysbHZCOSj0dW2HQjkFOWDQUkmiStWt09CpVXithec5sh7Mr31RLC14waxtxStQ9BKJfdYK8GwAE uIYonlHMr/mJ42RHifBSP2KSJdJOhLetk2/hKAvGllbPZBzKh/0Pqn2BkLNZo2nUxuith0U3ZI3 MA2HI4n7ARcPm81lrYBtuWECcfMM36bnogBhQFBRE34hdpRT+5hnxceZC9VSuoekjouWOpU4sjy jOuU6whJPci2JZvMnL+BWp5FRhvQbPDNMFjJL/k/HkvneAm75XxRENkOv9kjgANBXOODro20M51 hMtL0biL+nRKl4l4pvWrIizG0VmRreWXFWwXjH2TkAcRrOi+rVM4Xm58+60IdMIxH8rqx5OA== X-Received: by 2002:a17:903:4b03:b0:2ba:99a2:c44e with SMTP id d9443c01a7336-2bd275c6b33mr34992375ad.21.1778677840351; Wed, 13 May 2026 06:10:40 -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.10.35 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 13 May 2026 06:10:40 -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 34/69] mm/sparse: Inline usemap allocation into sparse_init_nid() Date: Wed, 13 May 2026 21:05:02 +0800 Message-ID: <20260513130542.35604-35-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 After removing SPARSEMEM_VMEMMAP_PREINIT, sparse_init_nid() no longer needs the transient sparse_usagebuf state and its helper wrappers. Allocate the usemap buffer directly in sparse_init_nid(), pass it to sparse_init_one_section(), and drop sparse_usage_init(), sparse_usage_fini(), and sparse_init_early_section(). Signed-off-by: Muchun Song --- include/linux/mmzone.h | 3 --- mm/sparse.c | 46 +++++++----------------------------------- 2 files changed, 7 insertions(+), 42 deletions(-) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index b9baef8cca91..a60fd5785fa5 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -2265,9 +2265,6 @@ static inline bool section_vmemmap_optimizable(const struct mem_section *section return section_order(section) >= OPTIMIZABLE_FOLIO_MIN_ORDER; } -void sparse_init_early_section(int nid, struct page *map, unsigned long pnum, - unsigned long flags); - #ifndef CONFIG_HAVE_ARCH_PFN_VALID /** * pfn_valid - check if there is a valid memory map entry for a PFN diff --git a/mm/sparse.c b/mm/sparse.c index eab37504819d..54c38ea08190 100644 --- a/mm/sparse.c +++ b/mm/sparse.c @@ -237,42 +237,6 @@ void __weak __meminit vmemmap_populate_print_last(void) { } -static void *sparse_usagebuf __meminitdata; -static void *sparse_usagebuf_end __meminitdata; - -/* - * Helper function that is used for generic section initialization, and - * can also be used by any hooks added above. - */ -void __init sparse_init_early_section(int nid, struct page *map, - unsigned long pnum, unsigned long flags) -{ - BUG_ON(!sparse_usagebuf || sparse_usagebuf >= sparse_usagebuf_end); - sparse_init_one_section(__nr_to_section(pnum), pnum, map, - sparse_usagebuf, SECTION_IS_EARLY | flags); - sparse_usagebuf = (void *)sparse_usagebuf + mem_section_usage_size(); -} - -static int __init sparse_usage_init(int nid, unsigned long map_count) -{ - unsigned long size; - - size = mem_section_usage_size() * map_count; - sparse_usagebuf = memblock_alloc_node(size, SMP_CACHE_BYTES, nid); - if (!sparse_usagebuf) { - sparse_usagebuf_end = NULL; - return -ENOMEM; - } - - sparse_usagebuf_end = sparse_usagebuf + size; - return 0; -} - -static void __init sparse_usage_fini(void) -{ - sparse_usagebuf = sparse_usagebuf_end = NULL; -} - int __meminit section_nr_vmemmap_pages(unsigned long pfn, unsigned long nr_pages, struct vmem_altmap *altmap, struct dev_pagemap *pgmap) { @@ -312,8 +276,11 @@ static void __init sparse_init_nid(int nid, unsigned long pnum_begin, unsigned long map_count) { unsigned long pnum; + struct mem_section_usage *usage; - if (sparse_usage_init(nid, map_count)) + usage = memblock_alloc_node(map_count * mem_section_usage_size(), + SMP_CACHE_BYTES, nid); + if (!usage) panic("Failed to allocate usemap for node %d\n", nid); for_each_present_section_nr(pnum_begin, pnum) { @@ -329,9 +296,10 @@ static void __init sparse_init_nid(int nid, unsigned long pnum_begin, panic("Failed to allocate memmap for section %lu\n", pnum); memmap_boot_pages_add(section_nr_vmemmap_pages(pfn, PAGES_PER_SECTION, NULL, NULL)); - sparse_init_early_section(nid, map, pnum, 0); + sparse_init_one_section(__nr_to_section(pnum), pnum, map, usage, + SECTION_IS_EARLY); + usage = (void *)usage + mem_section_usage_size(); } - sparse_usage_fini(); } /* -- 2.54.0