From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from va-1-115.ptr.blmpb.com (va-1-115.ptr.blmpb.com [209.127.230.115]) (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 5E118407CE2 for ; Wed, 3 Jun 2026 08:04:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.115 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780473900; cv=none; b=eGTv3nmxgd86EIPAILuT9KqDgViO+BRatwumKQWbf6vQ3BTcIYxnNZkj4LpYqk2h0QQ0n/aRfq/qgR2lElyLYJHENv6yrE/e/AIWrm32CYyIII/V7gzJxyXatvZgkPRYShInVsBHYFwGp5K3hwMNPtuD6xlLJqtcbm/7KoxkUes= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780473900; c=relaxed/simple; bh=TV9B3FF8uyNzCN29bSzOpcQAbaH6iSVb+B/b0Zh9c0w=; h=To:In-Reply-To:Content-Type:Cc:From:Message-Id:Mime-Version: Subject:Date:References; b=ODgBSHzJQCytK7+2od/AzwhQTwrRXRNMtic8b9M7MGQkx/CfesYxZu8fDaS6C7p1Jb0sIX2/MLiuZA5GDSPe1oXe9f1p/Tse8ZZ6Jps+f6o8bMf9sLqvA5v0CopMINuA4HoeMZOXMR8E8yGSq6vFKUpQN/hHZo1GKOj6KjiXGYI= 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=fOClk2CL; arc=none smtp.client-ip=209.127.230.115 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="fOClk2CL" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1780473894; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=Wk9MRIIObAkXzp6VZckmtUtqVfitvWEYaMcAPnuhTg0=; b=fOClk2CL1fCwzT3+vuaOHqsI7g5da5AScnzI84M2/HrGKXqxQrH4IPvNIHKS3TxVjyxM2Z VwcAqVELhm1mJS5Jrmlx2v2SgVi7W8wZU3PkB+nodYQ/qhJ3BAm9UHoTvdckGxPm2D6L9x egKnpB+fJeGVp48JQRIr4kUNcyMq8Go7tDmCSgORlhH8367V2nOEoSgZ/KNVOZ/2HRg/qt VfryU/jR3qHqofObntNIVieU04cbqrnmdgbKUL2HiCGvfpjyQXpwmXEYdrQhYMBJMG8zx1 rX+OEjJ7trpkY2JANC+C2RpU8o5q/J3iGZNIxu5udZ2lGtPjynn1E0LD1Bvmgg== To: , , , , , , , , , In-Reply-To: <20260603080152.64728-1-lizhe.67@bytedance.com> Content-Transfer-Encoding: 7bit X-Mailer: git-send-email 2.45.2 Content-Type: text/plain; charset=UTF-8 Cc: , , , , , From: "Li Zhe" Message-Id: <20260603080152.64728-4-lizhe.67@bytedance.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Subject: [PATCH v4 3/8] mm: add a set_page_section_from_pfn() helper Date: Wed, 3 Jun 2026 16:01:47 +0800 References: <20260603080152.64728-1-lizhe.67@bytedance.com> X-Original-From: Li Zhe X-Lms-Return-Path: Callers that want to update section bits from a PFN currently need to open-code: set_page_section(page, pfn_to_section_nr(pfn)); and guard that sequence with #ifdef SECTION_IN_PAGE_FLAGS. Add set_page_section_from_pfn() to wrap that update in one place. When section bits are stored in page flags, the helper derives the section number from the PFN and updates the page flags. Otherwise it degrades to a no-op. Convert set_page_links() to use the new helper so later ZONE_DEVICE fast-path patches can also update section bits without open-coding SECTION_IN_PAGE_FLAGS at each callsite. This keeps the PFN-to-section translation local to the configurations that actually store section bits in struct page flags, and avoids exposing that detail to generic callers. No functional change intended. Signed-off-by: Li Zhe Reviewed-by: Mike Rapoport (Microsoft) --- include/linux/mm.h | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 06bbe9eba636..1b0de1eef4c9 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2507,11 +2507,26 @@ static inline void set_page_section(struct page *page, unsigned long section) page->flags.f |= (section & SECTIONS_MASK) << SECTIONS_PGSHIFT; } +static inline void set_page_section_from_pfn(struct page *page, + unsigned long pfn) +{ + set_page_section(page, pfn_to_section_nr(pfn)); +} + static inline unsigned long memdesc_section(memdesc_flags_t mdf) { return (mdf.f >> SECTIONS_PGSHIFT) & SECTIONS_MASK; } #else /* !SECTION_IN_PAGE_FLAGS */ +static inline void set_page_section(struct page *page, unsigned long section) +{ +} + +static inline void set_page_section_from_pfn(struct page *page, + unsigned long pfn) +{ +} + static inline unsigned long memdesc_section(memdesc_flags_t mdf) { return 0; @@ -2734,9 +2749,7 @@ static inline void set_page_links(struct page *page, enum zone_type zone, { set_page_zone(page, zone); set_page_node(page, node); -#ifdef SECTION_IN_PAGE_FLAGS - set_page_section(page, pfn_to_section_nr(pfn)); -#endif + set_page_section_from_pfn(page, pfn); } /** -- 2.20.1