lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Wed, 08 May 2024 19:35:42 +0800
From: Chengming Zhou <chengming.zhou@...ux.dev>
To: Andrew Morton <akpm@...ux-foundation.org>, 
 David Hildenbrand <david@...hat.com>, 
 Andrea Arcangeli <aarcange@...hat.com>, Stefan Roesch <shr@...kernel.io>, 
 Hugh Dickins <hughd@...gle.com>
Cc: linux-mm@...ck.org, linux-kernel@...r.kernel.org, 
 zhouchengming@...edance.com, Chengming Zhou <chengming.zhou@...ux.dev>
Subject: [PATCH 2/2] mm/ksm: flush out migrated rmap_item to insert our
 rmap_item

From: Chengming Zhou <zhouchengming@...edance.com>

If tree_page has been migrated to another NUMA node and across_nodes
disabled, flush it out immediately and it will be put in the right
unstable tree when next time.

The good point is that we can retry to insert our rmap_item successfully
to increase the merge possibility, and we don't need to bother to
memcmp_pages() in this case.

Signed-off-by: Chengming Zhou <zhouchengming@...edance.com>
---
 mm/ksm.c | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/mm/ksm.c b/mm/ksm.c
index 66219983eb3a..b840fb55e1f4 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -2226,6 +2226,18 @@ struct ksm_rmap_item *unstable_tree_search_insert(struct ksm_rmap_item *rmap_ite
 			return NULL;
 		}
 
+		/*
+		 * If tree_page has been migrated to another NUMA node and
+		 * across_nodes disabled, flush it out here and it will be
+		 * put in the right unstable tree next time. So we can retry
+		 * to insert our rmap_item successfully.
+		 */
+		if (!ksm_merge_across_nodes &&
+		    page_to_nid(tree_page) != nid) {
+			remove_rmap_item_from_tree(tree_rmap_item);
+			goto again;
+		}
+
 		ret = memcmp_pages(page, tree_page);
 
 		parent = *new;
@@ -2235,15 +2247,6 @@ struct ksm_rmap_item *unstable_tree_search_insert(struct ksm_rmap_item *rmap_ite
 		} else if (ret > 0) {
 			put_page(tree_page);
 			new = &parent->rb_right;
-		} else if (!ksm_merge_across_nodes &&
-			   page_to_nid(tree_page) != nid) {
-			/*
-			 * If tree_page has been migrated to another NUMA node,
-			 * it will be flushed out and put in the right unstable
-			 * tree next time: only merge with it when across_nodes.
-			 */
-			put_page(tree_page);
-			return NULL;
 		} else {
 			*tree_pagep = tree_page;
 			return tree_rmap_item;

-- 
2.45.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ