* [PATCH v2 0/2] Two small patches to clean up mm/mm_slot.h
@ 2026-07-13 6:35 xu.xin16
2026-07-13 6:37 ` [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove xu.xin16
` (2 more replies)
0 siblings, 3 replies; 17+ messages in thread
From: xu.xin16 @ 2026-07-13 6:35 UTC (permalink / raw)
To: akpm, david, ljs
Cc: xu.xin16, ziy, baolin.wang, baohua, lance.yang, usama.arif,
chengming.zhou, qi.zheng, linux-mm, linux-kernel, npache,
ryan.roberts, dev.jain, wang.yaxin
From: xu xin <xu.xin16@zte.com.cn>
mm_slot.h is mainly used by THP and KSM.
Patch 1 introduces mm_slot_remove() to abstract the common
hash_del() + list_del() sequence used in both khugepaged and KSM.
Patch 2 cleans up the macro parameter names in mm_slot_lookup() and
mm_slot_insert() by removing the leading underscores, and adds a
comment explaining why they cannot be converted to static inline
functions (they rely on sizeof() on the actual array argument).
xu xin (2):
mm/mm_slot.h: add a helper function mm_slot_remove
mm/mm_slot.h: clean up macro parameter names in mm_slot_lookup() and
mm_slot_insert()
mm/khugepaged.c | 6 ++----
mm/ksm.c | 9 +++------
mm/mm_slot.h | 22 ++++++++++++++++------
3 files changed, 21 insertions(+), 16 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 17+ messages in thread* [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove 2026-07-13 6:35 [PATCH v2 0/2] Two small patches to clean up mm/mm_slot.h xu.xin16 @ 2026-07-13 6:37 ` xu.xin16 2026-07-13 11:48 ` Nico Pache ` (5 more replies) 2026-07-13 6:38 ` mm/mm_slot.h: clean up macro parameter names in mm_slot_lookup() and mm_slot_insert() xu.xin16 2026-07-13 6:41 ` [PATCH v2 2/2] " xu.xin16 2 siblings, 6 replies; 17+ messages in thread From: xu.xin16 @ 2026-07-13 6:37 UTC (permalink / raw) To: akpm, david, ljs Cc: akpm, david, ljs, ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, linux-mm, linux-kernel, npache, ryan.roberts, dev.jain, wang.yaxin, xu.xin16 From: xu xin <xu.xin16@zte.com.cn> Both THP 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(). Introduce mm_slot_remove() to abstract the common hash_del() + list_del() sequence used in both khugepaged and KSM. No functional change is intended. Signed-off-by: xu xin <xu.xin16@zte.com.cn> --- mm/khugepaged.c | 6 ++---- mm/ksm.c | 9 +++------ mm/mm_slot.h | 5 +++++ 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 58e14d1543ec..5f6eb1bd9a67 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -606,8 +606,7 @@ void __khugepaged_exit(struct mm_struct *mm) spin_lock(&khugepaged_mm_lock); slot = mm_slot_lookup(mm_slots_hash, mm); if (slot && khugepaged_scan.mm_slot != slot) { - hash_del(&slot->hash); - list_del(&slot->mm_node); + mm_slot_remove(slot); free = 1; } spin_unlock(&khugepaged_mm_lock); @@ -1802,8 +1801,7 @@ static void collect_mm_slot(struct mm_slot *slot) if (collapse_test_exit(mm)) { /* free mm_slot */ - hash_del(&slot->hash); - list_del(&slot->mm_node); + mm_slot_remove(slot); /* * Not strictly needed because the mm exited already. diff --git a/mm/ksm.c b/mm/ksm.c index 2791ce5bd44b..443dab513da6 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1257,8 +1257,7 @@ static int unmerge_and_remove_all_rmap_items(void) struct mm_slot, mm_node); ksm_scan.mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot); if (ksm_test_exit(mm)) { - hash_del(&mm_slot->slot.hash); - list_del(&mm_slot->slot.mm_node); + mm_slot_remove(&mm_slot->slot); spin_unlock(&ksm_mmlist_lock); mm_slot_free(mm_slot_cache, mm_slot); @@ -2772,8 +2771,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) * or when all VM_MERGEABLE areas have been unmapped (and * mmap_lock then protects against race with MADV_MERGEABLE). */ - hash_del(&mm_slot->slot.hash); - list_del(&mm_slot->slot.mm_node); + mm_slot_remove(&mm_slot->slot); spin_unlock(&ksm_mmlist_lock); mm_slot_free(mm_slot_cache, mm_slot); @@ -3116,8 +3114,7 @@ void __ksm_exit(struct mm_struct *mm) if (ksm_scan.mm_slot == mm_slot) goto unlock; if (!mm_slot->rmap_list) { - hash_del(&slot->hash); - list_del(&slot->mm_node); + mm_slot_remove(slot); easy_to_free = 1; } else { list_move(&slot->mm_node, diff --git a/mm/mm_slot.h b/mm/mm_slot.h index 83f18ed1c4bd..5de3e91d86b4 100644 --- a/mm/mm_slot.h +++ b/mm/mm_slot.h @@ -52,4 +52,9 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp) hash_add(_hashtable, &_mm_slot->hash, (unsigned long)_mm); \ }) +static inline void mm_slot_remove(struct mm_slot *slot) +{ + hash_del(&slot->hash); + list_del(&slot->mm_node); +} #endif /* _LINUX_MM_SLOT_H */ -- 2.25.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove 2026-07-13 6:37 ` [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove xu.xin16 @ 2026-07-13 11:48 ` Nico Pache 2026-07-13 13:51 ` Zi Yan ` (4 subsequent siblings) 5 siblings, 0 replies; 17+ messages in thread From: Nico Pache @ 2026-07-13 11:48 UTC (permalink / raw) To: xu.xin16 Cc: akpm, david, ljs, ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, linux-mm, linux-kernel, ryan.roberts, dev.jain, wang.yaxin On Mon, Jul 13, 2026 at 12:37 AM <xu.xin16@zte.com.cn> wrote: > > From: xu xin <xu.xin16@zte.com.cn> > > Both THP 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(). > > Introduce mm_slot_remove() to abstract the common hash_del() + list_del() > sequence used in both khugepaged and KSM. > > No functional change is intended. > > Signed-off-by: xu xin <xu.xin16@zte.com.cn> LGTM! Reviewed-by: Nico Pache <npache@redhat.com> > --- > mm/khugepaged.c | 6 ++---- > mm/ksm.c | 9 +++------ > mm/mm_slot.h | 5 +++++ > 3 files changed, 10 insertions(+), 10 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 58e14d1543ec..5f6eb1bd9a67 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -606,8 +606,7 @@ void __khugepaged_exit(struct mm_struct *mm) > spin_lock(&khugepaged_mm_lock); > slot = mm_slot_lookup(mm_slots_hash, mm); > if (slot && khugepaged_scan.mm_slot != slot) { > - hash_del(&slot->hash); > - list_del(&slot->mm_node); > + mm_slot_remove(slot); > free = 1; > } > spin_unlock(&khugepaged_mm_lock); > @@ -1802,8 +1801,7 @@ static void collect_mm_slot(struct mm_slot *slot) > > if (collapse_test_exit(mm)) { > /* free mm_slot */ > - hash_del(&slot->hash); > - list_del(&slot->mm_node); > + mm_slot_remove(slot); > > /* > * Not strictly needed because the mm exited already. > diff --git a/mm/ksm.c b/mm/ksm.c > index 2791ce5bd44b..443dab513da6 100644 > --- a/mm/ksm.c > +++ b/mm/ksm.c > @@ -1257,8 +1257,7 @@ static int unmerge_and_remove_all_rmap_items(void) > struct mm_slot, mm_node); > ksm_scan.mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot); > if (ksm_test_exit(mm)) { > - hash_del(&mm_slot->slot.hash); > - list_del(&mm_slot->slot.mm_node); > + mm_slot_remove(&mm_slot->slot); > spin_unlock(&ksm_mmlist_lock); > > mm_slot_free(mm_slot_cache, mm_slot); > @@ -2772,8 +2771,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) > * or when all VM_MERGEABLE areas have been unmapped (and > * mmap_lock then protects against race with MADV_MERGEABLE). > */ > - hash_del(&mm_slot->slot.hash); > - list_del(&mm_slot->slot.mm_node); > + mm_slot_remove(&mm_slot->slot); > spin_unlock(&ksm_mmlist_lock); > > mm_slot_free(mm_slot_cache, mm_slot); > @@ -3116,8 +3114,7 @@ void __ksm_exit(struct mm_struct *mm) > if (ksm_scan.mm_slot == mm_slot) > goto unlock; > if (!mm_slot->rmap_list) { > - hash_del(&slot->hash); > - list_del(&slot->mm_node); > + mm_slot_remove(slot); > easy_to_free = 1; > } else { > list_move(&slot->mm_node, > diff --git a/mm/mm_slot.h b/mm/mm_slot.h > index 83f18ed1c4bd..5de3e91d86b4 100644 > --- a/mm/mm_slot.h > +++ b/mm/mm_slot.h > @@ -52,4 +52,9 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp) > hash_add(_hashtable, &_mm_slot->hash, (unsigned long)_mm); \ > }) > > +static inline void mm_slot_remove(struct mm_slot *slot) > +{ > + hash_del(&slot->hash); > + list_del(&slot->mm_node); > +} > #endif /* _LINUX_MM_SLOT_H */ > -- > 2.25.1 > ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove 2026-07-13 6:37 ` [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove xu.xin16 2026-07-13 11:48 ` Nico Pache @ 2026-07-13 13:51 ` Zi Yan 2026-07-13 15:19 ` Barry Song ` (3 subsequent siblings) 5 siblings, 0 replies; 17+ messages in thread From: Zi Yan @ 2026-07-13 13:51 UTC (permalink / raw) To: xu.xin16 Cc: akpm, david, ljs, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, linux-mm, linux-kernel, npache, ryan.roberts, dev.jain, wang.yaxin On 13 Jul 2026, at 2:37, xu.xin16@zte.com.cn wrote: > From: xu xin <xu.xin16@zte.com.cn> > > Both THP 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(). > > Introduce mm_slot_remove() to abstract the common hash_del() + list_del() > sequence used in both khugepaged and KSM. > > No functional change is intended. > > Signed-off-by: xu xin <xu.xin16@zte.com.cn> > --- > mm/khugepaged.c | 6 ++---- > mm/ksm.c | 9 +++------ > mm/mm_slot.h | 5 +++++ > 3 files changed, 10 insertions(+), 10 deletions(-) > LGTM. Reviewed-by: Zi Yan <ziy@nvidia.com> Best Regards, Yan, Zi ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove 2026-07-13 6:37 ` [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove xu.xin16 2026-07-13 11:48 ` Nico Pache 2026-07-13 13:51 ` Zi Yan @ 2026-07-13 15:19 ` Barry Song 2026-07-13 15:23 ` David Hildenbrand (Arm) ` (2 subsequent siblings) 5 siblings, 0 replies; 17+ messages in thread From: Barry Song @ 2026-07-13 15:19 UTC (permalink / raw) To: xu.xin16 Cc: akpm, david, ljs, ziy, baolin.wang, lance.yang, usama.arif, chengming.zhou, qi.zheng, linux-mm, linux-kernel, npache, ryan.roberts, dev.jain, wang.yaxin On Mon, Jul 13, 2026 at 2:37 PM <xu.xin16@zte.com.cn> wrote: > > From: xu xin <xu.xin16@zte.com.cn> > > Both THP 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(). > > Introduce mm_slot_remove() to abstract the common hash_del() + list_del() > sequence used in both khugepaged and KSM. > > No functional change is intended. > > Signed-off-by: xu xin <xu.xin16@zte.com.cn> > --- LGTM, Reviewed-by: Barry Song <baohua@kernel.org> ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove 2026-07-13 6:37 ` [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove xu.xin16 ` (2 preceding siblings ...) 2026-07-13 15:19 ` Barry Song @ 2026-07-13 15:23 ` David Hildenbrand (Arm) 2026-07-13 16:03 ` Lorenzo Stoakes (ARM) 2026-07-14 0:16 ` SJ Park 5 siblings, 0 replies; 17+ messages in thread From: David Hildenbrand (Arm) @ 2026-07-13 15:23 UTC (permalink / raw) To: xu.xin16, akpm, ljs Cc: ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, linux-mm, linux-kernel, npache, ryan.roberts, dev.jain, wang.yaxin On 7/13/26 08:37, xu.xin16@zte.com.cn wrote: > From: xu xin <xu.xin16@zte.com.cn> > > Both THP 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(). > > Introduce mm_slot_remove() to abstract the common hash_del() + list_del() > sequence used in both khugepaged and KSM. > > No functional change is intended. > > Signed-off-by: xu xin <xu.xin16@zte.com.cn> > --- Acked-by: David Hildenbrand (Arm) <david@kernel.org> -- Cheers, David ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove 2026-07-13 6:37 ` [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove xu.xin16 ` (3 preceding siblings ...) 2026-07-13 15:23 ` David Hildenbrand (Arm) @ 2026-07-13 16:03 ` Lorenzo Stoakes (ARM) 2026-07-14 0:16 ` SJ Park 5 siblings, 0 replies; 17+ messages in thread From: Lorenzo Stoakes (ARM) @ 2026-07-13 16:03 UTC (permalink / raw) To: xu.xin16 Cc: akpm, david, ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, linux-mm, linux-kernel, npache, ryan.roberts, dev.jain, wang.yaxin On Mon, Jul 13, 2026 at 02:37:07PM +0800, xu.xin16@zte.com.cn wrote: > From: xu xin <xu.xin16@zte.com.cn> > > Both THP 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(). > > Introduce mm_slot_remove() to abstract the common hash_del() + list_del() > sequence used in both khugepaged and KSM. > > No functional change is intended. > > Signed-off-by: xu xin <xu.xin16@zte.com.cn> LGTM, so: Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org> > --- > mm/khugepaged.c | 6 ++---- > mm/ksm.c | 9 +++------ > mm/mm_slot.h | 5 +++++ > 3 files changed, 10 insertions(+), 10 deletions(-) > > diff --git a/mm/khugepaged.c b/mm/khugepaged.c > index 58e14d1543ec..5f6eb1bd9a67 100644 > --- a/mm/khugepaged.c > +++ b/mm/khugepaged.c > @@ -606,8 +606,7 @@ void __khugepaged_exit(struct mm_struct *mm) > spin_lock(&khugepaged_mm_lock); > slot = mm_slot_lookup(mm_slots_hash, mm); > if (slot && khugepaged_scan.mm_slot != slot) { > - hash_del(&slot->hash); > - list_del(&slot->mm_node); > + mm_slot_remove(slot); > free = 1; > } > spin_unlock(&khugepaged_mm_lock); > @@ -1802,8 +1801,7 @@ static void collect_mm_slot(struct mm_slot *slot) > > if (collapse_test_exit(mm)) { > /* free mm_slot */ > - hash_del(&slot->hash); > - list_del(&slot->mm_node); > + mm_slot_remove(slot); > > /* > * Not strictly needed because the mm exited already. > diff --git a/mm/ksm.c b/mm/ksm.c > index 2791ce5bd44b..443dab513da6 100644 > --- a/mm/ksm.c > +++ b/mm/ksm.c > @@ -1257,8 +1257,7 @@ static int unmerge_and_remove_all_rmap_items(void) > struct mm_slot, mm_node); > ksm_scan.mm_slot = mm_slot_entry(slot, struct ksm_mm_slot, slot); > if (ksm_test_exit(mm)) { > - hash_del(&mm_slot->slot.hash); > - list_del(&mm_slot->slot.mm_node); > + mm_slot_remove(&mm_slot->slot); > spin_unlock(&ksm_mmlist_lock); > > mm_slot_free(mm_slot_cache, mm_slot); > @@ -2772,8 +2771,7 @@ static struct ksm_rmap_item *scan_get_next_rmap_item(struct page **page) > * or when all VM_MERGEABLE areas have been unmapped (and > * mmap_lock then protects against race with MADV_MERGEABLE). > */ > - hash_del(&mm_slot->slot.hash); > - list_del(&mm_slot->slot.mm_node); > + mm_slot_remove(&mm_slot->slot); > spin_unlock(&ksm_mmlist_lock); > > mm_slot_free(mm_slot_cache, mm_slot); > @@ -3116,8 +3114,7 @@ void __ksm_exit(struct mm_struct *mm) > if (ksm_scan.mm_slot == mm_slot) > goto unlock; > if (!mm_slot->rmap_list) { > - hash_del(&slot->hash); > - list_del(&slot->mm_node); > + mm_slot_remove(slot); > easy_to_free = 1; > } else { > list_move(&slot->mm_node, > diff --git a/mm/mm_slot.h b/mm/mm_slot.h > index 83f18ed1c4bd..5de3e91d86b4 100644 > --- a/mm/mm_slot.h > +++ b/mm/mm_slot.h > @@ -52,4 +52,9 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp) > hash_add(_hashtable, &_mm_slot->hash, (unsigned long)_mm); \ > }) > > +static inline void mm_slot_remove(struct mm_slot *slot) > +{ > + hash_del(&slot->hash); > + list_del(&slot->mm_node); > +} > #endif /* _LINUX_MM_SLOT_H */ > -- > 2.25.1 Cheers, Lorenzo ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove 2026-07-13 6:37 ` [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove xu.xin16 ` (4 preceding siblings ...) 2026-07-13 16:03 ` Lorenzo Stoakes (ARM) @ 2026-07-14 0:16 ` SJ Park 5 siblings, 0 replies; 17+ messages in thread From: SJ Park @ 2026-07-14 0:16 UTC (permalink / raw) To: xu.xin16 Cc: SJ Park, akpm, david, ljs, ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, linux-mm, linux-kernel, npache, ryan.roberts, dev.jain, wang.yaxin On Mon, 13 Jul 2026 14:37:07 +0800 (CST) <xu.xin16@zte.com.cn> wrote: > From: xu xin <xu.xin16@zte.com.cn> > > Both THP 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(). > > Introduce mm_slot_remove() to abstract the common hash_del() + list_del() > sequence used in both khugepaged and KSM. > > No functional change is intended. Looks good and clean to me! > > Signed-off-by: xu xin <xu.xin16@zte.com.cn> Reviewed-by: SJ Park <sj@kernel.org> [...] > --- a/mm/mm_slot.h > +++ b/mm/mm_slot.h > @@ -52,4 +52,9 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp) > hash_add(_hashtable, &_mm_slot->hash, (unsigned long)_mm); \ > }) > > +static inline void mm_slot_remove(struct mm_slot *slot) > +{ > + hash_del(&slot->hash); > + list_del(&slot->mm_node); > +} > #endif /* _LINUX_MM_SLOT_H */ I'd prefer keep having the one blank line bfore the #endif. Definitely not a blocker but just thinking loud. Thanks, SJ [...] ^ permalink raw reply [flat|nested] 17+ messages in thread
* mm/mm_slot.h: clean up macro parameter names in mm_slot_lookup() and mm_slot_insert() 2026-07-13 6:35 [PATCH v2 0/2] Two small patches to clean up mm/mm_slot.h xu.xin16 2026-07-13 6:37 ` [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove xu.xin16 @ 2026-07-13 6:38 ` xu.xin16 2026-07-13 6:41 ` [PATCH v2 2/2] " xu.xin16 2 siblings, 0 replies; 17+ messages in thread From: xu.xin16 @ 2026-07-13 6:38 UTC (permalink / raw) To: akpm, david, ljs Cc: ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, linux-mm, linux-kernel, npache, ryan.roberts, dev.jain, wang.yaxin, xu.xin16 From: xu xin <xu.xin16@zte.com.cn> Clean up the names by replacing _foo with foo, and document why they cannot be static inline. Suggested-by: Lorenzo Stoakes <ljs@kernel.org> Signed-off-by: xu xin <xu.xin16@zte.com.cn> --- mm/mm_slot.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/mm/mm_slot.h b/mm/mm_slot.h index 5de3e91d86b4..710c70166c79 100644 --- a/mm/mm_slot.h +++ b/mm/mm_slot.h @@ -33,12 +33,17 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp) kmem_cache_free(cache, objp); } -#define mm_slot_lookup(_hashtable, _mm) \ +/* + * Note: mm_slot_lookup and mm_slot_insert cannot be converted to static inline + * functions because hash_for_each_possible relys on the actual array argument + * 'hashtable' for sizeof() instead of pointers. + */ +#define mm_slot_lookup(hashtable, mm) \ ({ \ struct mm_slot *tmp_slot, *mm_slot = NULL; \ \ - hash_for_each_possible(_hashtable, tmp_slot, hash, (unsigned long)_mm) \ - if (_mm == tmp_slot->mm) { \ + hash_for_each_possible(hashtable, tmp_slot, hash, (unsigned long)mm) \ + if (mm == tmp_slot->mm) { \ mm_slot = tmp_slot; \ break; \ } \ @@ -46,10 +51,10 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp) mm_slot; \ }) -#define mm_slot_insert(_hashtable, _mm, _mm_slot) \ +#define mm_slot_insert(hashtable, mm, mm_slot) \ ({ \ - _mm_slot->mm = _mm; \ - hash_add(_hashtable, &_mm_slot->hash, (unsigned long)_mm); \ + mm_slot->mm = mm; \ + hash_add(hashtable, &mm_slot->hash, (unsigned long)mm); \ }) static inline void mm_slot_remove(struct mm_slot *slot) -- 2.25.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v2 2/2] mm/mm_slot.h: clean up macro parameter names in mm_slot_lookup() and mm_slot_insert() 2026-07-13 6:35 [PATCH v2 0/2] Two small patches to clean up mm/mm_slot.h xu.xin16 2026-07-13 6:37 ` [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove xu.xin16 2026-07-13 6:38 ` mm/mm_slot.h: clean up macro parameter names in mm_slot_lookup() and mm_slot_insert() xu.xin16 @ 2026-07-13 6:41 ` xu.xin16 2026-07-13 15:21 ` Barry Song ` (2 more replies) 2 siblings, 3 replies; 17+ messages in thread From: xu.xin16 @ 2026-07-13 6:41 UTC (permalink / raw) To: akpm, david, ljs Cc: ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, linux-mm, linux-kernel, npache, ryan.roberts, dev.jain, wang.yaxin, xu.xin16 From: xu xin <xu.xin16@zte.com.cn> Suggested-by: Lorenzo Stoakes <ljs@kernel.org> Signed-off-by: xu xin <xu.xin16@zte.com.cn> --- mm/mm_slot.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/mm/mm_slot.h b/mm/mm_slot.h index 5de3e91d86b4..710c70166c79 100644 --- a/mm/mm_slot.h +++ b/mm/mm_slot.h @@ -33,12 +33,17 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp) kmem_cache_free(cache, objp); } -#define mm_slot_lookup(_hashtable, _mm) \ +/* + * Note: mm_slot_lookup and mm_slot_insert cannot be converted to static inline + * functions because hash_for_each_possible relys on the actual array argument + * 'hashtable' for sizeof() instead of pointers. + */ +#define mm_slot_lookup(hashtable, mm) \ ({ \ struct mm_slot *tmp_slot, *mm_slot = NULL; \ \ - hash_for_each_possible(_hashtable, tmp_slot, hash, (unsigned long)_mm) \ - if (_mm == tmp_slot->mm) { \ + hash_for_each_possible(hashtable, tmp_slot, hash, (unsigned long)mm) \ + if (mm == tmp_slot->mm) { \ mm_slot = tmp_slot; \ break; \ } \ @@ -46,10 +51,10 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp) mm_slot; \ }) -#define mm_slot_insert(_hashtable, _mm, _mm_slot) \ +#define mm_slot_insert(hashtable, mm, mm_slot) \ ({ \ - _mm_slot->mm = _mm; \ - hash_add(_hashtable, &_mm_slot->hash, (unsigned long)_mm); \ + mm_slot->mm = mm; \ + hash_add(hashtable, &mm_slot->hash, (unsigned long)mm); \ }) static inline void mm_slot_remove(struct mm_slot *slot) -- 2.25.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH v2 2/2] mm/mm_slot.h: clean up macro parameter names in mm_slot_lookup() and mm_slot_insert() 2026-07-13 6:41 ` [PATCH v2 2/2] " xu.xin16 @ 2026-07-13 15:21 ` Barry Song 2026-07-14 0:32 ` xu.xin16 2026-07-13 15:24 ` David Hildenbrand (Arm) 2026-07-13 16:13 ` Lorenzo Stoakes (ARM) 2 siblings, 1 reply; 17+ messages in thread From: Barry Song @ 2026-07-13 15:21 UTC (permalink / raw) To: xu.xin16 Cc: akpm, david, ljs, ziy, baolin.wang, lance.yang, usama.arif, chengming.zhou, qi.zheng, linux-mm, linux-kernel, npache, ryan.roberts, dev.jain, wang.yaxin On Mon, Jul 13, 2026 at 2:42 PM <xu.xin16@zte.com.cn> wrote: > > From: xu xin <xu.xin16@zte.com.cn> > Can we have some words here to explain why? > Suggested-by: Lorenzo Stoakes <ljs@kernel.org> > Signed-off-by: xu xin <xu.xin16@zte.com.cn> > --- ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 2/2] mm/mm_slot.h: clean up macro parameter names in mm_slot_lookup() and mm_slot_insert() 2026-07-13 15:21 ` Barry Song @ 2026-07-14 0:32 ` xu.xin16 0 siblings, 0 replies; 17+ messages in thread From: xu.xin16 @ 2026-07-14 0:32 UTC (permalink / raw) To: baohua Cc: akpm, david, ljs, ziy, baolin.wang, lance.yang, usama.arif, chengming.zhou, qi.zheng, linux-mm, linux-kernel, npache, ryan.roberts, dev.jain, wang.yaxin > > > > From: xu xin <xu.xin16@zte.com.cn> > > > > Can we have some words here to explain why? Sure, my SMTP settings were messed up, so I had to manually paste the patch, and it just so happened that I left out the description. I guess I should resend it. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 2/2] mm/mm_slot.h: clean up macro parameter names in mm_slot_lookup() and mm_slot_insert() 2026-07-13 6:41 ` [PATCH v2 2/2] " xu.xin16 2026-07-13 15:21 ` Barry Song @ 2026-07-13 15:24 ` David Hildenbrand (Arm) 2026-07-14 0:30 ` xu.xin16 2026-07-13 16:13 ` Lorenzo Stoakes (ARM) 2 siblings, 1 reply; 17+ messages in thread From: David Hildenbrand (Arm) @ 2026-07-13 15:24 UTC (permalink / raw) To: xu.xin16, akpm, ljs Cc: ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, linux-mm, linux-kernel, npache, ryan.roberts, dev.jain, wang.yaxin On 7/13/26 08:41, xu.xin16@zte.com.cn wrote: > From: xu xin <xu.xin16@zte.com.cn> > No patch description, but the other patch "mm/mm_slot.h: clean up macro parameter names in mm_slot_lookup() and mm_slot_insert()" has some. > Suggested-by: Lorenzo Stoakes <ljs@kernel.org> > Signed-off-by: xu xin <xu.xin16@zte.com.cn> > --- > mm/mm_slot.h | 17 +++++++++++------ > 1 file changed, 11 insertions(+), 6 deletions(-) > > diff --git a/mm/mm_slot.h b/mm/mm_slot.h > index 5de3e91d86b4..710c70166c79 100644 > --- a/mm/mm_slot.h > +++ b/mm/mm_slot.h > @@ -33,12 +33,17 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp) > kmem_cache_free(cache, objp); > } > > -#define mm_slot_lookup(_hashtable, _mm) \ > +/* > + * Note: mm_slot_lookup and mm_slot_insert cannot be converted to static inline > + * functions because hash_for_each_possible relys on the actual array argument > + * 'hashtable' for sizeof() instead of pointers. > + */ > +#define mm_slot_lookup(hashtable, mm) \ > ({ \ > struct mm_slot *tmp_slot, *mm_slot = NULL; \ > \ > - hash_for_each_possible(_hashtable, tmp_slot, hash, (unsigned long)_mm) \ > - if (_mm == tmp_slot->mm) { \ > + hash_for_each_possible(hashtable, tmp_slot, hash, (unsigned long)mm) \ > + if (mm == tmp_slot->mm) { \ > mm_slot = tmp_slot; \ > break; \ > } \ > @@ -46,10 +51,10 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp) > mm_slot; \ > }) > > -#define mm_slot_insert(_hashtable, _mm, _mm_slot) \ > +#define mm_slot_insert(hashtable, mm, mm_slot) \ > ({ \ > - _mm_slot->mm = _mm; \ > - hash_add(_hashtable, &_mm_slot->hash, (unsigned long)_mm); \ > + mm_slot->mm = mm; \ > + hash_add(hashtable, &mm_slot->hash, (unsigned long)mm); \ > }) > > static inline void mm_slot_remove(struct mm_slot *slot) -- Cheers, David ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 2/2] mm/mm_slot.h: clean up macro parameter names in mm_slot_lookup() and mm_slot_insert() 2026-07-13 15:24 ` David Hildenbrand (Arm) @ 2026-07-14 0:30 ` xu.xin16 0 siblings, 0 replies; 17+ messages in thread From: xu.xin16 @ 2026-07-14 0:30 UTC (permalink / raw) To: david Cc: akpm, ljs, ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, linux-mm, linux-kernel, npache, ryan.roberts, dev.jain, wang.yaxin > > From: xu xin <xu.xin16@zte.com.cn> > > > > No patch description, but the other patch "mm/mm_slot.h: clean up macro > parameter names in mm_slot_lookup() and mm_slot_insert()" has some. Oh, my SMTP settings were messed up, so I had to manually paste the patch, and it just so happened that I left out the description. I guess I should resend it. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 2/2] mm/mm_slot.h: clean up macro parameter names in mm_slot_lookup() and mm_slot_insert() 2026-07-13 6:41 ` [PATCH v2 2/2] " xu.xin16 2026-07-13 15:21 ` Barry Song 2026-07-13 15:24 ` David Hildenbrand (Arm) @ 2026-07-13 16:13 ` Lorenzo Stoakes (ARM) 2026-07-14 0:41 ` xu.xin16 2 siblings, 1 reply; 17+ messages in thread From: Lorenzo Stoakes (ARM) @ 2026-07-13 16:13 UTC (permalink / raw) To: xu.xin16 Cc: akpm, david, ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, linux-mm, linux-kernel, npache, ryan.roberts, dev.jain, wang.yaxin On Mon, Jul 13, 2026 at 02:41:53PM +0800, xu.xin16@zte.com.cn wrote: > From: xu xin <xu.xin16@zte.com.cn> > Obv. as others have noted, you're missing a commit message here :) > Suggested-by: Lorenzo Stoakes <ljs@kernel.org> Hmm not sure I suggested adding a comment to explain it... or removing the prefix _ from the existing macros :P > Signed-off-by: xu xin <xu.xin16@zte.com.cn> Honestly I don't think this is really adding much, but I guess adding the comment can't hurt. > --- > mm/mm_slot.h | 17 +++++++++++------ > 1 file changed, 11 insertions(+), 6 deletions(-) > > diff --git a/mm/mm_slot.h b/mm/mm_slot.h > index 5de3e91d86b4..710c70166c79 100644 > --- a/mm/mm_slot.h > +++ b/mm/mm_slot.h > @@ -33,12 +33,17 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp) > kmem_cache_free(cache, objp); > } > > -#define mm_slot_lookup(_hashtable, _mm) \ > +/* > + * Note: mm_slot_lookup and mm_slot_insert cannot be converted to static inline > + * functions because hash_for_each_possible relys on the actual array argument > + * 'hashtable' for sizeof() instead of pointers. > + */ I didn't say that you should change the _macros_ to drop the underscores though, there could be some nasty macro hygiene issue without (though probably something's broken if that does happen). So let's not do that. Also you'd probably want this comment above both with a newline after so it doesn't just seem attached to mm_slot_lookup() :) > +#define mm_slot_lookup(hashtable, mm) \ > ({ \ > struct mm_slot *tmp_slot, *mm_slot = NULL; \ > \ > - hash_for_each_possible(_hashtable, tmp_slot, hash, (unsigned long)_mm) \ > - if (_mm == tmp_slot->mm) { \ > + hash_for_each_possible(hashtable, tmp_slot, hash, (unsigned long)mm) \ > + if (mm == tmp_slot->mm) { \ > mm_slot = tmp_slot; \ > break; \ > } \ > @@ -46,10 +51,10 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp) > mm_slot; \ > }) > > -#define mm_slot_insert(_hashtable, _mm, _mm_slot) \ > +#define mm_slot_insert(hashtable, mm, mm_slot) \ > ({ \ > - _mm_slot->mm = _mm; \ > - hash_add(_hashtable, &_mm_slot->hash, (unsigned long)_mm); \ > + mm_slot->mm = mm; \ > + hash_add(hashtable, &mm_slot->hash, (unsigned long)mm); \ > }) > > static inline void mm_slot_remove(struct mm_slot *slot) > -- > 2.25.1 I think maybe we should just drop this patch altogether and stick with the first patch only. Cheers, Lorenzo ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 2/2] mm/mm_slot.h: clean up macro parameter names in mm_slot_lookup() and mm_slot_insert() 2026-07-13 16:13 ` Lorenzo Stoakes (ARM) @ 2026-07-14 0:41 ` xu.xin16 2026-07-14 1:06 ` Barry Song 0 siblings, 1 reply; 17+ messages in thread From: xu.xin16 @ 2026-07-14 0:41 UTC (permalink / raw) To: ljs Cc: akpm, david, ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, linux-mm, linux-kernel, npache, ryan.roberts, dev.jain, wang.yaxin > Hmm not sure I suggested adding a comment to explain it... or removing the > prefix _ from the existing macros :P Maybe I misunderstood it. > > > Signed-off-by: xu xin <xu.xin16@zte.com.cn> > > Honestly I don't think this is really adding much, but I guess adding the > comment can't hurt. Agreed. Regardless, adding a comment to explain why these have to be macros would be better. Would it be okay if I send a new patch that merely adds the comment, without removing the underscore prefixes from the existing macros? > > > --- > > mm/mm_slot.h | 17 +++++++++++------ > > 1 file changed, 11 insertions(+), 6 deletions(-) > > > > diff --git a/mm/mm_slot.h b/mm/mm_slot.h > > index 5de3e91d86b4..710c70166c79 100644 > > --- a/mm/mm_slot.h > > +++ b/mm/mm_slot.h > > @@ -33,12 +33,17 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp) > > kmem_cache_free(cache, objp); > > } > > > > -#define mm_slot_lookup(_hashtable, _mm) \ > > +/* > > + * Note: mm_slot_lookup and mm_slot_insert cannot be converted to static inline > > + * functions because hash_for_each_possible relys on the actual array argument > > + * 'hashtable' for sizeof() instead of pointers. > > + */ > > I didn't say that you should change the _macros_ to drop the underscores > though, there could be some nasty macro hygiene issue without (though > probably something's broken if that does happen). > > So let's not do that. > > Also you'd probably want this comment above both with a newline after so it > doesn't just seem attached to mm_slot_lookup() :) Yes. ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 2/2] mm/mm_slot.h: clean up macro parameter names in mm_slot_lookup() and mm_slot_insert() 2026-07-14 0:41 ` xu.xin16 @ 2026-07-14 1:06 ` Barry Song 0 siblings, 0 replies; 17+ messages in thread From: Barry Song @ 2026-07-14 1:06 UTC (permalink / raw) To: xu.xin16 Cc: ljs, akpm, david, ziy, baolin.wang, lance.yang, usama.arif, chengming.zhou, qi.zheng, linux-mm, linux-kernel, npache, ryan.roberts, dev.jain, wang.yaxin On Tue, Jul 14, 2026 at 8:41 AM <xu.xin16@zte.com.cn> wrote: > > > Hmm not sure I suggested adding a comment to explain it... or removing the > > prefix _ from the existing macros :P > > Maybe I misunderstood it. > > > > > > Signed-off-by: xu xin <xu.xin16@zte.com.cn> > > > > Honestly I don't think this is really adding much, but I guess adding the > > comment can't hurt. > > Agreed. > > Regardless, adding a comment to explain why these have to be macros would be > better. Would it be okay if I send a new patch that merely adds the comment, > without removing the underscore prefixes from the existing macros? > Yep, I would vote for this, because otherwise someone else might try to make it static inline again in the future. Best Regards Barry ^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2026-07-14 1:06 UTC | newest] Thread overview: 17+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-07-13 6:35 [PATCH v2 0/2] Two small patches to clean up mm/mm_slot.h xu.xin16 2026-07-13 6:37 ` [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove xu.xin16 2026-07-13 11:48 ` Nico Pache 2026-07-13 13:51 ` Zi Yan 2026-07-13 15:19 ` Barry Song 2026-07-13 15:23 ` David Hildenbrand (Arm) 2026-07-13 16:03 ` Lorenzo Stoakes (ARM) 2026-07-14 0:16 ` SJ Park 2026-07-13 6:38 ` mm/mm_slot.h: clean up macro parameter names in mm_slot_lookup() and mm_slot_insert() xu.xin16 2026-07-13 6:41 ` [PATCH v2 2/2] " xu.xin16 2026-07-13 15:21 ` Barry Song 2026-07-14 0:32 ` xu.xin16 2026-07-13 15:24 ` David Hildenbrand (Arm) 2026-07-14 0:30 ` xu.xin16 2026-07-13 16:13 ` Lorenzo Stoakes (ARM) 2026-07-14 0:41 ` xu.xin16 2026-07-14 1:06 ` Barry Song
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.