From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-179.mta0.migadu.com (out-179.mta0.migadu.com [91.218.175.179]) (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 3897A38F639 for ; Tue, 28 Apr 2026 02:22:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777342962; cv=none; b=RiU7NmqglmjDL0wfcM6m1A4V1/JP+B9kjSLGN6p7DNE6foWqk4prANMwr7tfFZgFAiMVv81wzNVEY7upAoU6ahlpuHwMyr2bKm+MO26MDqmcj13f5l8muOcgv/YvI2IeFSTNG4AaWcF23bJHxSArbb5WjoaYRIq4sjmoxmQ0wZs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777342962; c=relaxed/simple; bh=RdXGpfqLHnE6+NYvLGvcLCKTSLfboS39RbnS79AOxGo=; h=Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Cc: Message-Id:References:To; b=kKy1aFFGpxcIHgq17oBlU1ZR+jkuNW2zfIYI0yFlPPiOqwoOOGweyEr99/jGxf6wJgvQyHBIVF41V1soTF5Oci1k+q/9misBozYS2pFlyuB9Jay4U7yJP83r+NF/g3Xwby+GDzw91WAg1xXsxfcUBE59HECMOjoQLizdnaLwy7g= 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=DG0Bm5RX; arc=none smtp.client-ip=91.218.175.179 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="DG0Bm5RX" Content-Type: text/plain; charset=utf-8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1777342949; 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=P8WtTpk4C3bWW2J9TtLvfZiG0OAM5aNmX37Zh2TBXyQ=; b=DG0Bm5RXG0phliP9NHTpaSQiK2iNYYaMZjv8TQBv0NlXK+ehAEvDcUdk7LHI76DtXY4HnQ HAYjVIC+RR/KyTT84e0oVBYM3KSE2+z7RJHoNOxVzmN3xgqRSdR2k6yS0V3a3uvmt0KN7O qC7UG0CAXh1M6qThDTOdenB3pKZWZwM= Precedence: bulk X-Mailing-List: stable@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 v7 4/6] 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: <09298afa-9a36-4f29-a8e1-d4750c338df2@kernel.org> Date: Tue, 28 Apr 2026 10:21:47 +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, stable@vger.kernel.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <20260426092640.375967-1-songmuchun@bytedance.com> <20260426092640.375967-5-songmuchun@bytedance.com> <09298afa-9a36-4f29-a8e1-d4750c338df2@kernel.org> To: "David Hildenbrand (Arm)" X-Migadu-Flow: FLOW_OUT > On Apr 27, 2026, at 18:17, David Hildenbrand (Arm) = wrote: >=20 > On 4/26/26 11:26, 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_nr_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") >> Cc: stable@vger.kernel.org >> Signed-off-by: Muchun Song >> Acked-by: Mike Rapoport (Microsoft) >> Acked-by: Oscar Salvador >> --- >> v6 -> v7: >> - Refine the alignment assertions in section_nr_vmemmap_pages(). >> --- >> mm/sparse-vmemmap.c | 34 ++++++++++++++++++++++++++++++---- >> 1 file changed, 30 insertions(+), 4 deletions(-) >>=20 >> diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c >> index 3340f6d30b01..01f448607bad 100644 >> --- a/mm/sparse-vmemmap.c >> +++ b/mm/sparse-vmemmap.c >> @@ -652,6 +652,31 @@ void offline_mem_sections(unsigned long = start_pfn, unsigned long end_pfn) >> } >> } >>=20 >> +static int __meminit section_nr_vmemmap_pages(unsigned long pfn, = unsigned long nr_pages, >> + struct vmem_altmap *altmap, struct dev_pagemap *pgmap) >> +{ >> + const unsigned int order =3D pgmap ? pgmap->vmemmap_shift : 0; >> + const unsigned long pages_per_compound =3D 1UL << order; >> + >> + VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, = PAGES_PER_SUBSECTION)); >> + >> + if (!vmemmap_can_optimize(altmap, pgmap)) >> + return DIV_ROUND_UP(nr_pages * sizeof(struct page), = PAGE_SIZE); >> + >> + if (order < PFN_SECTION_SHIFT) { >> + VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, = pages_per_compound)); >> + return VMEMMAP_RESERVE_NR * nr_pages / = pages_per_compound; >> + } >> + >> + VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, PAGES_PER_SECTION)); >> + VM_WARN_ON_ONCE(nr_pages > PAGES_PER_SECTION); >=20 > I would just have done that at the very top, as this check applies to = all cases. My initial reasoning was that the current formula holds for compound = pages smaller than the section size, and we only need to impose limits when the page = size exceeds it. While the current callers of section_nr_vmemmap_pages() don't pass = sizes larger than a section, this will change in the future (see [1]). I might have been overthinking the future-proofing, which led to this = specific implementation. However, I=E2=80=99m inclined to keep it as is for now, = as I'll be updating that series [1] soon and it will involve further changes to = section_nr_vmemmap_pages(). That said, I'd love to hear your thoughts before I proceed. [1] = https://lore.kernel.org/linux-mm/20260405125240.2558577-43-songmuchun@byte= dance.com/ >=20 > Acked-by: David Hildenbrand (Arm) Thanks. >=20 > --=20 > Cheers, >=20 > David