From: Chengming Zhou <chengming.zhou@linux.dev>
To: Andrew Morton <akpm@linux-foundation.org>,
David Hildenbrand <david@redhat.com>,
Andrea Arcangeli <aarcange@redhat.com>,
Stefan Roesch <shr@devkernel.io>,
Hugh Dickins <hughd@google.com>
Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org,
zhouchengming@bytedance.com,
Chengming Zhou <chengming.zhou@linux.dev>
Subject: [PATCH 1/2] mm/ksm: re-search unstable tree when tree_rmap_item is stale
Date: Wed, 08 May 2024 19:35:41 +0800 [thread overview]
Message-ID: <20240508-b4-ksm-unstable-insert-v1-1-631cdbc2b77f@linux.dev> (raw)
In-Reply-To: <20240508-b4-ksm-unstable-insert-v1-0-631cdbc2b77f@linux.dev>
From: Chengming Zhou <zhouchengming@bytedance.com>
Now unstable_tree_search_insert() will return NULL if encounter a stale
tree_rmap_item, in which case get_mergeable_page() return NULL.
More reasonable handling is to remove stale rmap_item out of unstable
tree and re-search from root. That stale rmap_item will be reclaimed
when next time of scan.
So we can insert our rmap_item successfully instead of returning NULL.
Signed-off-by: Chengming Zhou <zhouchengming@bytedance.com>
---
mm/ksm.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/mm/ksm.c b/mm/ksm.c
index e1034bf1c937..66219983eb3a 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -2196,12 +2196,14 @@ struct ksm_rmap_item *unstable_tree_search_insert(struct ksm_rmap_item *rmap_ite
{
struct rb_node **new;
struct rb_root *root;
- struct rb_node *parent = NULL;
+ struct rb_node *parent;
int nid;
nid = get_kpfn_nid(page_to_pfn(page));
root = root_unstable_tree + nid;
+again:
new = &root->rb_node;
+ parent = NULL;
while (*new) {
struct ksm_rmap_item *tree_rmap_item;
@@ -2211,8 +2213,10 @@ struct ksm_rmap_item *unstable_tree_search_insert(struct ksm_rmap_item *rmap_ite
cond_resched();
tree_rmap_item = rb_entry(*new, struct ksm_rmap_item, node);
tree_page = get_mergeable_page(tree_rmap_item);
- if (!tree_page)
- return NULL;
+ if (!tree_page) {
+ remove_rmap_item_from_tree(tree_rmap_item);
+ goto again;
+ }
/*
* Don't substitute a ksm page for a forked page.
--
2.45.0
next prev parent reply other threads:[~2024-05-08 11:37 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-08 11:35 [PATCH 0/2] mm/ksm: optimize unstable_tree_search_insert() Chengming Zhou
2024-05-08 11:35 ` Chengming Zhou [this message]
2024-05-08 11:35 ` [PATCH 2/2] mm/ksm: flush out migrated rmap_item to insert our rmap_item Chengming Zhou
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=20240508-b4-ksm-unstable-insert-v1-1-631cdbc2b77f@linux.dev \
--to=chengming.zhou@linux.dev \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=david@redhat.com \
--cc=hughd@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=shr@devkernel.io \
--cc=zhouchengming@bytedance.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