Re: [PATCH 1/2] mm/ksm: extract helper functions for scan cycle cleanup
From: Lorenzo Stoakes (ARM)
Date: Fri Nov 13 2026 - 15:09:51 EST
On Thu, Nov 12, 2026 at 08:59:28PM +0800, Xu Xin (vivo) wrote:
> Since scan_get_next_rmap_item() is getting too large, extract two new
> helper functions, ksm_prune_migrate_nodes() and ksm_reset_unstable_trees(),
> to reduce indentation levels, isolate local variables, and improve the
> readability of the main scan loop.
>
> No functional change intended.
>
> Signed-off-by: Xu Xin (vivo) <xu.xin@xxxxxxxxx>
Thanks for doing this! LGTM so:
Reviewed-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
One small nit below, but it's not a big deal :)
> ---
> mm/ksm.c | 56 +++++++++++++++++++++++++++++++++-----------------------
> 1 file changed, 33 insertions(+), 23 deletions(-)
>
> diff --git a/mm/ksm.c b/mm/ksm.c
> index 5e24b5ca8dc8..49977bcf04f7 100644
> --- a/mm/ksm.c
> +++ b/mm/ksm.c
[ ... ]
> +static void ksm_reset_unstable_trees(void)
> +{
> + int nid;
> +
> + for (nid = 0; nid < ksm_nr_node_ids; nid++)
> + root_unstable_tree[nid] = RB_ROOT;
> +}
Recently I learned (and PeterZ reminded me :) that it's actually valid to
declare the var in the for-block in linux kernel C.
So this can be:
static void ksm_reset_unstable_trees(void)
{
for (int nid = 0; nid < ksm_nr_node_ids; nid++)
root_unstable_tree[nid] = RB_ROOT;
}
:)
--
Cheers, Lorenzo