From nobody Sat Jul 25 20:47:29 2026 Received: from mxct.zte.com.cn (mxct.zte.com.cn [183.62.165.209]) (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 1EA4C35F602 for ; Tue, 14 Jul 2026 01:26:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=183.62.165.209 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783992397; cv=none; b=T7aMpN7fGZsUHOUMZRkTw9h5Er/stebcn3DI48MXwdSV452s299Et5ecvSZbTF/0v4S/ZRycrRuVEqL68B/BorvHXsGbFlFbOyyTscVWc08AXthdDadsVO3GanOruJ0Q9WtoruAr11hCpHsubsP63+e1Jg24Fqq+WJD+Emgdt1g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783992397; c=relaxed/simple; bh=Hj+BCSK+r/V03+iGK4XiM0dCeGqB0833cxWlWqAftis=; h=Message-ID:In-Reply-To:References:Date:Mime-Version:From:To:Cc: Subject:Content-Type; b=d5VWT8bMXnydmJHH68q2sO02+izCYpC63i9paToz5EP35NaJH+rtcePEwqojsyNirdVubHEi0mJck2/ivAA4mSugyeoV2e0JZo45V9b07Dl8N2NGza0d2UMx68kXViDJQ/Ju55cNGD49crm3prwyFrMNAEu9OODLByuFshfpvFk= 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=183.62.165.209 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-fl1.zte.com.cn (unknown [10.5.228.132]) (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 mxct.zte.com.cn (FangMail) with ESMTPS id 4gzhTv3MWlz57KTp; Tue, 14 Jul 2026 09:26:27 +0800 (CST) Received: from xaxapp02.zte.com.cn ([10.88.97.241]) by mse-fl1.zte.com.cn with SMTP id 66E1QLL9093958; Tue, 14 Jul 2026 09:26:21 +0800 (+08) (envelope-from xu.xin16@zte.com.cn) Received: from mapi (xaxapp02[null]) by mapi (Zmail) with MAPI id mid32; Tue, 14 Jul 2026 09:26:22 +0800 (CST) X-Zmail-TransId: 2afa6a55903ed48-9f808 X-Mailer: Zmail v1.0 Message-ID: <20260714092622583ayzGzGYSjAareKKHt_T91@zte.com.cn> In-Reply-To: <202607140924549782dUh3YBPmy8g1NDMK2zIW@zte.com.cn> References: 202607140924549782dUh3YBPmy8g1NDMK2zIW@zte.com.cn Date: Tue, 14 Jul 2026 09:26:22 +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?W1BBVENIIHYzIDEvMl0gbW0vbW1fc2xvdC5oOiBhZGQgYSBoZWxwZXIgZnVuY3Rpb24gbW1fc2xvdF9yZW1vdmU=?= X-MAIL: mse-fl1.zte.com.cn 66E1QLL9093958 X-TLS: YES X-ENVELOPE-SENDER: xu.xin16@zte.com.cn X-SOURCE-IP: 10.5.228.132 unknown Tue, 14 Jul 2026 09:26:27 +0800 X-CLEAN: YES X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6A559043.000/4gzhTv3MWlz57KTp Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: xu xin 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 Reviewed-by: Nico Pache Reviewed-by: Zi Yan Reviewed-by: Barry Song Acked-by: David Hildenbrand (Arm) Reviewed-by: Lorenzo Stoakes (ARM) Reviewed-by: SJ Park --- 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 =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..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 */ --=20 2.25.1 From nobody Sat Jul 25 20:47:29 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 9DC7335838E for ; Tue, 14 Jul 2026 01:28:22 +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=1783992504; cv=none; b=Dod/igpZu5gDouvsdS7+0qS2RVV84gCdrQbfOjtE/gtfZeNinm9r+mP5ueAx+d8dJS/7RsU79Ei9uGHcRlvOIx/E57ecf6IcH8cbJkU1PqfpoHvB5te6c5pVzz7nyoCvLEWrCvOQ7VGN+u4wZZOR5wI+75kAaDvPDaOnIn0XN8k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783992504; c=relaxed/simple; bh=h18XibCmkk6nNLk4B3HRP/68onXXbGPRRuQf4Bon7Q8=; h=Message-ID:In-Reply-To:References:Date:Mime-Version:From:To:Cc: Subject:Content-Type; b=mEBv0lupj/zR0CkSJIH/tw4maUn9E2289NtPeavjdFvBKY6Y+MQA0tm9mNgXo9NHbHMgM6CcxqBFVFQN305r9eRG6hAy6PL5LG7gvBdAoiKmC4CUI1In+lAvqnaHKJP6B1ns9yC342BqareptJ8AgYQABZIDxQqv4GXnyG+4m8g= 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-fl1.zte.com.cn (unknown [10.5.228.132]) (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 4gzhX51XLHz4yjjG; Tue, 14 Jul 2026 09:28:21 +0800 (CST) Received: from xaxapp02.zte.com.cn ([10.88.97.241]) by mse-fl1.zte.com.cn with SMTP id 66E1SEBN096313; Tue, 14 Jul 2026 09:28:14 +0800 (+08) (envelope-from xu.xin16@zte.com.cn) Received: from mapi (xaxapp01[null]) by mapi (Zmail) with MAPI id mid32; Tue, 14 Jul 2026 09:28:15 +0800 (CST) X-Zmail-TransId: 2af96a5590afcc4-a677d X-Mailer: Zmail v1.0 Message-ID: <20260714092815120Wv-CFDlLKtsTmda--97Qw@zte.com.cn> In-Reply-To: <202607140924549782dUh3YBPmy8g1NDMK2zIW@zte.com.cn> References: 202607140924549782dUh3YBPmy8g1NDMK2zIW@zte.com.cn Date: Tue, 14 Jul 2026 09:28:15 +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?W1BBVENIIHYzIDIvMl0gbW0vbW1fc2xvdC5oOiBhZGQgY29tbWVudHMgZm9yIG1tX3Nsb3RfbG9va3VwL2luc2VydA==?= X-MAIL: mse-fl1.zte.com.cn 66E1SEBN096313 X-TLS: YES X-ENVELOPE-SENDER: xu.xin16@zte.com.cn X-SOURCE-IP: 10.5.228.132 unknown Tue, 14 Jul 2026 09:28:21 +0800 X-CLEAN: YES X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6A5590B5.000/4gzhX51XLHz4yjjG Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: xu xin 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 Acked-by: David Hildenbrand (Arm) Reviewed-by: Barry Song Reviewed-by: Lorenzo Stoakes (ARM) Reviewed-by: Qi Zheng Reviewed-by: SJ Park Reviewed-by: Zi Yan --- 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 i= nline + * functions because the hash helpers (hash_for_each_possible and hash_add= ) rely + * on the actual array argument 'hashtable' for sizeof() instead of pointe= rs. + */ + #define mm_slot_lookup(_hashtable, _mm) \ ({ \ struct mm_slot *tmp_slot, *mm_slot =3D NULL; \ --=20 2.25.1