From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) (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 9091A12E1E9 for ; Thu, 23 Apr 2026 02:17:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776910677; cv=none; b=k6aEoXRX3H90mtxT2MgLzHIvJhjqI3fSbIe08i5B3f4oUotDDR/lStnqgPJGNan1xKNW4JpilWCzI5yJQj/RqxRKyNOFOWMx1PcH5s+3j1Zx4YUgKLCqR+HF9gU9YPp/Z7gp5SiyF7qQDROS9iB5I5HvBKbLk/r35G04yiX1W34= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776910677; c=relaxed/simple; bh=F0jeTpoh8f/QuyQKn9EV2AsKoBKEXDqfK5GCsjXk2p4=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=I0wsd1gx8hsK2CyAzLfIBVR0IrPe1mL86z1Z3UpZJKLbHiFazzJh0mgTQDQ2lT39uj7COhHh9sNFS+ofXGBfqvw8r2seSNKujpGzvSY0rWKdP3ehwcI9ywr3PpWX9TYC0OYGQr7f0gcus4BtYyhWxU1iKbtVHQCeHCIQimpBnqs= 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=b/EJECuf; arc=none smtp.client-ip=91.218.175.171 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="b/EJECuf" Content-Type: text/plain; charset=us-ascii DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1776910673; 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=3Yl5gpUQ0/kTVgZbIhUE9Yavdt5ZXUQjjozCVUL0yP0=; b=b/EJECufayhtxajGQW4PznJfjd7sYzCSDHtMjXb2b8xNQSB1pU5qntYRvYaX0WZNC63JrE O+KFyPV20HrCEnMWvxGFL+u8VCcDINItPeNU7rqIl7g4xlnosoVzWu7KsxjBRGlYxtxrJk l/rl3vDAnT0rDM96adD7Mwz440krZ24= 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.500.181\)) Subject: Re: [PATCH v4 3/5] mm/sparse-vmemmap: Fix DAX vmemmap accounting with optimization X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Muchun Song In-Reply-To: <168f3ddd-de39-4896-a334-23a6fb8959e8@kernel.org> Date: Thu, 23 Apr 2026 10:17:08 +0800 Cc: Muchun Song , Andrew Morton , Oscar Salvador , Michael Ellerman , Madhavan Srinivasan , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Nicholas Piggin , Christophe Leroy , aneesh.kumar@linux.ibm.com, joao.m.martins@oracle.com, linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: <454BB596-DC35-4773-844C-4B32ABEEF423@linux.dev> References: <20260422081420.4009847-1-songmuchun@bytedance.com> <20260422081420.4009847-4-songmuchun@bytedance.com> <168f3ddd-de39-4896-a334-23a6fb8959e8@kernel.org> To: "David Hildenbrand (Arm)" X-Migadu-Flow: FLOW_OUT > On Apr 23, 2026, at 02:53, David Hildenbrand (Arm) = wrote: >=20 > On 4/22/26 10:14, Muchun Song wrote: >> When vmemmap optimization is enabled for DAX, the nr_memmap_pages >> counter in /proc/vmstat is incorrect. The current code always = accounts >> for the full, non-optimized vmemmap size, but vmemmap optimization >> reduces the actual number of vmemmap pages by reusing tail pages. = This >> causes the system to overcount vmemmap usage, leading to inaccurate >> page statistics in /proc/vmstat. >>=20 >> Fix this by introducing section_vmemmap_pages(), which returns the = exact >> vmemmap page count for a given pfn range based on whether = optimization >> is in effect. >>=20 >> Fixes: 15995a352474 ("mm: report per-page metadata information") >> Signed-off-by: Muchun Song >> Acked-by: Mike Rapoport (Microsoft) >> Acked-by: Oscar Salvador >> --- >> mm/sparse-vmemmap.c | 32 ++++++++++++++++++++++++++++---- >> 1 file changed, 28 insertions(+), 4 deletions(-) >>=20 >> diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c >> index c208187a4b00..fcc5e0eda9e7 100644 >> --- a/mm/sparse-vmemmap.c >> +++ b/mm/sparse-vmemmap.c >> @@ -652,6 +652,29 @@ void offline_mem_sections(unsigned long = start_pfn, unsigned long end_pfn) >> } >> } >>=20 >> +static int __meminit section_vmemmap_pages(unsigned long pfn, = unsigned long nr_pages, >=20 > I'd have called this "section_nr_vmemmap_pages" No problem. >=20 >> + struct vmem_altmap *altmap, >> + struct dev_pagemap *pgmap) >=20 > Two-tab indent. OK. >=20 >> +{ >> + unsigned int order =3D pgmap ? pgmap->vmemmap_shift : 0; >> + unsigned long pages_per_compound =3D 1L << order; >=20 > 1UL >=20 > Both can be const. Right. >=20 >> + >> + VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, min(pages_per_compound, >> + PAGES_PER_SECTION))); >=20 > Maybe simply >=20 > VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, pages_per_compound)); > VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, PAGES_PER_SECTION)); >=20 > Which is more readable? That's also quite good. >=20 >=20 >> + VM_WARN_ON_ONCE(pfn_to_section_nr(pfn) !=3D = pfn_to_section_nr(pfn + nr_pages - 1)); >> + >> + if (!vmemmap_can_optimize(altmap, pgmap)) >> + return DIV_ROUND_UP(nr_pages * sizeof(struct page), = PAGE_SIZE); >> + >> + if (order < PFN_SECTION_SHIFT) >> + return VMEMMAP_RESERVE_NR * nr_pages / = pages_per_compound; >> + >> + if (IS_ALIGNED(pfn, pages_per_compound)) >> + return VMEMMAP_RESERVE_NR; >> + >=20 > I'll have to trust you on these ones :) Thanks for your trust. Thanks, Muchun. >=20 >> + return 0; >> +} >=20 > --=20 > Cheers, >=20 > David