[PATCH v6 4/7] mm/sparse-vmemmap: Fix DAX vmemmap accounting with optimization
Muchun Song
muchun.song at linux.dev
Fri Apr 24 17:48:44 AEST 2026
> On Apr 24, 2026, at 15:33, David Hildenbrand (Arm) <david at kernel.org> wrote:
>
> On 4/24/26 04:55, 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")
>> Cc: stable at vger.kernel.org
>> 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..2e642c5ff3f2 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,
>> + min(pages_per_compound, PAGES_PER_SECTION)));
>
> FWIW, I though the right thing to do here would be:
>
> VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, pages_per_compound);
> VM_WARN_ON_ONCE(!IS_ALIGNED(pfn | nr_pages, PAGES_PER_SUBSECTION);
>
> I don't really see how PAGES_PER_SECTION make sense given that
> PAGES_PER_SUBSECTION are the smallest granularity we allow adding/removing.
>
> Also, the "min()" implies that there is a connection between both properties,
> but there isn't to that degree.
>
> If order == 0, then you'd only ever check alignment for ... 1, not
> PAGES_PER_SUBSECTION, which already looks weird.
>
> So you really want to check "max(pages_per_compound, PAGES_PER_SUBSECTION)", but
> just having two statements is clearer.
>
> Or am I getting something very wrong here? :)
>
You are absolutely right. I misread it earlier. I mistakenly read
PAGES_PER_SUBSECTION as PAGES_PER_SECTION, which is why I still used
PAGES_PER_SECTION in v5. That was my mistake and obviously not what
you originally meant.
I completely agree with your suggestion to use two statements here,
as it makes the alignment requirements much clearer. I'll fix this in
the next version. Thanks for pointing this out!
Muchun,
Thanks.
>
> --
> Cheers,
>
> David
More information about the Linuxppc-dev
mailing list