From nobody Sat Jul 25 21:59:23 2026 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [160.30.148.35]) (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 2947F380FF5 for ; Mon, 13 Jul 2026 06:37:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=160.30.148.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783924641; cv=none; b=p2aVbFyLn+fIBaLadkbsO6bVL32kOWQ+ak0DbVxc9ruChpzNNyWmaYLs3bkkZ+F6kvntWTpEl+Fyk4p6nimu1duE1ApTbIpuewYhQ8+LPoZXrXIfCDte6UCIvnw+1QJoCjZYQTi1zRjWFCSTcySOIMG8vDO1c0K2x/vO5OjmOcI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783924641; c=relaxed/simple; bh=xuLO3hER1nJhzhsFxowNAWCZV1GG7gC18zZ+skpI0AY=; h=Message-ID:In-Reply-To:References:Date:Mime-Version:From:To:Cc: Subject:Content-Type; b=Xz8WCJg3NguNF1HO9kckBmZwZ8KHAhCQ14A81xeRaqleoY+Ig6UMlAs2ROAeHWZMzAj/j/xIMabBNGIC0SviPLEmN9FCfTDBDhkjJxZZGNdFB4s61YEUgVWh/ZfjZEopB0hunrrrU6XScs+NdZapdz0uyQcaonbYYLkd4zqZZmo= 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.35 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 4gzCR12mYzz8Xrrd; Mon, 13 Jul 2026 14:37:17 +0800 (CST) Received: from xaxapp04.zte.com.cn ([10.99.98.157]) by mse-fl2.zte.com.cn with SMTP id 66D6b6Sd028040; Mon, 13 Jul 2026 14:37:06 +0800 (+08) (envelope-from xu.xin16@zte.com.cn) Received: from mapi (xaxapp02[null]) by mapi (Zmail) with MAPI id mid32; Mon, 13 Jul 2026 14:37:07 +0800 (CST) X-Zmail-TransId: 2afa6a5487932ca-652bf X-Mailer: Zmail v1.0 Message-ID: <20260713143707966lCkTinO0i9zYAc1K2ZmqZ@zte.com.cn> In-Reply-To: <20260713143534964Cml5-QLfcPMDtbbq_j7tG@zte.com.cn> References: 20260713143534964Cml5-QLfcPMDtbbq_j7tG@zte.com.cn Date: Mon, 13 Jul 2026 14:37:07 +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?W1BBVENIIHYyIDEvMl0gbW0vbW1fc2xvdC5oOiBhZGQgYSBoZWxwZXIgZnVuY3Rpb24gbW1fc2xvdF9yZW1vdmU=?= X-MAIL: mse-fl2.zte.com.cn 66D6b6Sd028040 X-TLS: YES X-ENVELOPE-SENDER: xu.xin16@zte.com.cn X-SOURCE-IP: 10.5.228.133 unknown Mon, 13 Jul 2026 14:37:17 +0800 X-CLEAN: YES X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6A54879D.000/4gzCR12mYzz8Xrrd 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 Acked-by: David Hildenbrand (Arm) Reviewed-by: Barry Song Reviewed-by: Lorenzo Stoakes (ARM) Reviewed-by: Nico Pache Reviewed-by: SJ Park Reviewed-by: Zi Yan --- 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 21:59:23 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 34B9C384CCD for ; Mon, 13 Jul 2026 06:42:03 +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=1783924925; cv=none; b=NB0jO9TM7k4/URQN9eQK4DqTuOk5BTef6HsVy4y73iMHkypdYfA0JrSrgD9iOcWvNf61pKaW3piUy8mNeFY/jornHoCsWmCnu7oC06EuYgjQQ8jLqLP5JRG3Lc9JbFZQbc2R0IUEP7xoUsJoJBuDDhudgrVdSXqXnM2rURXAUG0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783924925; c=relaxed/simple; bh=8R9gE9FKSDOUgkN5cYLxbc/URxpYAea1aZYo8xyAWRA=; h=Message-ID:In-Reply-To:References:Date:Mime-Version:From:To:Cc: Subject:Content-Type; b=izBtQHonr3jq9NrtNrMITVcfgHfG662ffo0u6iLV1APJx7wX04AVyGU386y159jl080xc+9QVa8cV0O92vzMymle90TWgM8VHjTYwRSD2N1dCKGu9H4CAlSEAHFpiBJ2VlsHhaPL1Hox7i49fAmhzabIkX7SS1Hg8Nj3ci8puvQ= 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 4gzCXT5GDhz57DCs; Mon, 13 Jul 2026 14:42:01 +0800 (CST) Received: from xaxapp02.zte.com.cn ([10.88.97.241]) by mse-fl2.zte.com.cn with SMTP id 66D6fpuE035154; Mon, 13 Jul 2026 14:41:51 +0800 (+08) (envelope-from xu.xin16@zte.com.cn) Received: from mapi (xaxapp04[null]) by mapi (Zmail) with MAPI id mid32; Mon, 13 Jul 2026 14:41:53 +0800 (CST) X-Zmail-TransId: 2afb6a5488b1c0b-5ec07 X-Mailer: Zmail v1.0 Message-ID: <20260713144153556amKkr4s-dWoQu5-ziCfZe@zte.com.cn> In-Reply-To: <20260713143534964Cml5-QLfcPMDtbbq_j7tG@zte.com.cn> References: 20260713143534964Cml5-QLfcPMDtbbq_j7tG@zte.com.cn Date: Mon, 13 Jul 2026 14:41:53 +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?W1BBVENIIHYyIDIvMl0gbW0vbW1fc2xvdC5oOiBjbGVhbiB1cCBtYWNybyBwYXJhbWV0ZXIgbmFtZXMgaW4gbW1fc2xvdF9sb29rdXAoKSBhbmQgbW1fc2xvdF9pbnNlcnQoKQ==?= X-MAIL: mse-fl2.zte.com.cn 66D6fpuE035154 X-TLS: YES X-ENVELOPE-SENDER: xu.xin16@zte.com.cn X-SOURCE-IP: 10.5.228.133 unknown Mon, 13 Jul 2026 14:42:01 +0800 X-CLEAN: YES X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6A5488B9.001/4gzCXT5GDhz57DCs Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: xu xin Suggested-by: Lorenzo Stoakes Signed-off-by: xu xin --- 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 *cach= e, 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 i= nline + * functions because hash_for_each_possible relys on the actual array argu= ment + * 'hashtable' for sizeof() instead of pointers. + */ +#define mm_slot_lookup(hashtable, mm) \ ({ \ struct mm_slot *tmp_slot, *mm_slot =3D NULL; \ \ - hash_for_each_possible(_hashtable, tmp_slot, hash, (unsigned long)_mm) \ - if (_mm =3D=3D tmp_slot->mm) { \ + hash_for_each_possible(hashtable, tmp_slot, hash, (unsigned long)mm) \ + if (mm =3D=3D tmp_slot->mm) { \ mm_slot =3D tmp_slot; \ break; \ } \ @@ -46,10 +51,10 @@ static inline void mm_slot_free(struct kmem_cache *cach= e, void *objp) mm_slot; \ }) -#define mm_slot_insert(_hashtable, _mm, _mm_slot) \ +#define mm_slot_insert(hashtable, mm, mm_slot) \ ({ \ - _mm_slot->mm =3D _mm; \ - hash_add(_hashtable, &_mm_slot->hash, (unsigned long)_mm); \ + mm_slot->mm =3D mm; \ + hash_add(hashtable, &mm_slot->hash, (unsigned long)mm); \ }) static inline void mm_slot_remove(struct mm_slot *slot) --=20 2.25.1 From nobody Sat Jul 25 21:59:23 2026 Received: from mxhk.zte.com.cn (mxhk.zte.com.cn [160.30.148.35]) (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 8029E382397 for ; Mon, 13 Jul 2026 06:39:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=160.30.148.35 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783924742; cv=none; b=mAGEMpZYTXxcNEULs0smkUZ4lO0xD0U1lCs4+HIyQGPNXBKPnri5iLfmfaeM3rxoQR2KEw1K+Vc9Jx9MCIIrAOsIejcBlY5zVJzE0Qsmv+dko03RE+5eldAoVGtOUIWx/I2LlgM3+aq8Y+HmAbqV/yVY6jrTjMn9hYd+ZKqFXvA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783924742; c=relaxed/simple; bh=cvXnCjj0ige6H3TUyZnd83JxwcE9dRVY941lfwlmmNI=; h=Message-ID:In-Reply-To:References:Date:Mime-Version:From:To:Cc: Subject:Content-Type; b=iRnw7m8ZCN2A4QvSeqY9UDghpoK8KbDHd5M4h6DmpGj2AE6HG9kD847qCHsgj4pRyz1NKr7YxgQUmkHO6SnVkh2x7B2kxOucR7UMS35dvmOUID10f+0aUWAqjo4sP7deFZWxV2F/SBVXMllIyAAO8lTwfqQCu0wttIiqsjG2FJ0= 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.35 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 4gzCSz1KsXz8Xrrb; Mon, 13 Jul 2026 14:38:59 +0800 (CST) Received: from xaxapp01.zte.com.cn ([10.88.99.176]) by mse-fl2.zte.com.cn with SMTP id 66D6crWj030739; Mon, 13 Jul 2026 14:38:53 +0800 (+08) (envelope-from xu.xin16@zte.com.cn) Received: from mapi (xaxapp02[null]) by mapi (Zmail) with MAPI id mid32; Mon, 13 Jul 2026 14:38:54 +0800 (CST) X-Zmail-TransId: 2afa6a5487fe820-68812 X-Mailer: Zmail v1.0 Message-ID: <20260713143854774IDQ756lKhFqhw7CX1qaXc@zte.com.cn> In-Reply-To: <20260713143534964Cml5-QLfcPMDtbbq_j7tG@zte.com.cn> References: 20260713143534964Cml5-QLfcPMDtbbq_j7tG@zte.com.cn Date: Mon, 13 Jul 2026 14:38:54 +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?bW0vbW1fc2xvdC5oOiBjbGVhbiB1cCBtYWNybyBwYXJhbWV0ZXIgbmFtZXMgaW4gbW1fc2xvdF9sb29rdXAoKSBhbmQgbW1fc2xvdF9pbnNlcnQoKQ==?= X-MAIL: mse-fl2.zte.com.cn 66D6crWj030739 X-TLS: YES X-ENVELOPE-SENDER: xu.xin16@zte.com.cn X-SOURCE-IP: 10.5.228.133 unknown Mon, 13 Jul 2026 14:38:59 +0800 X-CLEAN: YES X-Fangmail-Anti-Spam-Filtered: true X-Fangmail-MID-QID: 6A548803.000/4gzCSz1KsXz8Xrrb Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: xu xin Clean up the names by replacing _foo with foo, and document why they cannot be static inline. Suggested-by: Lorenzo Stoakes Signed-off-by: xu xin --- 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 *cach= e, 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 i= nline + * functions because hash_for_each_possible relys on the actual array argu= ment + * 'hashtable' for sizeof() instead of pointers. + */ +#define mm_slot_lookup(hashtable, mm) \ ({ \ struct mm_slot *tmp_slot, *mm_slot =3D NULL; \ \ - hash_for_each_possible(_hashtable, tmp_slot, hash, (unsigned long)_mm) \ - if (_mm =3D=3D tmp_slot->mm) { \ + hash_for_each_possible(hashtable, tmp_slot, hash, (unsigned long)mm) \ + if (mm =3D=3D tmp_slot->mm) { \ mm_slot =3D tmp_slot; \ break; \ } \ @@ -46,10 +51,10 @@ static inline void mm_slot_free(struct kmem_cache *cach= e, void *objp) mm_slot; \ }) -#define mm_slot_insert(_hashtable, _mm, _mm_slot) \ +#define mm_slot_insert(hashtable, mm, mm_slot) \ ({ \ - _mm_slot->mm =3D _mm; \ - hash_add(_hashtable, &_mm_slot->hash, (unsigned long)_mm); \ + mm_slot->mm =3D mm; \ + hash_add(hashtable, &mm_slot->hash, (unsigned long)mm); \ }) static inline void mm_slot_remove(struct mm_slot *slot) --=20 2.25.1