From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 6F7913DDDB2 for ; Wed, 15 Apr 2026 15:58:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776268737; cv=none; b=aDDGoYHZiVCtVWCUyWIibT02w500vjo38Gh3d72B2ZtaOEyDLyXJGqmapx7iTM9z1875TWLIpXdVAuDH+8jhlrQgrVY7pP/7euX6lKOdwT55NiNac9lrR6980WG87GjeWrz+XPRv7FMPmRn/uhhuAaNc3Gj3mzTIHrn13OMmOow= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776268737; c=relaxed/simple; bh=y+oq4INIxgbLQllztrJYjafmJkeuG9Q8awCwafdTv18=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=KTHQ5ct7XWhA25DVMiS/GL3dhqmbJP4OmMFKPFtj5j60dtCNjc4PnyVukZIq6pxY07FAakcB3pokcVX2nMfNHB3g6mkFLuFG8SNNfAH9r95/Kh2PdOwPsJGROeT4N2G3td8U3ltOb7E46QTx//wmTUZ6US+jiHGlu3mL0VvpvNc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H0i33bJZ; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="H0i33bJZ" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6368DC19424; Wed, 15 Apr 2026 15:58:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1776268737; bh=y+oq4INIxgbLQllztrJYjafmJkeuG9Q8awCwafdTv18=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=H0i33bJZOnaxzNBKISduWbARJbUIWH5tRHgMmNW9tGUDA65uuEWbQytdZpKAwleUm 2R/5Xj3BYQt06J9Pt8r1Umg7yauBzgLvmDnjAGySIE0ayUcHQHxeky8KavBuS9QUcs ZF0KFAz/6OUD0nQ+T+f1dJDvWHdhhTq8+PDYVBnlLr4nuTkaADeTEMzJXYlVO7s3AX o6fAv2+7lLuamfYG62wd2tnlRZNPn97bj0RSkuegYp/wVfhHKD0B1KQpV14gm4I9da BQ9hZk46xrvcn+0wl4O3LCZCwKYjlZ/63x5kdPTeA9qbpk182SsVzVmouMLLhLdgnI itjpqaY6gD1Cg== Date: Wed, 15 Apr 2026 18:58:47 +0300 From: Mike Rapoport To: Muchun Song Cc: Andrew Morton , David Hildenbrand , Muchun Song , Oscar Salvador , Michael Ellerman , Madhavan Srinivasan , Lorenzo Stoakes , "Liam R . Howlett" , Vlastimil Babka , 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 Subject: Re: [PATCH v2 3/6] mm/sparse-vmemmap: Fix DAX vmemmap accounting with optimization Message-ID: References: <20260415111412.1003526-1-songmuchun@bytedance.com> <20260415111412.1003526-4-songmuchun@bytedance.com> 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-Disposition: inline In-Reply-To: <20260415111412.1003526-4-songmuchun@bytedance.com> On Wed, Apr 15, 2026 at 07:14:09PM +0800, 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. > > 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. > > Fixes: 15995a352474 ("mm: report per-page metadata information") > Signed-off-by: Muchun Song Acked-by: Mike Rapoport (Microsoft) > --- > mm/sparse-vmemmap.c | 32 ++++++++++++++++++++++++++++---- > 1 file changed, 28 insertions(+), 4 deletions(-) > > diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c > index 40290fbc1db4..05e3e2b94e32 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) > } > } > > +static int __meminit section_vmemmap_pages(unsigned long pfn, unsigned long nr_pages, > + struct vmem_altmap *altmap, > + struct dev_pagemap *pgmap) > +{ > + unsigned int order = pgmap ? pgmap->vmemmap_shift : 0; > + unsigned long pages_per_compound = 1L << order; > + > + VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, min(pages_per_compound, > + PAGES_PER_SECTION))); > + VM_WARN_ON_ONCE(pfn_to_section_nr(pfn) != 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; > + > + return 0; > +} > + > static struct page * __meminit populate_section_memmap(unsigned long pfn, > unsigned long nr_pages, int nid, struct vmem_altmap *altmap, > struct dev_pagemap *pgmap) > @@ -659,7 +682,7 @@ static struct page * __meminit populate_section_memmap(unsigned long pfn, > struct page *page = __populate_section_memmap(pfn, nr_pages, nid, altmap, > pgmap); > > - memmap_pages_add(DIV_ROUND_UP(nr_pages * sizeof(struct page), PAGE_SIZE)); > + memmap_pages_add(section_vmemmap_pages(pfn, nr_pages, altmap, pgmap)); > > return page; > } > @@ -670,7 +693,7 @@ static void depopulate_section_memmap(unsigned long pfn, unsigned long nr_pages, > unsigned long start = (unsigned long) pfn_to_page(pfn); > unsigned long end = start + nr_pages * sizeof(struct page); > > - memmap_pages_add(-1L * (DIV_ROUND_UP(nr_pages * sizeof(struct page), PAGE_SIZE))); > + memmap_pages_add(-section_vmemmap_pages(pfn, nr_pages, altmap, pgmap)); > vmemmap_free(start, end, altmap); > } > > @@ -679,9 +702,10 @@ static void free_map_bootmem(struct page *memmap, struct vmem_altmap *altmap, > { > unsigned long start = (unsigned long)memmap; > unsigned long end = (unsigned long)(memmap + PAGES_PER_SECTION); > + unsigned long pfn = page_to_pfn(memmap); > > - memmap_boot_pages_add(-1L * (DIV_ROUND_UP(PAGES_PER_SECTION * sizeof(struct page), > - PAGE_SIZE))); > + memmap_boot_pages_add(-section_vmemmap_pages(pfn, PAGES_PER_SECTION, > + altmap, pgmap)); > vmemmap_free(start, end, NULL); > } > > -- > 2.20.1 > -- Sincerely yours, Mike.