From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 6FC4D25A33F for ; Wed, 13 May 2026 13:09:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778677782; cv=none; b=VrAvzLxJzjUtC2cM8gOK7IEeG/zrXSxbZoYumRpP9lquHpWxc7Fq25wRY1j+V2H+OGPqp0MzdLWMHVixB+VNDBGp4OxDlDWPn3hpX3D0U+eWClrBRCQ6I8btVlE2+D0CbaKryNdJI2sbz7KpIQGJ28VzfPC1TZ44e8+UmsJhbXA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778677782; c=relaxed/simple; bh=L5eDueHsGx1thkVp5gavJrvP5AdNJRWDZBvNX6ssF8A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=int4Elt28W8JeGWn8v61vBjtwGgW2EpJnlsXG5SspAoeDnIVl1ulwgDKNpD4SYnO5R1g4BNnjOicMDqUvLXMu/H+SLtLzct/I60x0qXMhAPrkM2Go7aXV/SMU4xxfkDBet1cdn166QqmjwJbUSX7EuJl0cQoIkxRgLprjpv5Ucc= 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=GQ6Auis1; arc=none smtp.client-ip=209.85.214.177 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="GQ6Auis1" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2bd2c147abaso5488385ad.3 for ; Wed, 13 May 2026 06:09:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1778677781; x=1779282581; 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=thKeB2NiafjiEdbVk8XkvNjvthrX3e0E5pBtn2l+Jas=; b=GQ6Auis1lPW5ARPPTowUrFT2cx6o/jxuIvemklUEh/m7j8BMl95df8cgRd04Vq5iDw SXoyssVtFqYiPMDVDHIV5CAvEp6r7NKSKKWDe5yBIyR7JAD5UQq2lLA4FTP1Ln71JFEO qeyf6XB4HwXdDVDYiEAsgN/JYdhMsPOhFtSfnjz4fCjFU+t+oXr1W951+GBCjzIjrIlf CWQffJC/XjsCTcKCXvFJfhv9KEK2UKb7MKgE+RycyxPP50JAHMgQxNyJvLVlMUxjHYZQ qtq41cgyU0rXGZHXaBN/pCJ5aVvssJbMsjA8rwApD4jwsEAP0dasrQcmrTxtrf1p4weK SyBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778677781; x=1779282581; 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=thKeB2NiafjiEdbVk8XkvNjvthrX3e0E5pBtn2l+Jas=; b=f4LZOuUVMj7C6hgOv/52/xB0K3RnN/q1AP6DO6n5x2oo3cTSElGkfuJ0Lf36kqiBQ/ tr0lb+6Ie2g97QOQYNWzuMRi5bBBPrLyIpkEJk++CGGlsD59y5oSBmyfr5iLcAFWm0d0 e2TpRS996ldSPg/I0iON+0/enktH0lLKNSS5lUToh4YyeTJcQS4eLSVmgW8HS8a3LKBl RNwtVU5yBtTXL1oVd0w2TqVUK8tbt9C9GcV4Eo1CQm78ZWKvmA6MDUL/IBglrCmrEIyU xZ0SP9RDzbrWHUqpoTIYD9hGOLhJa89gx6dqZRF96Xr1HmDAXqXaAWKGWuv3PZPPMCo1 5Clg== X-Forwarded-Encrypted: i=1; AFNElJ9w2SK2tJ/L81b1s5mo8C6RgbRUX4UKe67g2uyiMan7SY3KiPtK8UnfUnHBEFBbWD16RLvoVDvea/w0Ucs=@vger.kernel.org X-Gm-Message-State: AOJu0YxSfh3DDT9EbbOTeB4ad7ZPHI7uHNLu/QU9Dl6jK8ACAqbjaU7S mNTZcAjg4g6nYRtdTyLsRPk89QfO/0gUbxbWagJmTF2z1FwHDOZSUVepGicvxz9V3aQ= X-Gm-Gg: Acq92OHWTRmEyRwDgGGej/3zUfZaP/93XguGUvbIVnOlMpsJwIoRHdcm3epH9Ck6gYD cgRFQFciRH1wxupME2gZTWz802sQZaSJmJG74HzGix2AECwmmn+RbfY0ZRB0M2AxdjAfFUcRG+h wQR+NHDIwcd1X7b78670s1JTaKNTCG7zJSkKXTXFJ8U2eAkmFyN77dEGvg9XBTAjT4/S5Gwwkr/ P+DEK+99qSRNANgv0+fO/2Bov0D0aD4UY9WPAmOXJi1A2COze686qwzc3P6oMwKS97c2buaCjmu 4AcEvCnM4fQX3Qu7UuSvhFf/b3yJ8+K3YuQJFjFJMuXip607BgKOAGpCJibYhJcmmHdQ6MV8Zko matT6Jq3eyQjBdmxy80sNBs4ZH9Yvk5BPLLIoPOQ1nu5ADGwgGZG+6WF8gPClxPOtaGiEfsBvoS HkEPtL59IqsN1XqoZucFyMwA97LZwJEaVlcTUjtRre2MMwj8h4qQwonSmPYIM= X-Received: by 2002:a17:903:2ace:b0:2bc:7486:21cf with SMTP id d9443c01a7336-2bd276e6d61mr36673085ad.36.1778677780397; Wed, 13 May 2026 06:09:40 -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.09.35 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Wed, 13 May 2026 06:09:40 -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 23/69] mm/sparse-vmemmap: track compound page order in struct mem_section Date: Wed, 13 May 2026 21:04:51 +0800 Message-ID: <20260513130542.35604-24-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 HugeTLB and DAX both rely on vmemmap optimization, but sparsemem does not record what compound page order a section is populated with. As a result, code that needs this information has to open-code separate handling across users of vmemmap optimization. It also prevents other memory management code, such as struct page initialization, from skipping initialization of shared vmemmap pages when needed. Track the compound page order in struct mem_section and provide small helpers to access it. A compound page larger than a section naturally carries the same order across all covered sections. This is a preparatory change for consolidating vmemmap optimization handling and for letting later code make initialization decisions based on the section's compound page order. Signed-off-by: Muchun Song --- include/linux/mmzone.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index ae0271eaec05..6f112e6f42bb 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -2028,6 +2028,14 @@ struct mem_section { */ struct page_ext *page_ext; #endif +#ifdef CONFIG_SPARSEMEM_VMEMMAP + /* + * The order of compound pages in this section. Typically, the section + * holds compound pages of this order; a larger compound page will span + * multiple sections. + */ + unsigned int order; +#endif }; #ifdef CONFIG_SPARSEMEM_EXTREME @@ -2224,6 +2232,17 @@ static inline bool pfn_section_first_valid(struct mem_section *ms, unsigned long *pfn = (*pfn & PAGE_SECTION_MASK) + (bit * PAGES_PER_SUBSECTION); return true; } + +static inline void section_set_order(struct mem_section *section, unsigned int order) +{ + VM_WARN_ON(section->order && order && section->order != order); + section->order = order; +} + +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) { @@ -2234,6 +2253,15 @@ static inline bool pfn_section_first_valid(struct mem_section *ms, unsigned long { return true; } + +static inline void section_set_order(struct mem_section *section, unsigned int order) +{ +} + +static inline unsigned int section_order(const struct mem_section *section) +{ + return 0; +} #endif void sparse_init_early_section(int nid, struct page *map, unsigned long pnum, -- 2.54.0