From nobody Sun Jul 26 01:50:07 2026 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [160.30.148.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EA6511F4634 for ; Fri, 10 Jul 2026 05:15:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=160.30.148.34 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783660552; cv=none; b=F8IQ29FWdS3AOlAGa/7xl5rNnkKTnn8uLeV4DmmWLzsnuOj9xtIniiimRp8Jyf+ST+PoEPDypAJGqInSkRoxpq6cbPAdp1dVLYvZF5whlIxN4db+5HqP7J3a8lh6MfyN/9T8p8RNAomYHvU+M1xUKDDqy0Vgy0aq027rSY/ovNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783660552; c=relaxed/simple; bh=0s54vjiFZF50FnNHoiD5xpQmcQB0NQVjyTl9PnLJeDA=; h=Message-ID:Date:Mime-Version:From:To:Cc:Subject:Content-Type; b=F8Ay2u94dbiv7Wo3qjhdAsY6V8n2g7yBfbkqIc+QOPxmwHHpVaMyzWq64OsjPxIKogmpELhp+UcMos/QfFAe1F1ka/ss6WoI18gYYrZmwouR/8Cv4Oxi17f5uCmdxmDn+DCUV34QH/ILTuMlXP+L5CnRXEMc+EI+3a410Bc77YA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn; spf=pass smtp.mailfrom=zte.com.cn; arc=none smtp.client-ip=160.30.148.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=zte.com.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=zte.com.cn Received: from mse-fl2.zte.com.cn (unknown [10.5.228.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mxhk.zte.com.cn (FangMail) with ESMTPS id 4gxKmF3clWz5B13Y; Fri, 10 Jul 2026 13:15:41 +0800 (CST) Received: from xaxapp05.zte.com.cn ([10.99.98.109]) by mse-fl2.zte.com.cn with SMTP id 66A5Faux005801; Fri, 10 Jul 2026 13:15:36 +0800 (+08) (envelope-from xu.xin16@zte.com.cn) Received: from mapi (xaxapp05[null]) by mapi (Zmail) with MAPI id mid32; Fri, 10 Jul 2026 13:15:36 +0800 (CST) X-Zmail-TransId: 2afc6a507ff89bb-a3a62 X-Mailer: Zmail v1.0 Message-ID: <20260710131536564mY9CDv7aP2dKPiLFXbrBv@zte.com.cn> Date: Fri, 10 Jul 2026 13:15:36 +0800 (CST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 From: To: , , Cc: , , , , , , , , , , , , , Subject: =?UTF-8?B?W1BBVENIXSBtbS9tbV9zbG90Lmg6IGFkZCBhIGhlbHBlciBmdW5jdGlvbiBtbV9zbG90X3JlbW92ZQ==?= Content-Type: text/plain; charset="utf-8" X-MAIL: mse-fl2.zte.com.cn 66A5Faux005801 X-TLS: YES X-ENVELOPE-SENDER: xu.xin16@zte.com.cn X-SOURCE-IP: 10.5.228.133 unknown Fri, 10 Jul 2026 13:15:41 +0800 X-CLEAN: YES X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6A507FFD.000/4gxKmF3clWz5B13Y Content-Transfer-Encoding: quoted-printable From 69923b1aa7d702eeea7364a95d7b05ae82ebd3e0 Mon Sep 17 00:00:00 2001 From: xu xin Date: Fri, 10 Jul 2026 12:29:57 +0800 Subject: [PATCH] mm/mm_slot.h: add a helper function mm_slot_remove 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=E2=80=91step removal is open=E2=80=91coded in multiple = places 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. No functional change is intended. Signed-off-by: xu xin --- mm/khugepaged.c | 6 ++---- mm/ksm.c | 9 +++------ mm/mm_slot.h | 7 +++++++ 3 files changed, 12 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 =3D mm_slot_lookup(mm_slots_hash, mm); if (slot && khugepaged_scan.mm_slot !=3D slot) { - hash_del(&slot->hash); - list_del(&slot->mm_node); + mm_slot_remove(slot); free =3D 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 =3D 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 =3D=3D 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 =3D 1; } else { list_move(&slot->mm_node, 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); \ }) +static inline void mm_slot_remove(struct mm_slot *_mm_slot) +{ + hash_del(&_mm_slot->hash); + list_del(&_mm_slot->mm_node); +} + + #endif /* _LINUX_MM_SLOT_H */ --=20 2.25.1