Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

ksm: use a folio inside cmp_and_merge_page()

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.

Link: https://lkml.kernel.org/r/20250916181219.2400258-1-willy@infradead.org
Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
Reviewed-by: Chengming Zhou <chengming.zhou@linux.dev>
Acked-by: David Hildenbrand <david@redhat.com>
Cc: Longlong Xia <xialonglong@kylinos.cn>
Cc: xu xin <xu.xin16@zte.com.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

Matthew Wilcox (Oracle) and committed by
Andrew Morton
1b00ab48 19c5fb83

+6 -9
+6 -9
mm/ksm.c
··· 1061 1061 return folio_test_ksm(folio) ? folio_raw_mapping(folio) : NULL; 1062 1062 } 1063 1063 1064 - static inline struct ksm_stable_node *page_stable_node(struct page *page) 1065 - { 1066 - return folio_stable_node(page_folio(page)); 1067 - } 1068 - 1069 1064 static inline void folio_set_stable_node(struct folio *folio, 1070 1065 struct ksm_stable_node *stable_node) 1071 1066 { ··· 2220 2225 */ 2221 2226 static void cmp_and_merge_page(struct page *page, struct ksm_rmap_item *rmap_item) 2222 2227 { 2228 + struct folio *folio = page_folio(page); 2223 2229 struct ksm_rmap_item *tree_rmap_item; 2224 2230 struct page *tree_page = NULL; 2225 2231 struct ksm_stable_node *stable_node; ··· 2229 2233 int err; 2230 2234 bool max_page_sharing_bypass = false; 2231 2235 2232 - stable_node = page_stable_node(page); 2236 + stable_node = folio_stable_node(folio); 2233 2237 if (stable_node) { 2234 2238 if (stable_node->head != &migrate_nodes && 2235 2239 get_kpfn_nid(READ_ONCE(stable_node->kpfn)) != ··· 2268 2272 2269 2273 /* Start by searching for the folio in the stable tree */ 2270 2274 kfolio = stable_tree_search(page); 2271 - if (&kfolio->page == page && rmap_item->head == stable_node) { 2275 + if (kfolio == folio && rmap_item->head == stable_node) { 2272 2276 folio_put(kfolio); 2273 2277 return; 2274 2278 } ··· 2349 2353 * the page is locked, it is better to skip it and 2350 2354 * perhaps try again later. 2351 2355 */ 2352 - if (!trylock_page(page)) 2356 + if (!folio_trylock(folio)) 2353 2357 return; 2354 2358 split_huge_page(page); 2355 - unlock_page(page); 2359 + folio = page_folio(page); 2360 + folio_unlock(folio); 2356 2361 } 2357 2362 } 2358 2363 }