Re: [PATCH v3 1/4] mm/ksm: align smart scan skips with the scan number
From: David Hildenbrand (Arm)
Date: Sat Nov 07 2026 - 14:56:07 EST
On 11/7/26 17:57, Qiliang Yuan wrote:
> Smart scan skips pages that KSM has failed to de-duplicate for a while.
> Once a page is three scans old, its rmap_item counts down its own number
> of scans to skip, 1, 2, 4 and then 8 as it ages, so an old page is looked
> at every ninth scan.
>
> The unstable tree is rebuilt on every scan, so two identical pages that
> are not in the stable tree yet can only be merged in a scan that looks
> at both. Each countdown runs from when its own page became mergeable, so
> two pages that became mergeable at different times end up on different
> phases and, once both are old, may never be looked at in the same scan
> again. They then stay unmerged for as long as they live. The pairs below
> are counted by making a page mergeable, waiting for 0 to 20 full scans
> before doing the same with an identical page, 20 times for each wait,
> and checking the pair after another 64 full scans, on two boots per
> kernel.
>
> Pick the skipped scans by the global scan number instead, with periods
> of 2, 4 and 8 scans. The periods being powers of two, every old page is
> looked at on each scan that is a multiple of 8, whatever its age, so any
> two pages meet at least every eighth scan. The longest period goes from
> nine scans to eight, so ksmd looks at more of the pages that never
> merge. The rest of the table is measured on 64M of such pages, median of
> five runs of 256 scans on each of three boots per kernel, CPU time from
> schedstat:
>
> before after after/before
> pairs merged (of 420) 361 420 116%
> 334 420 126%
> pages looked at per scan 1792 2048 114%
>
Oh, I was wondering whether this should actually go to stable? Do you think the
above is rather an extreme case, and most users won't really run into it that
severely?
--
Cheers,
David