From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48]) (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 7A1AE2E888A for ; Thu, 16 Jul 2026 09:16:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784193365; cv=none; b=iXSaO6CqYdMBjcWoQEYarPhC4L7BxxV39k6VTu6pBLK+Oq/EHk1DDhyC+ctrY5GTScVilVXeB73v/jQ25hOeC19mRrUKOaVrfgUs4KHU8aD+/rAbnutiWGBFQrRoTTR6PU6apTaMKwfpLHU6w2C4n8PYHckCpHRzEmmzX5U2YvA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784193365; c=relaxed/simple; bh=c0n3qQcfMLohD5hSM2LYI8+AI81GHrlLf2TClOTkMPk=; h=Date:From:To:Cc:Subject:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=XVAyeKVDCbTOpDqI9tis++Pi1fzIfgd/tPC2xlR0SgRJ+tywrMvgTbxvcb3lmiwy/ffOkmksb6E/9WaHrtMWqo+gmEz0bLj5WZqb1GtBbLEqgpqntkPXZOLkx/3KrgxreAH12VCMEyTr8/ozzYHsq+3DJ9fwDA+Ca7Wt/EEOaRo= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Cmf2sxEo; arc=none smtp.client-ip=209.85.221.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Cmf2sxEo" Received: by mail-wr1-f48.google.com with SMTP id ffacd0b85a97d-47de008b020so224400f8f.1 for ; Thu, 16 Jul 2026 02:16:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784193361; x=1784798161; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=TA75zpkjRtJ1CrSuCCINdIy5fnUYiQFMSAO8lzyxCcw=; b=Cmf2sxEoQlqNGMxEsNMPAc3ueZlrj3Pg7kulUxY7lopwG3K+bTZvOYlxQdz71HQTlz awn3NJmKn84Jdk4/F9HVJBRSyQJ7ZeukHCb63hHguJeL67qDRPJB3iimwX9YI/znEaOH L16jOTxL6T1q5EbGr2tEX+vWqS7JtdgUf2RXeYiKmMiYc89sWGs40l+uJ7lWOBTBrI3J omPEJq9cWsdWxQJz3h0V4g16wdlLoHrBTibmluRNFLNHnJy9IDMOIwYAmyGYYv1hNezv BIge9kaxjxOFc34nwTJyMHdJ2yZN7sjrPkb42RHaeqdurY2F7jPMO1L900yslBI2EaRt 7hGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784193361; x=1784798161; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=TA75zpkjRtJ1CrSuCCINdIy5fnUYiQFMSAO8lzyxCcw=; b=l5EMfE8gTR2nuW0pxbxbc/otobsSUz4EgLhVhizKo5MikDIdiIAVl/O4Q4/h4FRz7T EfNuTb8n0UTfC2jGfoJKh03F7JLVnPwricCwk8S3Qdv4kH/lHLZUGuEwqfzqJtCjvVNv 1MDbWQnKWb+U/hjgzh7syfroWzrhPXEIxkE6SQtxPgnMmy93TG7u8U4JFjd9H9eIY0Fa 5bDqvgXn5G79wFKAPichZzqCaWv0SXLmqh4VVbKpJ7Cr9dBkmCehlz76xu6FUzpZtZs5 b1jP25On/jrHZb61uql2Zsu6Uw40KKMr6knRuSkn447LYmtItVBJtaRwoEsyBOdL2Lwg 8sDA== X-Forwarded-Encrypted: i=1; AHgh+Rqc0yLmbcvIvA7zr5eiWw7FZE/PFuIpPSy0WONk0TFQ8ReCog5paK4GIymVR6gRECT2CSX1rP8WkIEFXvc=@vger.kernel.org X-Gm-Message-State: AOJu0YzlK9QNJZd73RFalijIZRXJHuOZSS+c1cLJH6PrRSOBXiLiU6fN uz0XSMmh5/ZSL+GX7jBkGLVX3WF0gW8m03IXeSAzVmGgJlmJL342tLSo X-Gm-Gg: AfdE7ckAsIOYtnCp5dqsImgFOWjG+qdhT9IWatw1rTnKxYunEEXdT00N8CeBhxXnHNI klGFmjiBBZnqGFX5xNWhSR1vbgzWG3A3WIz2JCuly/XXhU07iT4pwEAHyqf7tQ1pSYJ41/xOAYl vTMSED1QFeuNqfRt+YkczGEp0+kjGXIHosrECd7ai7mKjT7NuyultmsOEKmxLFcqJU+Wakmslji hBA4Fy5UjK6etMkvbyppHMfRmqExUs0NPPRjlxhoajITq8eyNSUYn37rPP3tkFgbBty2JCkkN76 sr0sJ8pZ0XUIccX8Rdfl1p0WHM+0POjSMACccCkZbAk+esAQ0IoCow5YFH7xsmIakVAFx+kHZwa /A7BSYEOGb9361FvCFdH3H585WXVLeKeriTmOlnVqk4Nqk+xIRidVnUsZx1oXCLgIhRVabQ+Pjs chCz6EyNDo9xLQm533b7moTU4hy8wB5SuuczSuWMERU7d/hXIoEA== X-Received: by 2002:a05:6000:2509:b0:46f:1b89:999 with SMTP id ffacd0b85a97d-47f5a676c8emr2211362f8f.30.1784193361307; Thu, 16 Jul 2026 02:16:01 -0700 (PDT) Received: from pumpkin (82-69-66-36.dsl.in-addr.zen.co.uk. [82.69.66.36]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47f4635a9cesm23400333f8f.14.2026.07.16.02.16.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Jul 2026 02:16:00 -0700 (PDT) Date: Thu, 16 Jul 2026 10:15:59 +0100 From: David Laight To: Muchun Song Cc: Andrew Morton , Oscar Salvador , David Hildenbrand , linux-mm@kvack.org, Mike Rapoport , Vlastimil Babka , Lorenzo Stoakes , Michal Hocko , linux-kernel@vger.kernel.org, muchun.song@linux.dev Subject: Re: [PATCH 02/17] mm/sparse-vmemmap: track compound page order in struct mem_section Message-ID: <20260716101559.2e640e99@pumpkin> In-Reply-To: <20260702093821.2740183-3-songmuchun@bytedance.com> References: <20260702093821.2740183-1-songmuchun@bytedance.com> <20260702093821.2740183-3-songmuchun@bytedance.com> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; arm-unknown-linux-gnueabihf) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Thu, 2 Jul 2026 17:38:06 +0800 Muchun Song wrote: > 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 | 32 ++++++++++++++++++++++++++++++++ > 1 file changed, 32 insertions(+) > > diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h > index 1353bcf7b712..bacd89572c5c 100644 > --- a/include/linux/mmzone.h > +++ b/include/linux/mmzone.h > @@ -2015,6 +2015,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 > }; That increases the size of the structure by 8 bytes for a value that would fit in one (or 16 bytes to maintain power-of-2 size). I'm pretty sure this array is big - so that is significant. I've looked up some constants... On x86-64 each section is (1 << 27) bytes or 128M. A page contains 256 small 'struct mm_section' so covers 32GB of physical address. That is pretty much the memory limit for a 'normal' system. So even doubling the structure size only uses 2 pages for 32GB memory. Even packing the structure (or making it 48 bytes) would still use 2 pages. Of course there are the big servers with TB of memory... A more interesting problem is the size of the 'page pointer' array. That is sized for physical addresses right at the top of the 52bits supported by 5-level page tables. I make that 52-27-8+3 = 20 bits or 1MB, doubling to 2MB if struct mem_section is increased to 32 bytes. However, in practise, I suspect that the actual upper limit for physical addresses is much lower. It is also worth noting that CONFIG_PAGE_EXTENSION is a debug option. It probably doesn't matter about efficiency if it is enabled. You could change the code to use % instead of & - makes no difference if the size is a power of 2. That is generally safer. Then do: #if defined(CONFIG_PAGE_EXTENSION) || defined (CONFIG_SPARSEMEM_VMEMMAP) struct page_ext *page_ext; unsigned int order; #endif With an extra comment about keeping power of 2 size for effifiency. David