Linux-mm Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] fs/proc/task_mmu: count KSM-placed zero pages in smaps
@ 2026-07-06 12:13 Jinjiang Tu
  2026-07-06 13:40 ` David Hildenbrand (Arm)
  0 siblings, 1 reply; 4+ messages in thread
From: Jinjiang Tu @ 2026-07-06 12:13 UTC (permalink / raw)
  To: akpm, david, liam, ljs, vbabka, jannh, pfalcato, xu.xin16,
	chengming.zhou, linux-mm, linux-fsdevel
  Cc: wangkefeng.wang, sunnanyong, tujinjiang

When KSM deduplicates a page to the kernel zero page (i.e. when
/sys/kernel/mm/ksm/use_zero_pages=1), it places a zero PTE with the dirty
bit set. vm_normal_page() returns NULL for such PTEs, so smaps_pte_entry()
bails out before reaching smaps_account() and these pages are never counted
into mss->ksm. As a result /proc/<pid>/smaps and smaps_rollup report a KSM
value of 0 even though the region is fully merged.

Count KSM-placed zero pages directly in smaps_pte_entry() using
is_ksm_zero_pte().

Signed-off-by: Jinjiang Tu <tujinjiang@huawei.com>
---
 fs/proc/task_mmu.c  | 3 +++
 include/linux/ksm.h | 2 ++
 2 files changed, 5 insertions(+)

diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index d32408f7cd5e..3f446e9f59b6 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -1061,6 +1061,9 @@ static void smaps_pte_entry(pte_t *pte, unsigned long addr,
 		young = pte_young(ptent);
 		dirty = pte_dirty(ptent);
 		present = true;
+
+		if (is_ksm_zero_pte(ptent))
+			mss->ksm += PAGE_SIZE;
 	} else if (pte_none(ptent)) {
 		smaps_pte_hole_lookup(addr, walk);
 	} else {
diff --git a/include/linux/ksm.h b/include/linux/ksm.h
index d39d0d5483a2..abb41b3b7f4b 100644
--- a/include/linux/ksm.h
+++ b/include/linux/ksm.h
@@ -127,6 +127,8 @@ static inline void ksm_exit(struct mm_struct *mm)
 {
 }
 
+#define is_ksm_zero_pte(pte) false
+
 static inline void ksm_might_unmap_zero_page(struct mm_struct *mm, pte_t pte)
 {
 }
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-07-07  2:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-06 12:13 [PATCH] fs/proc/task_mmu: count KSM-placed zero pages in smaps Jinjiang Tu
2026-07-06 13:40 ` David Hildenbrand (Arm)
2026-07-07  2:42   ` Jinjiang Tu
2026-07-07  2:49   ` Jinjiang Tu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox