From: <xu.xin16@zte.com.cn>
To: <akpm@linux-foundation.org>, <david@kernel.org>, <ljs@kernel.org>
Cc: <akpm@linux-foundation.org>, <david@kernel.org>, <ljs@kernel.org>,
<ziy@nvidia.com>, <baolin.wang@linux.alibaba.com>,
<baohua@kernel.org>, <lance.yang@linux.dev>,
<usama.arif@linux.dev>, <chengming.zhou@linux.dev>,
<qi.zheng@linux.dev>, <linux-mm@kvack.org>,
<linux-kernel@vger.kernel.org>, <npache@redhat.com>,
<ryan.roberts@arm.com>, <dev.jain@arm.com>,
<wang.yaxin@zte.com.cn>, <xu.xin16@zte.com.cn>
Subject: [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove
Date: Mon, 13 Jul 2026 14:37:07 +0800 (CST) [thread overview]
Message-ID: <20260713143707966lCkTinO0i9zYAc1K2ZmqZ@zte.com.cn> (raw)
In-Reply-To: <20260713143534964Cml5-QLfcPMDtbbq_j7tG@zte.com.cn>
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
next prev parent reply other threads:[~2026-07-13 6:37 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2026-07-13 11:48 ` [PATCH v2 1/2] mm/mm_slot.h: add a helper function mm_slot_remove 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260713143707966lCkTinO0i9zYAc1K2ZmqZ@zte.com.cn \
--to=xu.xin16@zte.com.cn \
--cc=akpm@linux-foundation.org \
--cc=baohua@kernel.org \
--cc=baolin.wang@linux.alibaba.com \
--cc=chengming.zhou@linux.dev \
--cc=david@kernel.org \
--cc=dev.jain@arm.com \
--cc=lance.yang@linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=npache@redhat.com \
--cc=qi.zheng@linux.dev \
--cc=ryan.roberts@arm.com \
--cc=usama.arif@linux.dev \
--cc=wang.yaxin@zte.com.cn \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox