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

From: Weilin Tong

Date: Wed Oct 14 2026 - 02:28:23 EST


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 directly and remove the unused hstate variable.

Fixes: a08c7193e4f1 ("mm/filemap: remove hugetlb special casing in filemap.c")
Signed-off-by: Weilin Tong <tongweilin@xxxxxxxxxxxxxxxxx>

---
ipc/shm.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/ipc/shm.c b/ipc/shm.c
index 25190965c9a50..5ed2beef0f1d2 100644
--- a/ipc/shm.c
+++ b/ipc/shm.c
@@ -943,8 +943,7 @@ static void shm_add_rss_swap(struct shmid_kernel *shp,

if (is_file_hugepages(shp->shm_file)) {
struct address_space *mapping = inode->i_mapping;
- struct hstate *h = hstate_file(shp->shm_file);
- *rss_add += pages_per_huge_page(h) * mapping->nrpages;
+ *rss_add += mapping->nrpages;
} else {
#ifdef CONFIG_SHMEM
struct shmem_inode_info *info = SHMEM_I(inode);
--
2.43.5