* [PATCH v3 0/2] Two small patches to clean up mm/mm_slot.h @ 2026-07-14 1:24 xu.xin16 2026-07-14 1:26 ` [PATCH v3 1/2] mm/mm_slot.h: add a helper function mm_slot_remove xu.xin16 2026-07-14 1:28 ` [PATCH v3 2/2] mm/mm_slot.h: add comments for mm_slot_lookup/insert xu.xin16 0 siblings, 2 replies; 7+ messages in thread From: xu.xin16 @ 2026-07-14 1:24 UTC (permalink / raw) To: akpm, david, ljs, xu.xin16, ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, npache, ryan.roberts, dev.jain Cc: linux-mm, linux-kernel, 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 adds a comment explaining why mm_slot_lookup/insert cannot be converted to static inline functions. xu xin (2): mm/mm_slot.h: add a helper function mm_slot_remove mm/mm_slot.h: add comments for mm_slot_lookup/insert mm/khugepaged.c | 6 ++---- mm/ksm.c | 9 +++------ mm/mm_slot.h | 11 +++++++++++ 3 files changed, 16 insertions(+), 10 deletions(-) -- 2.25.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH v3 1/2] mm/mm_slot.h: add a helper function mm_slot_remove 2026-07-14 1:24 [PATCH v3 0/2] Two small patches to clean up mm/mm_slot.h xu.xin16 @ 2026-07-14 1:26 ` xu.xin16 2026-07-14 1:28 ` [PATCH v3 2/2] mm/mm_slot.h: add comments for mm_slot_lookup/insert xu.xin16 1 sibling, 0 replies; 7+ messages in thread From: xu.xin16 @ 2026-07-14 1:26 UTC (permalink / raw) To: akpm, david, ljs, ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, npache, ryan.roberts, dev.jain Cc: linux-mm, linux-kernel, 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> Reviewed-by: Nico Pache <npache@redhat.com> Reviewed-by: Zi Yan <ziy@nvidia.com> Reviewed-by: Barry Song <baohua@kernel.org> Acked-by: David Hildenbrand (Arm) <david@kernel.org> Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org> Reviewed-by: SJ Park <sj@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 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH v3 2/2] mm/mm_slot.h: add comments for mm_slot_lookup/insert 2026-07-14 1:24 [PATCH v3 0/2] Two small patches to clean up mm/mm_slot.h xu.xin16 2026-07-14 1:26 ` [PATCH v3 1/2] mm/mm_slot.h: add a helper function mm_slot_remove xu.xin16 @ 2026-07-14 1:28 ` xu.xin16 2026-07-14 1:37 ` Barry Song ` (3 more replies) 1 sibling, 4 replies; 7+ messages in thread From: xu.xin16 @ 2026-07-14 1:28 UTC (permalink / raw) To: akpm, david, ljs, ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, npache, ryan.roberts, dev.jain Cc: linux-mm, linux-kernel, wang.yaxin, xu.xin16 From: xu xin <xu.xin16@zte.com.cn> mm_slot_lookup() and mm_slot_insert() are the only helpers in this header that are implemented as macros rather than static inline functions. This may look inconsistent without explanation. Explain they must be macros because hash_for_each_possible() needs the table as an array (for sizeof), not a pointer. Signed-off-by: xu xin <xu.xin16@zte.com.cn> --- mm/mm_slot.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/mm_slot.h b/mm/mm_slot.h index 5de3e91d86b4..9b09b68e5742 100644 --- a/mm/mm_slot.h +++ b/mm/mm_slot.h @@ -33,6 +33,12 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp) kmem_cache_free(cache, objp); } +/* + * Note: mm_slot_lookup and mm_slot_insert cannot be converted to static inline + * functions because the hash helpers (hash_for_each_possible and hash_add) rely + * 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; \ -- 2.25.1 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH v3 2/2] mm/mm_slot.h: add comments for mm_slot_lookup/insert 2026-07-14 1:28 ` [PATCH v3 2/2] mm/mm_slot.h: add comments for mm_slot_lookup/insert xu.xin16 @ 2026-07-14 1:37 ` Barry Song 2026-07-14 9:35 ` Lorenzo Stoakes (ARM) ` (2 subsequent siblings) 3 siblings, 0 replies; 7+ messages in thread From: Barry Song @ 2026-07-14 1:37 UTC (permalink / raw) To: xu.xin16 Cc: akpm, david, ljs, ziy, baolin.wang, lance.yang, usama.arif, chengming.zhou, qi.zheng, npache, ryan.roberts, dev.jain, linux-mm, linux-kernel, wang.yaxin On Tue, Jul 14, 2026 at 9:28 AM <xu.xin16@zte.com.cn> wrote: > > From: xu xin <xu.xin16@zte.com.cn> > > mm_slot_lookup() and mm_slot_insert() are the only helpers in > this header that are implemented as macros rather than static inline > functions. This may look inconsistent without explanation. > > Explain they must be macros because hash_for_each_possible() > needs the table as an array (for sizeof), not a pointer. > > Signed-off-by: xu xin <xu.xin16@zte.com.cn> Thanks! Reviewed-by: Barry Song <baohua@kernel.org> ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 2/2] mm/mm_slot.h: add comments for mm_slot_lookup/insert 2026-07-14 1:28 ` [PATCH v3 2/2] mm/mm_slot.h: add comments for mm_slot_lookup/insert xu.xin16 2026-07-14 1:37 ` Barry Song @ 2026-07-14 9:35 ` Lorenzo Stoakes (ARM) 2026-07-14 9:44 ` Qi Zheng 2026-07-14 13:26 ` David Hildenbrand (Arm) 3 siblings, 0 replies; 7+ messages in thread From: Lorenzo Stoakes (ARM) @ 2026-07-14 9:35 UTC (permalink / raw) To: xu.xin16 Cc: akpm, david, ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, npache, ryan.roberts, dev.jain, linux-mm, linux-kernel, wang.yaxin On Tue, Jul 14, 2026 at 09:28:15AM +0800, xu.xin16@zte.com.cn wrote: > From: xu xin <xu.xin16@zte.com.cn> > > mm_slot_lookup() and mm_slot_insert() are the only helpers in > this header that are implemented as macros rather than static inline > functions. This may look inconsistent without explanation. > > Explain they must be macros because hash_for_each_possible() > needs the table as an array (for sizeof), not a pointer. > > Signed-off-by: xu xin <xu.xin16@zte.com.cn> LGTM, so: Reviewed-by: Lorenzo Stoakes (ARM) <ljs@kernel.org> > --- > mm/mm_slot.h | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/mm/mm_slot.h b/mm/mm_slot.h > index 5de3e91d86b4..9b09b68e5742 100644 > --- a/mm/mm_slot.h > +++ b/mm/mm_slot.h > @@ -33,6 +33,12 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp) > kmem_cache_free(cache, objp); > } > > +/* > + * Note: mm_slot_lookup and mm_slot_insert cannot be converted to static inline > + * functions because the hash helpers (hash_for_each_possible and hash_add) rely > + * 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; \ > -- > 2.25.1 ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 2/2] mm/mm_slot.h: add comments for mm_slot_lookup/insert 2026-07-14 1:28 ` [PATCH v3 2/2] mm/mm_slot.h: add comments for mm_slot_lookup/insert xu.xin16 2026-07-14 1:37 ` Barry Song 2026-07-14 9:35 ` Lorenzo Stoakes (ARM) @ 2026-07-14 9:44 ` Qi Zheng 2026-07-14 13:26 ` David Hildenbrand (Arm) 3 siblings, 0 replies; 7+ messages in thread From: Qi Zheng @ 2026-07-14 9:44 UTC (permalink / raw) To: xu.xin16, akpm, david, ljs, ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, npache, ryan.roberts, dev.jain Cc: linux-mm, linux-kernel, wang.yaxin On 7/14/26 9:28 AM, xu.xin16@zte.com.cn wrote: > From: xu xin <xu.xin16@zte.com.cn> > > mm_slot_lookup() and mm_slot_insert() are the only helpers in > this header that are implemented as macros rather than static inline > functions. This may look inconsistent without explanation. > > Explain they must be macros because hash_for_each_possible() > needs the table as an array (for sizeof), not a pointer. > > Signed-off-by: xu xin <xu.xin16@zte.com.cn> > --- > mm/mm_slot.h | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/mm/mm_slot.h b/mm/mm_slot.h > index 5de3e91d86b4..9b09b68e5742 100644 > --- a/mm/mm_slot.h > +++ b/mm/mm_slot.h > @@ -33,6 +33,12 @@ static inline void mm_slot_free(struct kmem_cache *cache, void *objp) > kmem_cache_free(cache, objp); > } > > +/* > + * Note: mm_slot_lookup and mm_slot_insert cannot be converted to static inline > + * functions because the hash helpers (hash_for_each_possible and hash_add) rely > + * on the actual array argument 'hashtable' for sizeof() instead of pointers. > + */ Right, that's why I wrote them as macros to begin with. Reviewed-by: Qi Zheng <qi.zheng@linux.dev> Thanks, Qi > + > #define mm_slot_lookup(_hashtable, _mm) \ > ({ \ > struct mm_slot *tmp_slot, *mm_slot = NULL; \ ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH v3 2/2] mm/mm_slot.h: add comments for mm_slot_lookup/insert 2026-07-14 1:28 ` [PATCH v3 2/2] mm/mm_slot.h: add comments for mm_slot_lookup/insert xu.xin16 ` (2 preceding siblings ...) 2026-07-14 9:44 ` Qi Zheng @ 2026-07-14 13:26 ` David Hildenbrand (Arm) 3 siblings, 0 replies; 7+ messages in thread From: David Hildenbrand (Arm) @ 2026-07-14 13:26 UTC (permalink / raw) To: xu.xin16, akpm, ljs, ziy, baolin.wang, baohua, lance.yang, usama.arif, chengming.zhou, qi.zheng, npache, ryan.roberts, dev.jain Cc: linux-mm, linux-kernel, wang.yaxin On 7/14/26 03:28, xu.xin16@zte.com.cn wrote: > From: xu xin <xu.xin16@zte.com.cn> > > mm_slot_lookup() and mm_slot_insert() are the only helpers in > this header that are implemented as macros rather than static inline > functions. This may look inconsistent without explanation. > > Explain they must be macros because hash_for_each_possible() > needs the table as an array (for sizeof), not a pointer. > > 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] 7+ messages in thread
end of thread, other threads:[~2026-07-14 13:26 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2026-07-14 1:24 [PATCH v3 0/2] Two small patches to clean up mm/mm_slot.h xu.xin16 2026-07-14 1:26 ` [PATCH v3 1/2] mm/mm_slot.h: add a helper function mm_slot_remove xu.xin16 2026-07-14 1:28 ` [PATCH v3 2/2] mm/mm_slot.h: add comments for mm_slot_lookup/insert xu.xin16 2026-07-14 1:37 ` Barry Song 2026-07-14 9:35 ` Lorenzo Stoakes (ARM) 2026-07-14 9:44 ` Qi Zheng 2026-07-14 13:26 ` David Hildenbrand (Arm)
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.