From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from va-1-114.ptr.blmpb.com (va-1-114.ptr.blmpb.com [209.127.230.114]) (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 B835A3090F4 for ; Mon, 3 Aug 2026 07:11:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.127.230.114 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785741079; cv=none; b=LV1R3HfIgrlVLcyOpqcji1I58bwsZSmX1SlPuLR1mTzTDVUAZdGfeYb3wGuqabjdashp28WUWEqaBWgiFHO1CYuU6QqYU5MdUHJ2qvPHksog0o1iamGkuvsgzXA9NR1BzTTdYFjyIEcSRMgDc6Y4ukUIJLR3i1bqA+GcPEp9NX0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785741079; c=relaxed/simple; bh=BIVDw/5zLYeH4lTLhdwm8OUozWu2BrvT0BiGbt//W2c=; h=To:Message-Id:From:Subject:Mime-Version:References:In-Reply-To:Cc: Date:Content-Type; b=snRLUG+nywoozuc4zOdLEG9GteVUlNKVFGA6317WDkpG+Rkk3chP7nQEfDHf6d64BrcNOTRzzbz1jUlaBewO2HA+nqVtRsrBq+uPsXXv9ZPmCf/6yOOH1z8B5bUhpLw2YnclBha91u4K6EkUzK2GDCKFot/y39crgG7m8J38W3k= 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=e2PdTZLH; arc=none smtp.client-ip=209.127.230.114 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="e2PdTZLH" DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=2212171451; d=bytedance.com; t=1785741071; h=from:subject: mime-version:from:date:message-id:subject:to:cc:reply-to:content-type: mime-version:in-reply-to:message-id; bh=HX3xWYPWMGyEZ3/iAdp9cHSDCjeSCNmVjV7Tq4qpRvQ=; b=e2PdTZLHPSo4lhkRRzMlcM1fzB6NXcH7MQlhE5P5aJ9Xbn/lvF2GOhuD8uwPOQhPli+jIb c+Bg/EALcOFDEv0AbcdZptSJQz1+lFib89Hq5CbIqLMC8/IlGKkYpr7WQqsGcbFdlmfMfS BhJOEyJRbJ3MBI3ZRQX21USJFRQ+23rsKK9MnWWKGq9PGKsMbk1uRoEt37ltvYyqVOuuMA 8jMP8DtIXxeJttmfRBvjpaAlSEoheCu/4wOsyAUThnSlanHGA8XhgE+2qxi2yAT4Z08xdi d06j9lfKmJnEBt4D/S7PomLr1TV/ictq9zin3kgQmDdTGbt7Pztsv+iUSeAFIQ== To: , , , , , , , , , , , Message-Id: <20260803070929.86075-4-lizhe.67@bytedance.com> From: "Li Zhe" X-Original-From: Li Zhe X-Mailer: git-send-email 2.45.2 Content-Transfer-Encoding: 7bit Subject: [PATCH v9 3/8] mm: add a set_page_section_from_pfn() helper Precedence: bulk X-Mailing-List: linux-arch@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260803070929.86075-1-lizhe.67@bytedance.com> In-Reply-To: <20260803070929.86075-1-lizhe.67@bytedance.com> Cc: , , , , , Date: Mon, 3 Aug 2026 15:09:24 +0800 X-Lms-Return-Path: Content-Type: text/plain; charset=UTF-8 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 keep it as a no-op so callers can use one helper without open-coding SECTION_IN_PAGE_FLAGS. 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) Acked-by: Muchun Song Reviewed-by: Balbir Singh --- include/linux/mm.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 485df9c2dbdd..43343bfce493 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -2541,11 +2541,22 @@ 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_from_pfn(struct page *page, + unsigned long pfn) +{ +} + static inline unsigned long memdesc_section(memdesc_flags_t mdf) { return 0; @@ -2768,9 +2779,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