From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) (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 52D4534846A for ; Wed, 13 May 2026 13:21:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.51 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778678510; cv=none; b=s/Omf4Y7he9tnahnYk4PnNf+XVt0V2Io76UBfrBMbz4uHLpVQEF16MCKESk7vZf+nwtvvnjAJInhZW6Db+CykohzQYGxnAkHUb61OkRAXfvzkf48dVBySUC6ZXg4RP0G5by47Q7Ax3BNL5Xo6Jlb9JahBeif3GfKmS950UlIJUM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778678510; c=relaxed/simple; bh=2kYODvgzjF/tAj7NooRDeUyy6Bc1leC9/cRydSPcw2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ha3zG05+VpfbNTkw7m48Df1MirFOtf15Vg+Fcs02K2Z8s2iDkNrR6ONaBpVTKkVX4pvX++6NOka+shil+2+DAd/PRusOIq7/lbyWkBPPxsmZHJ84AB7K8yR7jtacvvtREawwo67Z56FOe1dJGu7DfQJ2RReTE5KmWUG6gt/4Qzw= 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=fS2p08lH; arc=none smtp.client-ip=209.85.216.51 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="fS2p08lH" Received: by mail-pj1-f51.google.com with SMTP id 98e67ed59e1d1-3665a90bcd3so5007493a91.1 for ; Wed, 13 May 2026 06:21:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1778678508; x=1779283308; 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=bX0eh9yAs1Ger4W6kkJzAbg+VRL/E8mjDpD877qpJLc=; b=fS2p08lHtCjLH8s4o47Svl+0aRM8E9LmuinvgCXOgaokPBwkXGMLsU8J80EXyAvlM0 s+ZtqFYXhHHb3tv1kMElpHBxaH5x6tkPoSgVsHJPNp1syZloLeWY1mu7JIZ7vacN34cK 0xF5+j2d0dPOzWjeS+dk7LiMjoE+PUfGstrsWv1KtZMEFO2FC2IyWG/iZ9gNqWunO+mJ UOZfxQ9DO31eQfnPseuov5OfkuBQ4tVzZ5gyw7EzmCRCacWtW2gQJszVwBrZzoJnIorc Lm+5ZMPaIJ57HXtQSBqh4RXgvbeAY8dV0USBRwXzUalyEiTfbqfeMi3x+RjpgVpldt0I N2jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778678508; x=1779283308; 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=bX0eh9yAs1Ger4W6kkJzAbg+VRL/E8mjDpD877qpJLc=; b=L4ssM9DcdazHD2J1Gum69PAjkRZmqVfP8huv2P0KAbKHuRIck4j7W+klc32C16v51r qprrsFVTcke6/l0CisNBrexAkRDtVRWaHJKR+q8ELD5odbxLdXzlDiAcdsqJg1zg8bb1 VREHfSUfTDIB5SCc7aWWJja2rGFzeTvWUPTCPtlGfbZWHBLGEi0qyCIlT5kZ9IZt6jrT /9SrM4GoMV6pspUB1ysRhrKHWBzIdtzyjcAXtwEqXRH3PreYNXjLxIWsBrT4YuHi4xdW H3cML6s6vgtQVXlBdhy9at+kQt8YCfqRbMfMh/WjBAAQ6UMymkGE90dSY1pg07KliKir qD7w== X-Forwarded-Encrypted: i=1; AFNElJ9CJn1WQB8azVjv1GJxAG11WR+QGWjtPHVg+FlEueaITpxptSaPRGELcdDyBV0fUxd3pX62WmjYEDTCdho=@vger.kernel.org X-Gm-Message-State: AOJu0Yxf0IQwpWnzZiWbwJamxaVkYxTZ2LuFSXoWn2vdJXgNH4qFyf6w uj5/kmO3nDP14ww4Mhj03JBabBOE3xvtCMfdccdFZWuRiqxIjXRtsFi0WGOSgE02fv0= X-Gm-Gg: Acq92OEkTHp7NcSxzbfZoVwZzf7nmYDPW5TIi+xZbw0YucLH2JD/wTFYwPGOQOl1L+p rez1ixOOPl+tTsaqr0U9JSaGI4b19HeZxFNmGn/+hDkC3z/rK3BWBUSah+HA9HcP/Uk6SxqkqpI E5j4B0cvv+hQSzU0KtzLs/HyHHzOkwJ4WCSLYT8Rp9qNlD98dgXBTS6boozqJvXEwCoWch2cfG0 NnQvsLlrntEYgSL0Mx5ApQRE7+F9VzDAPd19Spz0GFScd+C+o/1fwa5HZC45W3UygaB7uCBnN// uSeHHVRU6L6Lbr12HKRGyjVz54/b6Q1FPweiTAEw8qhA/4qHdCQ/5X8vjv2nfEotFgZJOBV8U58 IQg8HHtCMN7gqdCrzz+NpcQRk/J+HUQlddbMWam69vzou5TCkOULt3e6kUUwBFzSCC5NT+eMNxi BWM/tayMRIizOTXYHE/ixgEmdDcWGNbzCS/leEn4aUHwiGh672RxXtWKFnmcTc793HUGWeoK4= X-Received: by 2002:a17:90b:3f86:b0:366:33a6:9921 with SMTP id 98e67ed59e1d1-368f3a909b4mr3551470a91.4.1778678508386; Wed, 13 May 2026 06:21:48 -0700 (PDT) Received: from PXLDJ45XCM.bytedance.net ([61.213.176.10]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-368edf7cbc2sm3098406a91.14.2026.05.13.06.21.42 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 13 May 2026 06:21:47 -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 55/69] mm/sparse: Decouple section activation from ZONE_DEVICE Date: Wed, 13 May 2026 21:20:20 +0800 Message-ID: <20260513132044.41690-9-songmuchun@bytedance.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260513132044.41690-1-songmuchun@bytedance.com> References: <20260513130542.35604-1-songmuchun@bytedance.com> <20260513132044.41690-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 sparse_add_section()/section_activate() currently takes struct dev_pagemap only to obtain the compound page order. Pass the order explicitly instead of routing it through a ZONE_DEVICE specific structure. This removes the dev_pagemap dependency from the generic sparse memory population path and keeps the interface usable for other callers (if possible). Signed-off-by: Muchun Song --- include/linux/memory_hotplug.h | 4 ++-- mm/memory_hotplug.c | 4 ++-- mm/sparse-vmemmap.c | 14 ++++++-------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/include/linux/memory_hotplug.h b/include/linux/memory_hotplug.h index 815e908c4135..083f0abea62d 100644 --- a/include/linux/memory_hotplug.h +++ b/include/linux/memory_hotplug.h @@ -304,8 +304,8 @@ extern void remove_pfn_range_from_zone(struct zone *zone, unsigned long start_pfn, unsigned long nr_pages); extern int sparse_add_section(int nid, unsigned long pfn, - unsigned long nr_pages, struct vmem_altmap *altmap, - struct dev_pagemap *pgmap); + unsigned long nr_pages, unsigned int order, + struct vmem_altmap *altmap); extern void sparse_remove_section(unsigned long pfn, unsigned long nr_pages, struct vmem_altmap *altmap); extern struct zone *zone_for_pfn_range(enum mmop online_type, diff --git a/mm/memory_hotplug.c b/mm/memory_hotplug.c index 5c60533677a1..ef1595bdfd3a 100644 --- a/mm/memory_hotplug.c +++ b/mm/memory_hotplug.c @@ -385,6 +385,7 @@ int __add_pages(int nid, unsigned long pfn, unsigned long nr_pages, unsigned long cur_nr_pages; int err; struct vmem_altmap *altmap = params->altmap; + unsigned int order = params->pgmap ? params->pgmap->vmemmap_shift : 0; if (WARN_ON_ONCE(!pgprot_val(params->pgprot))) return -EINVAL; @@ -412,8 +413,7 @@ int __add_pages(int nid, unsigned long pfn, unsigned long nr_pages, /* Select all remaining pages up to the next section boundary */ cur_nr_pages = min(end_pfn - pfn, SECTION_ALIGN_UP(pfn + 1) - pfn); - err = sparse_add_section(nid, pfn, cur_nr_pages, altmap, - params->pgmap); + err = sparse_add_section(nid, pfn, cur_nr_pages, order, altmap); if (err) break; cond_resched(); diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c index a807210fe9e1..667424aadd6b 100644 --- a/mm/sparse-vmemmap.c +++ b/mm/sparse-vmemmap.c @@ -613,16 +613,14 @@ static void section_deactivate(unsigned long pfn, unsigned long nr_pages, } static struct page * __meminit section_activate(int nid, unsigned long pfn, - unsigned long nr_pages, struct vmem_altmap *altmap, - struct dev_pagemap *pgmap) + unsigned long nr_pages, unsigned int order, + struct vmem_altmap *altmap) { struct mem_section *ms = __pfn_to_section(pfn); struct mem_section_usage *usage = NULL; struct page *memmap; - unsigned int order; int rc; - order = pgmap ? pgmap->vmemmap_shift : 0; /* All sub-sections within a section must share the same order. */ if (nr_pages < PAGES_PER_SECTION && section_order(ms) && section_order(ms) != order) return ERR_PTR(-ENOTSUPP); @@ -667,8 +665,8 @@ static struct page * __meminit section_activate(int nid, unsigned long pfn, * @nid: The node to add section on * @start_pfn: start pfn of the memory range * @nr_pages: number of pfns to add in the section + * @order: section order * @altmap: alternate pfns to allocate the memmap backing store - * @pgmap: alternate compound page geometry for devmap mappings * * This is only intended for hotplug. * @@ -682,8 +680,8 @@ static struct page * __meminit section_activate(int nid, unsigned long pfn, * * -ENOMEM - Out of memory. */ int __meminit sparse_add_section(int nid, unsigned long start_pfn, - unsigned long nr_pages, struct vmem_altmap *altmap, - struct dev_pagemap *pgmap) + unsigned long nr_pages, unsigned int order, + struct vmem_altmap *altmap) { unsigned long section_nr = pfn_to_section_nr(start_pfn); struct mem_section *ms; @@ -694,7 +692,7 @@ int __meminit sparse_add_section(int nid, unsigned long start_pfn, if (ret < 0) return ret; - memmap = section_activate(nid, start_pfn, nr_pages, altmap, pgmap); + memmap = section_activate(nid, start_pfn, nr_pages, order, altmap); if (IS_ERR(memmap)) return PTR_ERR(memmap); -- 2.54.0