From: alexs@kernel.org
To: Andrew Morton <akpm@linux-foundation.org>,
linux-mm@kvack.org, linux-kernel@vger.kernel.org,
izik.eidus@ravellosystems.com, willy@infradead.org,
aarcange@redhat.com, chrisw@sous-sol.org, hughd@google.com,
david@redhat.com
Cc: "Alex Shi (tencent)" <alexs@kernel.org>
Subject: [RFC 2/3] mm/ksm: jump out early if vma out of date in cmp_and_merge_page
Date: Wed, 5 Jun 2024 17:53:02 +0800 [thread overview]
Message-ID: <20240605095304.66389-2-alexs@kernel.org> (raw)
In-Reply-To: <20240605095304.66389-1-alexs@kernel.org>
From: "Alex Shi (tencent)" <alexs@kernel.org>
If we get a page which in a disappearing vma, the page should be useless
soon, so don't bother to add it into ksm.
Signed-off-by: Alex Shi (tencent) <alexs@kernel.org>
---
mm/ksm.c | 36 +++++++++++++++++-------------------
1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/mm/ksm.c b/mm/ksm.c
index 088bce39cd33..ef335ee508d3 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -2315,6 +2315,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite
unsigned int checksum;
int err;
bool max_page_sharing_bypass = false;
+ struct vm_area_struct *vma;
stable_node = page_stable_node(page);
if (stable_node) {
@@ -2370,9 +2371,17 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite
* don't want to insert it in the unstable tree, and we don't want
* to waste our time searching for something identical to it there.
*/
+ mmap_read_lock(mm);
+ vma = find_mergeable_vma(mm, rmap_item->address);
+ if (!vma) {
+ /* If the vma is out of date, we do not need to continue.*/
+ mmap_read_unlock(mm);
+ return;
+ }
checksum = calc_checksum(page);
if (rmap_item->oldchecksum != checksum) {
rmap_item->oldchecksum = checksum;
+ mmap_read_unlock(mm);
return;
}
@@ -2381,31 +2390,20 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite
* appropriate zero page if the user enabled this via sysfs.
*/
if (ksm_use_zero_pages && (checksum == zero_checksum)) {
- struct vm_area_struct *vma;
-
- mmap_read_lock(mm);
- vma = find_mergeable_vma(mm, rmap_item->address);
- if (vma) {
- err = try_to_merge_one_page(vma, page,
- ZERO_PAGE(rmap_item->address));
- trace_ksm_merge_one_page(
- page_to_pfn(ZERO_PAGE(rmap_item->address)),
- rmap_item, mm, err);
- } else {
- /*
- * If the vma is out of date, we do not need to
- * continue.
- */
- err = 0;
- }
- mmap_read_unlock(mm);
+ err = try_to_merge_one_page(vma, page, ZERO_PAGE(rmap_item->address));
+ trace_ksm_merge_one_page(page_to_pfn(ZERO_PAGE(rmap_item->address)),
+ rmap_item, mm, err);
/*
* In case of failure, the page was not really empty, so we
* need to continue. Otherwise we're done.
*/
- if (!err)
+ if (!err) {
+ mmap_read_unlock(mm);
return;
+ }
}
+ mmap_read_unlock(mm);
+
tree_rmap_item =
unstable_tree_search_insert(rmap_item, page, &tree_page);
if (tree_rmap_item) {
--
2.43.0
next prev parent reply other threads:[~2024-06-05 9:48 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-05 9:53 [RFC 1/3] mm/ksm: add anonymous check in find_mergeable_vma alexs
2024-06-05 9:53 ` alexs [this message]
2024-06-05 9:53 ` [RFC 3/3] mm/ksm: move flush_anon_page before checksum calculation alexs
2024-06-05 10:04 ` Alex Shi
[not found] ` <353d4f6c-ed3d-4afe-82ab-8c0b22a0178f@redhat.com>
2024-06-07 9:33 ` [RFC 1/3] mm/ksm: add anonymous check in find_mergeable_vma Alex Shi
2024-06-07 10:13 ` David Hildenbrand
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=20240605095304.66389-2-alexs@kernel.org \
--to=alexs@kernel.org \
--cc=aarcange@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=chrisw@sous-sol.org \
--cc=david@redhat.com \
--cc=hughd@google.com \
--cc=izik.eidus@ravellosystems.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=willy@infradead.org \
/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