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//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 --- 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