From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-188.mta1.migadu.com (out-188.mta1.migadu.com [95.215.58.188]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CFF5C3126B9 for ; Thu, 16 Jul 2026 10:58:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.188 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784199512; cv=none; b=L5nd4HsVzTHdxvFvZi5WRlKdahIdjAYjJlZT6/olDekitSypp7V42pJtd86fWA7sfIrittMVBos+RhdMVOCO86kKuFS0OHfNXXIclfkRU3MYobNrdsICGksP8Ct7+6zg1D0PM5UrMQ5OhebigP1qXfT1K4qfyAX9q/2/PRIU45w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784199512; c=relaxed/simple; bh=q2K6qhuqDVelN0qLzeEBoY1gKhxd4XpsCf1s3LKWRO0=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=mG4HNxqDVba+sxCVmc/sWrdCVVvGgBTI3mwrzFpPDfPYtIVjGpz/+Dz6dRRyFrRuT2ZTiQxCvEVkMchXJ6VbLBfnWub4IPiUCxvUwK6OHY8qO0QiibUgfTPLIxClaOiQJCAaR6ELpyOszyi88ArTfiZtfFWXr/J2WVUV5WdwZvs= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=b03CyX1d; arc=none smtp.client-ip=95.215.58.188 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="b03CyX1d" Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1784199507; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A9J2mfzReK0vZRJuzRH9sZHoLpDeO+iBwK/xyDsq7Kc=; b=b03CyX1dRHhr7QK7K8Bi+z9V2blADechNztWBv2EwWnhnkb7K2qCMQZFZJo4CN+5PaAtZ1 B2vktp/6aXOjpw4h+ftljMkWMCP7OaSNHlzh8Wj5FBD6NMM7196ofRGOkRdQgh9UzxNAPl hFoXhmbaJ5BgN8egRmGkldkt6rsjqOc= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.600.51.1.1\)) Subject: Re: [PATCH 02/17] mm/sparse-vmemmap: track compound page order in struct mem_section X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <20260716101559.2e640e99@pumpkin> Date: Thu, 16 Jul 2026 18:57:57 +0800 Cc: Muchun Song , Andrew Morton , Oscar Salvador , David Hildenbrand , linux-mm@kvack.org, Mike Rapoport , Vlastimil Babka , Lorenzo Stoakes , Michal Hocko , linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <7BE734F3-4B0A-4990-9511-C2274C1CFA51@linux.dev> References: <20260702093821.2740183-1-songmuchun@bytedance.com> <20260702093821.2740183-3-songmuchun@bytedance.com> <20260716101559.2e640e99@pumpkin> To: David Laight X-Migadu-Flow: FLOW_OUT > On Jul 16, 2026, at 17:15, David Laight = wrote: >=20 > On Thu, 2 Jul 2026 17:38:06 +0800 > Muchun Song wrote: >=20 >> HugeTLB and DAX both rely on vmemmap optimization, but sparsemem does >> not record what compound page order a section is populated with. >>=20 >> 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. >>=20 >> 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. >>=20 >> 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. >>=20 >> Signed-off-by: Muchun Song >> --- >> include/linux/mmzone.h | 32 ++++++++++++++++++++++++++++++++ >> 1 file changed, 32 insertions(+) >>=20 >> 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 >> }; >=20 > 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. >=20 > 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... >=20 > 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 =3D 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. That was a truly excellent analysis. It is clear that the memory used by = the mem_section occupies a very small percentage of the overall system = memory. >=20 > It is also worth noting that CONFIG_PAGE_EXTENSION is a debug option. > It probably doesn't matter about efficiency if it is enabled. >=20 > You could change the code to use % instead of & - makes no difference = if > the size is a power of 2. That is generally safer. No problem. My patch 1 has already handled that. >=20 > 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. Thanks for the suggestion! I'll use this approach to ensure men_section is aligned to a power of two again. I'll also add a comment here to = explain the reasoning behind this implementation. I really appreciate your detailed analysis and insights. Muchun, Thanks. >=20 > David