Re: [PATCH v2] ipc/shm: fix RSS accounting for hugetlb shared memory

From: Muchun Song

Date: Wed Oct 14 2026 - 04:34:25 EST




> On Oct 14, 2026, at 16:22, Weilin Tong <tongweilin@xxxxxxxxxxxxxxxxx> wrote:
>
> Commit a08c7193e4f1 ("mm/filemap: remove hugetlb special casing in
> filemap.c") changed mapping->nrpages to count base pages for hugetlb
> folios. However, shm_add_rss_swap() still multiplies it by
> pages_per_huge_page(), overcounting RSS in both SHM_INFO and
> /proc/sysvipc/shm.
>
> Use mapping->nrpages for RSS accounting across all backing types, and
> account swap only for non-hugetlb shmem. Use READ_ONCE() for both counters
> instead of info->lock, which does not protect nrpages and cannot provide
> a consistent snapshot.
>
> Fixes: a08c7193e4f1 ("mm/filemap: remove hugetlb special casing in filemap.c")
> Suggested-by: Muchun Song <muchun.song@xxxxxxxxx>
> Signed-off-by: Weilin Tong <tongweilin@xxxxxxxxxxxxxxxxx>

Acked-by: Muchun Song <muchun.song@xxxxxxxxx>

Thanks.