* [PATCH 1/1] mm/ksm: remove page_stable_node() and use folio_stable_node() directly @ 2025-09-16 8:05 Longlong Xia 2025-09-16 18:11 ` [PATCH] ksm: Use a folio inside cmp_and_merge_page() Matthew Wilcox (Oracle) 2025-09-16 18:14 ` [PATCH 1/1] mm/ksm: remove page_stable_node() and use folio_stable_node() directly Matthew Wilcox 0 siblings, 2 replies; 5+ messages in thread From: Longlong Xia @ 2025-09-16 8:05 UTC (permalink / raw) To: akpm, david Cc: xu.xin16, chengming.zhou, linux-kernel, linux-mm, Longlong Xia The page_stable_node() function was a trivial wrapper around folio_stable_node() that had only one call site. Remove this unnecessary helper and call folio_stable_node(page_folio(page)) directly at that site.There is no functional change. Signed-off-by: Longlong Xia <xialonglong@kylinos.cn> --- mm/ksm.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 160787bb121c..eab5348d19a7 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1061,11 +1061,6 @@ struct ksm_stable_node *folio_stable_node(const struct folio *folio) return folio_test_ksm(folio) ? folio_raw_mapping(folio) : NULL; } -static inline struct ksm_stable_node *page_stable_node(struct page *page) -{ - return folio_stable_node(page_folio(page)); -} - static inline void folio_set_stable_node(struct folio *folio, struct ksm_stable_node *stable_node) { @@ -2233,7 +2228,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite int err; bool max_page_sharing_bypass = false; - stable_node = page_stable_node(page); + stable_node = folio_stable_node(page_folio(page)); if (stable_node) { if (stable_node->head != &migrate_nodes && get_kpfn_nid(READ_ONCE(stable_node->kpfn)) != -- 2.43.0 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH] ksm: Use a folio inside cmp_and_merge_page() 2025-09-16 8:05 [PATCH 1/1] mm/ksm: remove page_stable_node() and use folio_stable_node() directly Longlong Xia @ 2025-09-16 18:11 ` Matthew Wilcox (Oracle) 2025-09-17 7:38 ` David Hildenbrand 2025-09-17 12:21 ` Chengming Zhou 2025-09-16 18:14 ` [PATCH 1/1] mm/ksm: remove page_stable_node() and use folio_stable_node() directly Matthew Wilcox 1 sibling, 2 replies; 5+ messages in thread From: Matthew Wilcox (Oracle) @ 2025-09-16 18:11 UTC (permalink / raw) To: akpm, david, xu.xin16, chengming.zhou, linux-kernel, linux-mm, Longlong Xia Cc: Matthew Wilcox (Oracle) This removes the last call to page_stable_node(), so delete the wrapper. It also removes a call to trylock_page() and saves a call to compound_head(), as well as removing a reference to folio->page. Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> --- mm/ksm.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/mm/ksm.c b/mm/ksm.c index 8583fb91ef13..47655ca8f9a5 100644 --- a/mm/ksm.c +++ b/mm/ksm.c @@ -1057,11 +1057,6 @@ struct ksm_stable_node *folio_stable_node(const struct folio *folio) return folio_test_ksm(folio) ? folio_raw_mapping(folio) : NULL; } -static inline struct ksm_stable_node *page_stable_node(struct page *page) -{ - return folio_stable_node(page_folio(page)); -} - static inline void folio_set_stable_node(struct folio *folio, struct ksm_stable_node *stable_node) { @@ -2221,6 +2216,7 @@ static void stable_tree_append(struct ksm_rmap_item *rmap_item, */ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_item) { + struct folio *folio = page_folio(page); struct ksm_rmap_item *tree_rmap_item; struct page *tree_page = NULL; struct ksm_stable_node *stable_node; @@ -2229,7 +2225,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite int err; bool max_page_sharing_bypass = false; - stable_node = page_stable_node(page); + stable_node = folio_stable_node(folio); if (stable_node) { if (stable_node->head != &migrate_nodes && get_kpfn_nid(READ_ONCE(stable_node->kpfn)) != @@ -2268,7 +2264,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite /* Start by searching for the folio in the stable tree */ kfolio = stable_tree_search(page); - if (&kfolio->page == page && rmap_item->head == stable_node) { + if (kfolio == folio && rmap_item->head == stable_node) { folio_put(kfolio); return; } @@ -2349,10 +2345,11 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite * the page is locked, it is better to skip it and * perhaps try again later. */ - if (!trylock_page(page)) + if (!folio_trylock(folio)) return; split_huge_page(page); - unlock_page(page); + folio = page_folio(page); + folio_unlock(folio); } } } -- 2.47.2 ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] ksm: Use a folio inside cmp_and_merge_page() 2025-09-16 18:11 ` [PATCH] ksm: Use a folio inside cmp_and_merge_page() Matthew Wilcox (Oracle) @ 2025-09-17 7:38 ` David Hildenbrand 2025-09-17 12:21 ` Chengming Zhou 1 sibling, 0 replies; 5+ messages in thread From: David Hildenbrand @ 2025-09-17 7:38 UTC (permalink / raw) To: Matthew Wilcox (Oracle), akpm, xu.xin16, chengming.zhou, linux-kernel, linux-mm, Longlong Xia On 16.09.25 20:11, Matthew Wilcox (Oracle) wrote: > This removes the last call to page_stable_node(), so delete the > wrapper. It also removes a call to trylock_page() and saves a call to > compound_head(), as well as removing a reference to folio->page. > > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> > --- Acked-by: David Hildenbrand <david@redhat.com> -- Cheers David / dhildenb ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] ksm: Use a folio inside cmp_and_merge_page() 2025-09-16 18:11 ` [PATCH] ksm: Use a folio inside cmp_and_merge_page() Matthew Wilcox (Oracle) 2025-09-17 7:38 ` David Hildenbrand @ 2025-09-17 12:21 ` Chengming Zhou 1 sibling, 0 replies; 5+ messages in thread From: Chengming Zhou @ 2025-09-17 12:21 UTC (permalink / raw) To: Matthew Wilcox (Oracle), akpm, david, xu.xin16, linux-kernel, linux-mm, Longlong Xia On 2025/9/17 02:11, Matthew Wilcox (Oracle) wrote: > This removes the last call to page_stable_node(), so delete the > wrapper. It also removes a call to trylock_page() and saves a call to > compound_head(), as well as removing a reference to folio->page. > > Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org> Reviewed-by: Chengming Zhou <chengming.zhou@linux.dev> Thanks. > --- > mm/ksm.c | 15 ++++++--------- > 1 file changed, 6 insertions(+), 9 deletions(-) > > diff --git a/mm/ksm.c b/mm/ksm.c > index 8583fb91ef13..47655ca8f9a5 100644 > --- a/mm/ksm.c > +++ b/mm/ksm.c > @@ -1057,11 +1057,6 @@ struct ksm_stable_node *folio_stable_node(const struct folio *folio) > return folio_test_ksm(folio) ? folio_raw_mapping(folio) : NULL; > } > > -static inline struct ksm_stable_node *page_stable_node(struct page *page) > -{ > - return folio_stable_node(page_folio(page)); > -} > - > static inline void folio_set_stable_node(struct folio *folio, > struct ksm_stable_node *stable_node) > { > @@ -2221,6 +2216,7 @@ static void stable_tree_append(struct ksm_rmap_item *rmap_item, > */ > static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_item) > { > + struct folio *folio = page_folio(page); > struct ksm_rmap_item *tree_rmap_item; > struct page *tree_page = NULL; > struct ksm_stable_node *stable_node; > @@ -2229,7 +2225,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite > int err; > bool max_page_sharing_bypass = false; > > - stable_node = page_stable_node(page); > + stable_node = folio_stable_node(folio); > if (stable_node) { > if (stable_node->head != &migrate_nodes && > get_kpfn_nid(READ_ONCE(stable_node->kpfn)) != > @@ -2268,7 +2264,7 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite > > /* Start by searching for the folio in the stable tree */ > kfolio = stable_tree_search(page); > - if (&kfolio->page == page && rmap_item->head == stable_node) { > + if (kfolio == folio && rmap_item->head == stable_node) { > folio_put(kfolio); > return; > } > @@ -2349,10 +2345,11 @@ static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_ite > * the page is locked, it is better to skip it and > * perhaps try again later. > */ > - if (!trylock_page(page)) > + if (!folio_trylock(folio)) > return; > split_huge_page(page); > - unlock_page(page); > + folio = page_folio(page); > + folio_unlock(folio); > } > } > } ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH 1/1] mm/ksm: remove page_stable_node() and use folio_stable_node() directly 2025-09-16 8:05 [PATCH 1/1] mm/ksm: remove page_stable_node() and use folio_stable_node() directly Longlong Xia 2025-09-16 18:11 ` [PATCH] ksm: Use a folio inside cmp_and_merge_page() Matthew Wilcox (Oracle) @ 2025-09-16 18:14 ` Matthew Wilcox 1 sibling, 0 replies; 5+ messages in thread From: Matthew Wilcox @ 2025-09-16 18:14 UTC (permalink / raw) To: Longlong Xia Cc: akpm, david, xu.xin16, chengming.zhou, linux-kernel, linux-mm On Tue, Sep 16, 2025 at 04:05:33PM +0800, Longlong Xia wrote: > The page_stable_node() function was a trivial wrapper around > folio_stable_node() that had only one call site. Remove this > unnecessary helper and call folio_stable_node(page_folio(page)) > directly at that site.There is no functional change. I just sent a replacement for this patch as a reply. I've been sitting on it since last December as it didn't really feel important nough to send, but if people are going to try to do this kind of thing, may as well do it properly. ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-09-17 12:21 UTC | newest] Thread overview: 5+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2025-09-16 8:05 [PATCH 1/1] mm/ksm: remove page_stable_node() and use folio_stable_node() directly Longlong Xia 2025-09-16 18:11 ` [PATCH] ksm: Use a folio inside cmp_and_merge_page() Matthew Wilcox (Oracle) 2025-09-17 7:38 ` David Hildenbrand 2025-09-17 12:21 ` Chengming Zhou 2025-09-16 18:14 ` [PATCH 1/1] mm/ksm: remove page_stable_node() and use folio_stable_node() directly Matthew Wilcox
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).