From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
linux-mm@kvack.org, Alex Shi <alexs@kernel.org>
Subject: [PATCH 2/5] ksm: Convert cmp_and_merge_page() to use a folio
Date: Wed, 2 Oct 2024 16:25:28 +0100 [thread overview]
Message-ID: <20241002152533.1350629-3-willy@infradead.org> (raw)
In-Reply-To: <20241002152533.1350629-1-willy@infradead.org>
By making try_to_merge_two_pages() and stable_tree_search() return a
folio, we can replace kpage with kfolio. This replaces 7 calls to
compound_head() with one.
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
---
mm/ksm.c | 48 ++++++++++++++++++++++++------------------------
1 file changed, 24 insertions(+), 24 deletions(-)
diff --git a/mm/ksm.c b/mm/ksm.c
index 57f998b172e6..19e17b228ae1 100644
--- a/mm/ksm.c
+++ b/mm/ksm.c
@@ -1583,7 +1583,7 @@ static int try_to_merge_with_ksm_page(struct ksm_rmap_item *rmap_item,
* Note that this function upgrades page to ksm page: if one of the pages
* is already a ksm page, try_to_merge_with_ksm_page should be used.
*/
-static struct page *try_to_merge_two_pages(struct ksm_rmap_item *rmap_item,
+static struct folio *try_to_merge_two_pages(struct ksm_rmap_item *rmap_item,
struct page *page,
struct ksm_rmap_item *tree_rmap_item,
struct page *tree_page)
@@ -1601,7 +1601,7 @@ static struct page *try_to_merge_two_pages(struct ksm_rmap_item *rmap_item,
if (err)
break_cow(rmap_item);
}
- return err ? NULL : page;
+ return err ? NULL : page_folio(page);
}
static __always_inline
@@ -1790,7 +1790,7 @@ static __always_inline struct folio *chain(struct ksm_stable_node **s_n_d,
* This function returns the stable tree node of identical content if found,
* NULL otherwise.
*/
-static struct page *stable_tree_search(struct page *page)
+static struct folio *stable_tree_search(struct page *page)
{
int nid;
struct rb_root *root;
@@ -1805,7 +1805,7 @@ static struct page *stable_tree_search(struct page *page)
if (page_node && page_node->head != &migrate_nodes) {
/* ksm page forked */
folio_get(folio);
- return &folio->page;
+ return folio;
}
nid = get_kpfn_nid(folio_pfn(folio));
@@ -1900,7 +1900,7 @@ static struct page *stable_tree_search(struct page *page)
folio_put(tree_folio);
goto replace;
}
- return &tree_folio->page;
+ return tree_folio;
}
}
@@ -1914,7 +1914,7 @@ static struct page *stable_tree_search(struct page *page)
out:
if (is_page_sharing_candidate(page_node)) {
folio_get(folio);
- return &folio->page;
+ return folio;
} else
return NULL;
@@ -1964,7 +1964,7 @@ static struct page *stable_tree_search(struct page *page)
}
stable_node_dup->head = &migrate_nodes;
list_add(&stable_node_dup->list, stable_node_dup->head);
- return &folio->page;
+ return folio;
chain_append:
/*
@@ -2218,7 +2218,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite
struct ksm_rmap_item *tree_rmap_item;
struct page *tree_page = NULL;
struct ksm_stable_node *stable_node;
- struct page *kpage;
+ struct folio *kfolio;
unsigned int checksum;
int err;
bool max_page_sharing_bypass = false;
@@ -2260,31 +2260,31 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite
return;
}
- /* We first start with searching the page inside the stable tree */
- kpage = stable_tree_search(page);
- if (kpage == page && rmap_item->head == stable_node) {
- put_page(kpage);
+ /* Start by searching for the folio in the stable tree */
+ kfolio = stable_tree_search(page);
+ if (&kfolio->page == page && rmap_item->head == stable_node) {
+ folio_put(kfolio);
return;
}
remove_rmap_item_from_tree(rmap_item);
- if (kpage) {
- if (PTR_ERR(kpage) == -EBUSY)
+ if (kfolio) {
+ if (kfolio == ERR_PTR(-EBUSY))
return;
- err = try_to_merge_with_ksm_page(rmap_item, page, kpage);
+ err = try_to_merge_with_ksm_page(rmap_item, page, &kfolio->page);
if (!err) {
/*
* The page was successfully merged:
* add its rmap_item to the stable tree.
*/
- lock_page(kpage);
- stable_tree_append(rmap_item, page_stable_node(kpage),
+ folio_lock(kfolio);
+ stable_tree_append(rmap_item, folio_stable_node(kfolio),
max_page_sharing_bypass);
- unlock_page(kpage);
+ folio_unlock(kfolio);
}
- put_page(kpage);
+ folio_put(kfolio);
return;
}
@@ -2293,7 +2293,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite
if (tree_rmap_item) {
bool split;
- kpage = try_to_merge_two_pages(rmap_item, page,
+ kfolio = try_to_merge_two_pages(rmap_item, page,
tree_rmap_item, tree_page);
/*
* If both pages we tried to merge belong to the same compound
@@ -2308,20 +2308,20 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite
split = PageTransCompound(page)
&& compound_head(page) == compound_head(tree_page);
put_page(tree_page);
- if (kpage) {
+ if (kfolio) {
/*
* The pages were successfully merged: insert new
* node in the stable tree and add both rmap_items.
*/
- lock_page(kpage);
- stable_node = stable_tree_insert(page_folio(kpage));
+ folio_lock(kfolio);
+ stable_node = stable_tree_insert(kfolio);
if (stable_node) {
stable_tree_append(tree_rmap_item, stable_node,
false);
stable_tree_append(rmap_item, stable_node,
false);
}
- unlock_page(kpage);
+ folio_unlock(kfolio);
/*
* If we fail to insert the page into the stable tree,
--
2.43.0
next prev parent reply other threads:[~2024-10-02 15:25 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-02 15:25 [PATCH 0/5] Remove PageKsm() Matthew Wilcox (Oracle)
2024-10-02 15:25 ` [PATCH 1/5] ksm: Use a folio in try_to_merge_one_page() Matthew Wilcox (Oracle)
2024-10-07 9:43 ` David Hildenbrand
2024-10-02 15:25 ` Matthew Wilcox (Oracle) [this message]
2024-10-07 9:44 ` [PATCH 2/5] ksm: Convert cmp_and_merge_page() to use a folio David Hildenbrand
2024-10-02 15:25 ` [PATCH 3/5] ksm: Convert should_skip_rmap_item() to take " Matthew Wilcox (Oracle)
2024-10-07 9:46 ` David Hildenbrand
2024-10-02 15:25 ` [PATCH 4/5] mm: Add PageAnonNotKsm() Matthew Wilcox (Oracle)
[not found] ` <CGME20241004114615eucas1p1910b6b4e74f8a878f56104026eece731@eucas1p1.samsung.com>
2024-10-04 11:46 ` Marek Szyprowski
2024-10-06 14:11 ` kernel test robot
2024-10-07 9:46 ` David Hildenbrand
2024-10-02 15:25 ` [PATCH 5/5] mm: Remove PageKsm() Matthew Wilcox (Oracle)
2024-10-07 9:47 ` 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=20241002152533.1350629-3-willy@infradead.org \
--to=willy@infradead.org \
--cc=akpm@linux-foundation.org \
--cc=alexs@kernel.org \
--cc=linux-mm@kvack.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;
as well as URLs for NNTP newsgroup(s).