Re: [PATCH 01/32] mm/shmem: count only the swapped pages in the requested range
From: Baolin Wang
Date: Wed Dec 02 2026 - 02:29:48 EST
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. Anyway, LGTM.
Reviewed-by: Baolin Wang <baolin.wang@xxxxxxxxxxxxxxxxx>