Re: [PATCH v2 1/3] mm/ksm: do not inherit ksm_zero_pages counter or PTE markers on fork

From: Karl Mehltretter

Date: Sat Nov 21 2026 - 10:38:11 EST


On Fri, 20 Nov 2026 15:43:59 +0800, Xu Xin (vivo) wrote:
> With the marker cleared, ksm_might_unmap_zero_page() will not
> decrement the counters on child exit, MADV_UNMERGEABLE in the child
> will not unnecessarily unshare inherited zero pages, and the global
> counter remains untouched.

Confirmed on mm-everything 758802f13004 with the smart-scan v4 series.
A test merged 1024 zero pages with use_zero_pages=1 and forked. Without
this patch, the child started with ksm_zero_pages=1024, the global
counter doubled, and MADV_UNMERGEABLE in the child allocated new pages.
With it, none of this happens.

The new check from 3/3 fails without this patch and passes with it, at
the default ksmd settings. Both tests gave the same results on x86-64,
i386, arm64, arm, riscv64, s390x, ppc64le, ppc64, ppc32, mips64el,
mipsel, sparc64, alpha, parisc, m68k and sh4 in QEMU.

Tested-by: Karl Mehltretter <kmehltretter@xxxxxxxxx>

Thanks,
Karl