From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794025952; b=qFAXfxchI3I2wLs3qMPkB6Grcgr2+R07nbtIyoUdsawenx5WqGLKAU4Ij4u7fnAbeNSO 9gIl3EJAZL3j+/HSRBwe1dadgfQmK5Tqmr+LyKcE6dpsZ1/vDRpm6GJFQwJ3RfidsFQ8O 3+yBIyTY2Axg3iBb5ZV9aB07DTvDXk+S+5EhDT76GUI7qxCvXSXVDB8cEOe5k8cktLXCp S8yJYIBh575V7gYS64DDK1XKrKlW+1ys9qMWqerpgzynPkH/4YhriTQeyBTmea3zaAcLP 7bRPu2QYlhbyJDERAuOqVJVif6qu5qcuzUxM5U/XTj9YPR9/CkG5sQRVzD1EyMNPf6A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794025952; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-ID:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=BY1PW5EQCsSwahWNQsNirKWCM+cX6Fs3QmmMD9rosww=; b=Il5PzdY5+FTQU3+rx6RitdmWgWWFuj0dBJhQFlJdNZvxOjX7psaQMSOQc17B/R+tfNmO U7RZ2kNyog836Z3R6efn/Sn19tjRFHFQZkeSYZHAoDqGRcin9B04M3LRDnXJv403DTLQT U+61njl7Siyt9GROryFU6AMZCIqlsgbSCSZu6yg6yHIAYmh5TJu9SIs9sHSADONYbXFZM 7f7zMkPQUtfvEsELkXGvZZYVP9SxMIO05Ie2Yr6pa2A2NK07R0+QU1v2KvFy/NgzWiCYe 5I6SawQC96NL5d7xH8ErHT0R/7yYnlDLZkzoew47Y7ycNed/V/KXwadwMgkdOhLR8Jw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=bytedance.com; spf=pass smtp.mailfrom=bytedance.com; dkim=pass header.d=bytedance.com header.i=@bytedance.com header.a=rsa-sha256 header.s=google header.b="Yw/xntLX"; arc=none smtp.remote-ip=209.85.214.174 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D5EE1606A331 for ; Sat, 7 Nov 2026 04:32:31 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org D5EE1606A331 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.a=rsa-sha256 header.s=google header.b=Yw/xntLX Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-2e8da6ef7ddso7445405ad.3 for ; Fri, 06 Nov 2026 20:32:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1794025951; x=1794630751; 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:content-type; bh=BY1PW5EQCsSwahWNQsNirKWCM+cX6Fs3QmmMD9rosww=; b=Yw/xntLX1Emc5Zji6LogGgC+qzrpcJwEieREH8IPXZncmX0OfpYUecfbwqxo+QkeHM Rau0Gi2zXSKDuAELU3lh1PdrD8Zf8wVigmZh9ysbYvhOTbJx6mBjStuSAk05BrRJY7mG mEJNzSNKl1vYAv2YyT7HZEd9ucNYGEAFHnqn6YHy9h9b4thDr1S9HkMAPqFwmwK0F2ZN FsfBOl2Rh8Fi3+FUWkVQA6+gEfGhz/IcWMfgQeZsckT7q+R0wl3hPf6HaeJzT7QWFd2y ZYtvJ+FGXP6Np2X4FOsrx87TX3Ks30H3y0vOH5OY/LS/0m2HFSkezhEtIV8y9H0/HyrR BPPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794025951; x=1794630751; 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:content-type; bh=BY1PW5EQCsSwahWNQsNirKWCM+cX6Fs3QmmMD9rosww=; b=VXsAJd7WLLKsDGpmdn5UjUSgaNxLg7sBKtQuGjJKiroowlLyMz5NISmaXNTBjSYUcq AjaxHWnObek3QfyyCakdLv3DWBzKtINUsXxWHkVCTdJGb/Yw3GpaqyqZHvETe4mF3R7Q nf2QmwgeZsbV8WNbaCvFVfHS4Uo0/913kEEpEyfpDYCs2Qp6isfdfyfLTY8h32YWlVcA HSvUGuHsGucdApuEo9QQQwD+GdV4Ke6TyJKwNPhD87WzMoD7EKQYbh6kpIjTKQPh9P5D /B9Ef95gpXbWebnr7BJaVJkAdMZ/TJI4U972ytxpBqUyy3Fgx9sFHHlmZx5ymRoPyM+P OBQA== X-Forwarded-Encrypted: i=1; AL+hErGm1M2ly07EmQMYQLmnMq9zF56rdG7K9lnFfstvAiGwRWUXv2vjLNQ8us/E1XhdX3BfVlZlLIbKAlrDTgc=@vger.kernel.org X-Gm-Message-State: APuU4Z8ogK7JyZoYXCrPFKa65f6p4RaZYeeIs7RcY/Yl3AHkFhabv1NP mz6K76cQnQAiHyOT/pFVRO7+V3ctNUuTJMf7FGuvDXuGyxsQiT3EIqrzi85noey3QYc= X-Gm-Gg: AYBFou0DC6Rk8XcKuiH9tOpmCYQMshDBgc20UDaS0vwRynbRTFnHBGO4KWgVu8IELYp kF2CmHbv2gDDZ2ZqHLx55Cxf/Y7OJ+AYkBrv9kKBKGbgD6TLNLPRKrqMG+V7zq6/7MXeKJ6eo69 +Rm3BkrzmD/Px6BJ2A9mhBV9luxZRp5jkUTGWY+Vgx/KRs58pN4Gt5/R3aMFL9ET02d5e+14oG6 I1BruTTDlv0AImmCrGTvv1vYcZMnvrXrx8bTbntu44oQUjLCyMPJJBo9oh2hr4JAY4IItno6Mcq 6sOucYN3DRMbtA0Rml0Gzv3Lah+rVbOcEXUGwnjTvFCv7ECMKsn2jEUnHyRcVS0ZFrAIt3i1Tfl 1HKzEtxm1AqaRoKRhAnztJAUZI3cpBvax6xsRtm4uupczWjlUJiORylEfI6+x1BijBkvS8wlXWt eNHJfm5CoOqV0Nx8LSezTKKElB3mmcgXEXKtPbiommBIUgLwDW0b+4anOHwqPsGjvvjm8femdXc 79LRGihRG6ae9u9O6bDIlqfhgrDzhaFv897RaJzoh6L7w5K0t70+TAvbKdAISDI4MP88rkgUukK ZMvHJheH8IVNjbiWSSw/A4ZKtXuc/9j6+biVsMdcw59c4V4eYI3meHa3c7JlB8CQ2uAh/VtJgcN NihUy2w== X-Received: by 2002:a17:90b:530c:b0:3a8:59d3:530f with SMTP id 98e67ed59e1d1-3b0db71d480mr4559125a91.57.1794025951057; Fri, 06 Nov 2026 20:32:31 -0800 (PST) Received: from G6L4RL2QG9 ([2409:8a00:1832:6900:c8de:13da:804b:a0fa]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b10584b66bsm1578451a91.14.2026.11.06.20.32.23 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 06 Nov 2026 20:32:30 -0800 (PST) From: Muchun Song To: David Hildenbrand , Madhavan Srinivasan , Mike Rapoport , Andrew Morton Cc: Lance Yang , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Ritesh Harjani , Shrikanth Hegde , Oscar Salvador , Qi Zheng , Muchun Song , Huacai Chen , WANG Xuerui , linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-riscv@lists.infradead.org, x86@kernel.org, loongarch@lists.linux.dev, linux-s390@vger.kernel.org, Muchun Song Subject: [PATCH v3 4/5] mm/sparse-vmemmap: drop vmemmap_can_optimize() Date: Sat, 7 Nov 2026 12:31:21 +0800 Message-ID: <20261107043122.25650-5-songmuchun@bytedance.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20261107043122.25650-1-songmuchun@bytedance.com> References: <20261107043122.25650-1-songmuchun@bytedance.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit section_vmemmap_optimizable() can already decide whether a section uses vmemmap optimization based on the section compound order. The DAX-specific vmemmap_can_optimize() helper duplicates that policy, so remove it to simplify the code. Signed-off-by: Muchun Song --- v2: - Ignore non-optimizable nonzero section orders while retaining zero as the reset value (reported by Sashiko) - Use section_vmemmap_optimization_disable() for the altmap fallback - Move vmemmap_optimizable_order() before its first caller --- include/linux/mm.h | 37 ---------------------------- include/linux/vmemmap-optimization.h | 25 ++++++++++--------- mm/sparse-vmemmap.c | 6 +++-- 3 files changed, 18 insertions(+), 50 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 2d0b8a4c9974..43eb19474d26 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -38,7 +38,6 @@ #include #include #include -#include struct mempolicy; struct anon_vma; @@ -5385,42 +5384,6 @@ static inline void vmem_altmap_free(struct vmem_altmap *altmap, } #endif -#ifdef CONFIG_ARCH_WANT_OPTIMIZE_DAX_VMEMMAP -static inline bool __vmemmap_can_optimize(struct vmem_altmap *altmap, - struct dev_pagemap *pgmap) -{ - unsigned long nr_pages; - unsigned long nr_vmemmap_pages; - - if (!IS_ENABLED(CONFIG_VMEMMAP_OPTIMIZATION)) - return false; - - if (!pgmap || !is_power_of_2(sizeof(struct page))) - return false; - - nr_pages = pgmap_vmemmap_nr(pgmap); - nr_vmemmap_pages = ((nr_pages * sizeof(struct page)) >> PAGE_SHIFT); - /* - * For vmemmap optimization with DAX we need minimum 2 vmemmap - * pages. See layout diagram in Documentation/mm/vmemmap_dedup.rst - */ - return !altmap && (nr_vmemmap_pages > VMEMMAP_OPTIMIZATION_PAGES); -} -/* - * If we don't have an architecture override, use the generic rule - */ -#ifndef vmemmap_can_optimize -#define vmemmap_can_optimize __vmemmap_can_optimize -#endif - -#else -static inline bool vmemmap_can_optimize(struct vmem_altmap *altmap, - struct dev_pagemap *pgmap) -{ - return false; -} -#endif - enum mf_flags { MF_COUNT_INCREASED = 1 << 0, MF_ACTION_REQUIRED = 1 << 1, diff --git a/include/linux/vmemmap-optimization.h b/include/linux/vmemmap-optimization.h index 22e5a322be0b..985a37dfcab7 100644 --- a/include/linux/vmemmap-optimization.h +++ b/include/linux/vmemmap-optimization.h @@ -31,6 +31,17 @@ #define VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES (VMEMMAP_OPTIMIZATION_SIZE / sizeof(struct page)) #define VMEMMAP_OPTIMIZATION_MIN_ORDER (ilog2(VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES) + 1) +static inline bool vmemmap_optimizable_order(unsigned int order) +{ + if (!IS_ENABLED(CONFIG_VMEMMAP_OPTIMIZATION)) + return false; + + if (!is_power_of_2(sizeof(struct page))) + return false; + + return order >= VMEMMAP_OPTIMIZATION_MIN_ORDER; +} + #ifdef CONFIG_VMEMMAP_OPTIMIZATION static inline unsigned int section_compound_order(const struct mem_section *section) { @@ -40,6 +51,9 @@ static inline unsigned int section_compound_order(const struct mem_section *sect static inline void section_set_compound_order(struct mem_section *section, unsigned int order) { + if (order && !vmemmap_optimizable_order(order)) + return; + VM_WARN_ON(section_compound_order(section) && order && section_compound_order(section) != order); section->compound_page_order = order; @@ -109,15 +123,4 @@ static inline bool vmemmap_optimizable_pfn(unsigned long pfn, unsigned int order return (pfn & (nr_pages - 1)) >= VMEMMAP_OPTIMIZATION_NR_STRUCT_PAGES; } - -static inline bool vmemmap_optimizable_order(unsigned int order) -{ - if (!IS_ENABLED(CONFIG_VMEMMAP_OPTIMIZATION)) - return false; - - if (!is_power_of_2(sizeof(struct page))) - return false; - - return order >= VMEMMAP_OPTIMIZATION_MIN_ORDER; -} #endif /* _LINUX_VMEMMAP_OPTIMIZATION_H */ diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c index 57aa5c2d8034..f6a8b8e51b6c 100644 --- a/mm/sparse-vmemmap.c +++ b/mm/sparse-vmemmap.c @@ -490,6 +490,9 @@ struct page * __meminit __populate_section_memmap(unsigned long pfn, !IS_ALIGNED(nr_pages, PAGES_PER_SUBSECTION))) return NULL; + /* Altmap-backed vmemmap pages cannot be optimized. */ + if (altmap) + section_vmemmap_optimization_disable(start, end); r = vmemmap_populate(start, end, nid, altmap); if (r < 0) return NULL; @@ -717,10 +720,9 @@ static struct page * __meminit section_activate(int nid, unsigned long pfn, struct mem_section *ms = __pfn_to_section(pfn); struct mem_section_usage *usage = NULL; struct page *memmap; - unsigned int order; + unsigned int order = pgmap ? pgmap->vmemmap_shift : 0; int rc; - order = vmemmap_can_optimize(altmap, pgmap) ? pgmap->vmemmap_shift : 0; if (nr_pages < PAGES_PER_SECTION && section_compound_order(ms)) return ERR_PTR(-EOPNOTSUPP); -- 2.54.0