From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) (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 A4FA547B437 for ; Wed, 13 May 2026 13:11:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778677864; cv=none; b=nHOIn/DAeUwQD81BLJeDjam9junfyYNNozmDIxtdi8PM083GcvMC7NdjGZMNNlmW+Dn2THoe11Hy5+9LiWdUcLBqVmEb2GzhLJGdLJt1JqRW0jdPjYxxu9tFKq1t3ULQq1CUR1s2X+0pOW5WwXWnrQFb8dWSUw53h7yZeUndpCM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778677864; c=relaxed/simple; bh=V1RI7shZieDH+rgacq68niRkULNmChDS3rXE7ISzatE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l+ip6zwzHPhkbmjsZ2zpQ4rpXznvG1shsMBh2urNz5Bqxv3jKEvr/emooz0FYZ9Wa3jpQfzIQu/+TWR4LY8KVpDWyfv+F/esC/X5yeJZGLadT2JUjl2CmMHJTaSWpGJD75lEXhDsKtYpX9irjNecZ9ea10uZMiRx1iWRnjegEY8= 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=lnvRN4S4; arc=none smtp.client-ip=209.85.214.171 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="lnvRN4S4" Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2ad9a9be502so41311195ad.0 for ; Wed, 13 May 2026 06:11:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1778677862; x=1779282662; 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=LpwPxpfie30YAMOHUn6jeAG+IgoJLqSekICSQMqQJSE=; b=lnvRN4S4SXWcZWV72Vif60HZATfwlO2KPI8+Effel9NJiRqXCCgoDjkf8F/hd/HaRB QFZ4aWRKyBcBi5u7jlvI8/xenPnrUtiLfs5WuTJ8M5v657iFXtiNDjDscw/l7Qgy5iU/ e+J8QwiEsKv1v9UColrJDwYwoy4MrQ0sYNi73Nlm3wGlSFkeFSF6zEwg2FzaNokMwXnR jtyfWuTco47fO+cno0U6ylQTpwqGsF9dO8sX+bSdFGzYW+s6dSKkmxr86Qr5BaAo+mzM YiP0N2YEi1mD51TXWU1oefJh44pot5/V12Set5BRsc3Lo7ubvANkqSEYOsP3jSCb76qk VyjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778677862; x=1779282662; 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=LpwPxpfie30YAMOHUn6jeAG+IgoJLqSekICSQMqQJSE=; b=nYTjqiEORfuLXIaFkd6QNSJCGUotrozuX+dH58qSL89NKHVqQ9PM2v5+ps+ldmLKmh 0sYDuMtAsymOC0mhEZs65Bcnx+naHOWELg7P5jaqg66ifwZ4QI44jryjozR65yNnltNE gui9KONXn7kzaZjGzh5oEu3/0wPwrUv3Z3DMJDQobb+w4udPX/mVljZ2Cs5fqajPSblg l5Fz9i8mPm4SSAHvZy5EQh0/vicy+6cNgIb/LQTF2yyMix69R0A4FeJdR+GW8O+MeISp I/muMNDiUBmN+2Yx5XweEM129uXlHvgF1WUK2ua29tiRVPQk6zBmOXBWdLtZ6RirME7h ixxA== X-Forwarded-Encrypted: i=1; AFNElJ8PzIG1C8PRbVmJ/d0We6AE7gJj+zkSmiVrP5BvYp4Gvvk5FwacJ7Mq4LgoDsGOPxEp0B/YOlHfLFajLOg=@vger.kernel.org X-Gm-Message-State: AOJu0YwJivMxrV7dPBdcMQdSjl+69Nd87c7vwtL1nhLbfIs16lmb5B6U 6xI/fivH9Yzj17rzgR6zJ5RRC/ZLsRqOhTbwUaR8YqE9hRPzgzGA9Oxkr9aE414QIs8= X-Gm-Gg: Acq92OEWjb6HBzlaxyR1SLDacjDtym8Ig3A4sNUQx34nRB8Kj1SecTodITuvwMVZjfY eeIwPREoly7g7ps55Oze6AWUP8dGRoK6x4fYQBbSjITDKl4AiDxrFm8Z3FbBRqm6GYI5kzL1+Tm 1VAACn/JhZIcx4rh6Od51fAgXitdLenzZg/XL/ZVAX13IwF5mrtfsHRFiyjDugrucBq9DFpF6NZ 3ngWGOA9cpVFRHcX3/CbaRLZcWsq/nIoAWHvN/0yA5KxpT886zFjJyL3UtSkoWdUIauCT8eULaU l3bEmOTTebfsDCeZd1Pi6f3kdp7dBE7rWHzIUG4XzgAO504sN9BIX/xm6/MRa1nAIlUNUw57vcp U3eTdk2HSXaVR9z2PsItxESfWJu59w4ppvc8kvDU3cWs9ENX6dmgZ6xgMNmjL+wt5mUgxiXKXxl 8s/7rzhrvRdqed4GdCEZ+p+AwGomF0faqyMQEDuQbwRmuyCq+o6VcmKicZzHI= X-Received: by 2002:a17:903:22d0:b0:2b7:abc0:3bd7 with SMTP id d9443c01a7336-2bd2716ecabmr35771225ad.9.1778677861863; Wed, 13 May 2026 06:11:01 -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.56 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 13 May 2026 06:11:01 -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 38/69] mm/sparse-vmemmap: Introduce CONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION Date: Wed, 13 May 2026 21:05:06 +0800 Message-ID: <20260513130542.35604-39-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 The generic sparse-vmemmap optimization code is still guarded by CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP, even though it is no longer HugeTLB-specific. Introduce CONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION to represent the common vmemmap optimization infrastructure. Have HugeTLB and DAX select it, and use it to guard generic optimization code. Signed-off-by: Muchun Song --- arch/x86/entry/vdso/vdso32/fake_32bit_build.h | 2 +- drivers/dax/Kconfig | 1 + fs/Kconfig | 1 + include/linux/mmzone.h | 33 ++++++++++--------- include/linux/page-flags.h | 5 +-- mm/Kconfig | 4 +++ 6 files changed, 26 insertions(+), 20 deletions(-) diff --git a/arch/x86/entry/vdso/vdso32/fake_32bit_build.h b/arch/x86/entry/vdso/vdso32/fake_32bit_build.h index bc3e549795c3..5f8424eade2b 100644 --- a/arch/x86/entry/vdso/vdso32/fake_32bit_build.h +++ b/arch/x86/entry/vdso/vdso32/fake_32bit_build.h @@ -11,7 +11,7 @@ #undef CONFIG_PGTABLE_LEVELS #undef CONFIG_ILLEGAL_POINTER_VALUE #undef CONFIG_SPARSEMEM_VMEMMAP -#undef CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP +#undef CONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION #undef CONFIG_NR_CPUS #undef CONFIG_PARAVIRT_XXL diff --git a/drivers/dax/Kconfig b/drivers/dax/Kconfig index 602f9a0839a9..60cb05dce53d 100644 --- a/drivers/dax/Kconfig +++ b/drivers/dax/Kconfig @@ -8,6 +8,7 @@ if DAX config DEV_DAX tristate "Device DAX: direct access mapping device" depends on TRANSPARENT_HUGEPAGE + select SPARSEMEM_VMEMMAP_OPTIMIZATION if ARCH_WANT_OPTIMIZE_DAX_VMEMMAP && SPARSEMEM_VMEMMAP help Support raw access to differentiated (persistence, bandwidth, latency...) memory via an mmap(2) capable character diff --git a/fs/Kconfig b/fs/Kconfig index ccb9dd480523..f6cee1bbb1fc 100644 --- a/fs/Kconfig +++ b/fs/Kconfig @@ -278,6 +278,7 @@ config HUGETLB_PAGE_OPTIMIZE_VMEMMAP def_bool HUGETLB_PAGE depends on ARCH_WANT_OPTIMIZE_HUGETLB_VMEMMAP depends on SPARSEMEM_VMEMMAP + select SPARSEMEM_VMEMMAP_OPTIMIZATION config HUGETLB_PMD_PAGE_TABLE_SHARING def_bool HUGETLB_PAGE diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 9b87d798a365..5285d53b0c53 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -102,9 +102,9 @@ * * HVO which is only active if the size of struct page is a power of 2. */ -#define MAX_FOLIO_VMEMMAP_ALIGN \ - (IS_ENABLED(CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP) && \ - is_power_of_2(sizeof(struct page)) ? \ +#define MAX_FOLIO_VMEMMAP_ALIGN \ + (IS_ENABLED(CONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION) && \ + is_power_of_2(sizeof(struct page)) ? \ MAX_FOLIO_NR_PAGES * sizeof(struct page) : 0) /* The number of vmemmap pages required by a vmemmap-optimized folio. */ @@ -115,7 +115,8 @@ #define __NR_OPTIMIZABLE_FOLIO_ORDERS (MAX_FOLIO_ORDER - OPTIMIZABLE_FOLIO_MIN_ORDER + 1) #define NR_OPTIMIZABLE_FOLIO_ORDERS \ - (__NR_OPTIMIZABLE_FOLIO_ORDERS > 0 ? __NR_OPTIMIZABLE_FOLIO_ORDERS : 0) + ((__NR_OPTIMIZABLE_FOLIO_ORDERS > 0 && \ + IS_ENABLED(CONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION)) ? __NR_OPTIMIZABLE_FOLIO_ORDERS : 0) static inline bool order_vmemmap_optimizable(unsigned int order) { @@ -2033,7 +2034,7 @@ struct mem_section { */ struct page_ext *page_ext; #endif -#ifdef CONFIG_SPARSEMEM_VMEMMAP +#ifdef CONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION /* * The order of compound pages in this section. Typically, the section * holds compound pages of this order; a larger compound page will span @@ -2213,7 +2214,19 @@ static inline bool pfn_section_first_valid(struct mem_section *ms, unsigned long *pfn = (*pfn & PAGE_SECTION_MASK) + (bit * PAGES_PER_SUBSECTION); return true; } +#else +static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn) +{ + return 1; +} + +static inline bool pfn_section_first_valid(struct mem_section *ms, unsigned long *pfn) +{ + return true; +} +#endif +#ifdef CONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION static inline void section_set_order(struct mem_section *section, unsigned int order) { VM_WARN_ON(section->order && order && section->order != order); @@ -2225,16 +2238,6 @@ static inline unsigned int section_order(const struct mem_section *section) return section->order; } #else -static inline int pfn_section_valid(struct mem_section *ms, unsigned long pfn) -{ - return 1; -} - -static inline bool pfn_section_first_valid(struct mem_section *ms, unsigned long *pfn) -{ - return true; -} - static inline void section_set_order(struct mem_section *section, unsigned int order) { } diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 0e03d816e8b9..12665b34586c 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -208,14 +208,11 @@ enum pageflags { static __always_inline bool compound_info_has_mask(void) { /* - * Limit mask usage to HugeTLB vmemmap optimization (HVO) where it - * makes a difference. - * * The approach with mask would work in the wider set of conditions, * but it requires validating that struct pages are naturally aligned * for all orders up to the MAX_FOLIO_ORDER, which can be tricky. */ - if (!IS_ENABLED(CONFIG_HUGETLB_PAGE_OPTIMIZE_VMEMMAP)) + if (!IS_ENABLED(CONFIG_SPARSEMEM_VMEMMAP_OPTIMIZATION)) return false; return is_power_of_2(sizeof(struct page)); diff --git a/mm/Kconfig b/mm/Kconfig index c26d2d2050d5..ddd10cb4d0a3 100644 --- a/mm/Kconfig +++ b/mm/Kconfig @@ -410,6 +410,10 @@ config SPARSEMEM_VMEMMAP pfn_to_page and page_to_pfn operations. This is the most efficient option when sufficient kernel resources are available. +config SPARSEMEM_VMEMMAP_OPTIMIZATION + bool + depends on SPARSEMEM_VMEMMAP + # # Select this config option from the architecture Kconfig, if it is preferred # to enable the feature of HugeTLB/dev_dax vmemmap optimization. -- 2.54.0