Re: [PATCH 01/32] mm/shmem: count only the swapped pages in the requested range
From: Gregory Price (Meta)
Date: Tue Dec 01 2026 - 08:47:23 EST
On 2026-11-29 11:06 +0100, 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>
Tested-by: Gregory Price (Meta) <gourry@xxxxxxxxxx>
--
~Gregory