Re: [PATCH 2/2] mm/ksm: add initialization helpers for scan_get_next_rmap_item()

From: Xu Xin (vivo)

Date: Sat Nov 14 2026 - 09:56:47 EST


> On Thu, Nov 12, 2026 at 08:59:59PM +0800, Xu Xin (vivo) wrote:
> > Extract the new scan cycle detection (including draining per-CPU LRU
> > caches) and advancing the scan cursor to the first mm_slot into
> > scan_begin_new_cycle() and scan_get_first_mm().
> >
> > This keeps the exact execution order intact while making
> > scan_get_next_rmap_item() cleaner and easier to follow.
> >
> > No functional change intended.
> >
> > Signed-off-by: Xu Xin (vivo) <xu.xin@xxxxxxxxx>
>
> Again, thanks for doing this! LGTM and:
>
> Reviewed-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>

Thanks.

>
> > +static struct ksm_mm_slot *scan_get_first_mm(void)
> > +{
> > + struct ksm_mm_slot *mm_slot = ksm_scan.mm_slot;
> > + struct mm_slot *slot;
> > +
> > + spin_lock(&ksm_mmlist_lock);
> > +
> > + slot = list_entry(mm_slot->slot.mm_node.next, struct mm_slot, mm_node);
> > + mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot);
> > + ksm_scan.mm_slot = mm_slot;
> > +
> > + spin_unlock(&ksm_mmlist_lock);
>
> NIT: optional, but this could be:
>
> scoped_guard(mutex, &ksm_mmlist_lock) {
> slot = list_entry(mm_slot->slot.mm_node.next, struct mm_slot, mm_node);
> mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot);
> ksm_scan.mm_slot = mm_slot;
> }
>
>

Good idea, I will switch to scoped_guard.