Re: [PATCH] mm/mm_slot.h: add a helper function mm_slot_remove

From: Lorenzo Stoakes

Date: Fri Jul 10 2026 - 08:19:24 EST


On Fri, 10 Jul 2026 13:15:36 +0800, xu.xin16@xxxxxxxxxx <xu.xin16@xxxxxxxxxx> wrote:
> Both khugepaged (THP collapsing) and KSM manage per-mm scanning slots
> using the mm_slot structure. The slot is kept in a hash table and a
> list, and removal from both containers requires the same two operations:
> hash_del() and list_del().
>
> Currently, this two‑step removal is open‑coded in multiple places

Let's not have em-dots in the commit message ;)

> across khugepaged.c and ksm.c. This duplication makes the code slightly
> harder to read and maintain, and creates the risk that future changes to
> the removal logic might miss one of the call sites.
>
> Introduce a helper function mm_slot_remove() that encapsulates both
> deletions. This reduces redundancy, improves code clarity, and ensures
> that the removal sequence stays consistent.

You're talking far too much about a trivial change, just say something like
'this patch introduces mm_remove() to abstract this'.

>
> No functional change is intended.
>
> Signed-off-by: xu xin <xu.xin16@xxxxxxxxxx>

In general it's fine but I want more :) see below.

>
>
> diff --git a/mm/mm_slot.h b/mm/mm_slot.h
> index 83f18ed1c4bd..bc3b9ae8fdbc 100644
> --- a/mm/mm_slot.h
> +++ b/mm/mm_slot.h
> @@ -52,4 +52,11 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp)
> hash_add(_hashtable, &_mm_slot->hash, (unsigned long)_mm); \
> })
>

mm_slot.h also inexplicably implements mm_slot_lookup() and mm_slot_insert() as
macros. Can you change these to static inline functions in the respin?

Also rename the horrible names from _foo -> foo too please.

And we don't really need 'mm_slot' in the var name for a slot just 'slot' works
fine.

> +static inline void mm_slot_remove(struct mm_slot *_mm_slot)

Yeah this name is gross just 'slot' please.

> +{
> + hash_del(&_mm_slot->hash);
> + list_del(&_mm_slot->mm_node);
> +}
> +
> +
> #endif /* _LINUX_MM_SLOT_H */

Thanks, Lorenzo

--
Lorenzo Stoakes <ljs@xxxxxxxxxx>