Re: [PATCH 01/32] mm/shmem: count only the swapped pages in the requested range
From: David Hildenbrand (Arm)
Date: Wed Dec 02 2026 - 10:22:57 EST
On 12/2/26 08:29, Baolin Wang wrote:
>
>
> On 11/29/26 6:06 PM, David Hildenbrand (Arm) wrote:
>> shmem_partial_swap_usage() counts whole swap entries even when only part
>> of an entry falls within the requested range. Further, when a walk
>> starts inside a large entry, xas_pause() can resume beyond its end and
>> skip subsequent entries.
>>
>> Consequently, we can overcount "Swap" in /proc/<pid>/smaps and
>> smaps_rollup, especially for private writable mappings where the
>> function can be called once per empty PTE, but we can also undercount
>> it.
>>
>> Let's fix it by clamping each entry to the remaining range and advancing
>> "start" to avoid counting pages twice, and by using xas_set() to resume
>> at the first uncounted index after cond_resched_rcu().
>>
>> This has low urgency, as it only affects the "Swap" statistics in
>> /proc/<pid>/smaps and smaps_rollup. No need to CC stable.
>>
>> Fixes: 50f381eccefd ("mm: shmem: extend shmem_partial_swap_usage() to support large folio swap")
>> Reported-by: Chris Mason <mason@xxxxxxxxxx>
>> Signed-off-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
>> ---
>
> Agree, this is not a stable fix. I remember I discussed with Hugh early
> on that the smaps accounting is tolerable here, since xas_get_order() in
> this function is not reliable either.
Thanks for confirming!
--
Cheers,
David