[PATCH v5 v5 4/6] mm/sparse-vmemmap: Fix DAX vmemmap accounting with optimization

Muchun Song muchun.song at linux.dev
Thu Apr 23 22:04:21 AEST 2026



> On Apr 23, 2026, at 18:40, David Hildenbrand (Arm) <david at kernel.org> wrote:
> 
> On 4/23/26 09:19, 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 <songmuchun at bytedance.com>
>> Acked-by: Mike Rapoport (Microsoft) <rppt at kernel.org>
>> Acked-by: Oscar Salvador <osalvador at suse.de>
>> ---
>> mm/sparse-vmemmap.c | 31 +++++++++++++++++++++++++++----
>> 1 file changed, 27 insertions(+), 4 deletions(-)
>> 
>> diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
>> index 3340f6d30b01..979d71158c9b 100644
>> --- a/mm/sparse-vmemmap.c
>> +++ b/mm/sparse-vmemmap.c
>> @@ -652,6 +652,28 @@ void offline_mem_sections(unsigned long start_pfn, unsigned long end_pfn)
>> }
>> }
>> 
>> +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 = pgmap ? pgmap->vmemmap_shift : 0;
>> + 	const unsigned long pages_per_compound = 1UL << order;
>> +
>> + 	VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, pages_per_compound));
>> + 	VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, PAGES_PER_SECTION));
> 
> Thinking about the PAGES_PER_SECTION, can't we get called for sub-sections?

Oh, I see. My apologies—I just remembered why I took the minimum of
pages_per_compound and PAGES_PER_SECTION in the previous version v4:
it was specifically to support subsections.

In the last version, when I was addressing your suggestions/questions,
I forgot about this underlying logic and simplified it to two lines.
Of course, that’s on me, not you.

Ah, looks like I need to update the patch to fix this.

Muchun,
Thanks.

> 
> -- 
> Cheers,
> 
> David




More information about the Linuxppc-dev mailing list