Re: [PATCH v4 2/5] docs/mm: ksm: describe how smart scan picks the scans to skip

From: Xu Xin (vivo)

Date: Sun Nov 08 2026 - 21:13:44 EST


On Sun, Nov 08, 2026 at 08:22:51PM -0500, Qiliang Yuan wrote:
> Documentation/mm/ksm.rst covers the stable tree and its reverse mapping,
> and Documentation/admin-guide/mm/ksm.rst only says that smart scan skips
> pages KSM has failed to merge before.
>
> Neither says how often an unmerged page is looked at, or that the scans
> are picked by the global scan number so that identical pages of
> different ages still meet in some scan, which merging through the
> unstable tree depends on.
>
> Add a section on smart scan that describes both.
>
> Signed-off-by: Qiliang Yuan <odys.yuan@xxxxxxxxx>
> Tested-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
> Reviewed-by: David Hildenbrand (Arm) <david@xxxxxxxxxx>
> ---
> Documentation/mm/ksm.rst | 16 ++++++++++++++++
> 1 file changed, 16 insertions(+)

Reviewed-by: Xu Xin (vivo) <xu.xin@xxxxxxxxx>

>
> diff --git a/Documentation/mm/ksm.rst b/Documentation/mm/ksm.rst
> index 5a80573162def..f954d221e8017 100644
> --- a/Documentation/mm/ksm.rst
> +++ b/Documentation/mm/ksm.rst
> @@ -75,6 +75,22 @@ The whole list of stable_node "dups" linked in the stable_node
> The frequency of such scans is defined by
> ``stable_node_chains_prune_millisecs`` sysfs tunable.
>
> +Smart scan
> +----------
> +With ``smart_scan`` enabled, ksmd skips pages that it has already tried
> +to merge without success. The ``age`` of a page's ksm_rmap_item counts
> +the scans that went by while the page stayed unmerged. A page younger
> +than three scans is looked at on every scan; after that it is looked at
> +every second scan up to an age of five, every fourth scan up to an age
> +of eight, and every eighth scan from then on.
> +
> +The scans that look at a page are picked by the global scan number
> +``ksm_scan.seqnr``, not counted per page. The unstable tree is rebuilt
> +on every scan, so two identical pages can only be merged in a scan that
> +looks at both. As the periods are powers of two, every page is looked
> +at on each scan whose number is a multiple of eight, so two identical
> +pages meet at least every eighth scan whatever their ages.
> +
> Reference
> ---------
> .. kernel-doc:: mm/ksm.c
>
> --
> 2.43.0
>