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.

mm: remove __folio_test_movable()

Convert to page_has_movable_ops(). While at it, cleanup relevant code a
bit.

The data_race() in migrate_folio_unmap() is questionable: we already hold
a page reference, and concurrent modifications can no longer happen (iow:
__ClearPageMovable() no longer exists). Drop it for now, we'll rework
page_has_movable_ops() soon either way to no longer rely on page->mapping.

Wherever we cast from folio to page now is a clear sign that this code has
to be decoupled.

Link: https://lkml.kernel.org/r/20250704102524.326966-19-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Cc: Alistair Popple <apopple@nvidia.com>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Brendan Jackman <jackmanb@google.com>
Cc: Byungchul Park <byungchul@sk.com>
Cc: Chengming Zhou <chengming.zhou@linux.dev>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Christophe Leroy <christophe.leroy@csgroup.eu>
Cc: Eugenio Pé rez <eperezma@redhat.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Gregory Price <gourry@gourry.net>
Cc: "Huang, Ying" <ying.huang@linux.alibaba.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jason Wang <jasowang@redhat.com>
Cc: Jerrin Shaji George <jerrin.shaji-george@broadcom.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Cc: John Hubbard <jhubbard@nvidia.com>
Cc: Jonathan Corbet <corbet@lwn.net>
Cc: Joshua Hahn <joshua.hahnjy@gmail.com>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Mathew Brost <matthew.brost@intel.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Miaohe Lin <linmiaohe@huawei.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: "Michael S. Tsirkin" <mst@redhat.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Minchan Kim <minchan@kernel.org>
Cc: Naoya Horiguchi <nao.horiguchi@gmail.com>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Oscar Salvador <osalvador@suse.de>
Cc: Peter Xu <peterx@redhat.com>
Cc: Qi Zheng <zhengqi.arch@bytedance.com>
Cc: Rakie Kim <rakie.kim@sk.com>
Cc: Rik van Riel <riel@surriel.com>
Cc: Sergey Senozhatsky <senozhatsky@chromium.org>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Vlastimil Babka <vbabka@suse.cz>
Cc: Xuan Zhuo <xuanzhuo@linux.alibaba.com>
Cc: xu xin <xu.xin16@zte.com.cn>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Hildenbrand and committed by
Andrew Morton
457d7b3a 9f56c08a

+17 -38
-6
include/linux/page-flags.h
··· 744 744 return folio_test_anon(page_folio(page)); 745 745 } 746 746 747 - static __always_inline bool __folio_test_movable(const struct folio *folio) 748 - { 749 - return ((unsigned long)folio->mapping & PAGE_MAPPING_FLAGS) == 750 - PAGE_MAPPING_MOVABLE; 751 - } 752 - 753 747 static __always_inline bool page_has_movable_ops(const struct page *page) 754 748 { 755 749 return ((unsigned long)page->mapping & PAGE_MAPPING_FLAGS) ==
+13 -30
mm/migrate.c
··· 221 221 continue; 222 222 } 223 223 list_del(&folio->lru); 224 - /* 225 - * We isolated non-lru movable folio so here we can use 226 - * __folio_test_movable because LRU folio's mapping cannot 227 - * have PAGE_MAPPING_MOVABLE. 228 - */ 229 - if (unlikely(__folio_test_movable(folio))) { 224 + if (unlikely(page_has_movable_ops(&folio->page))) { 230 225 putback_movable_ops_page(&folio->page); 231 226 } else { 232 227 node_stat_mod_folio(folio, NR_ISOLATED_ANON + ··· 234 239 /* Must be called with an elevated refcount on the non-hugetlb folio */ 235 240 bool isolate_folio_to_list(struct folio *folio, struct list_head *list) 236 241 { 237 - bool isolated, lru; 238 - 239 242 if (folio_test_hugetlb(folio)) 240 243 return folio_isolate_hugetlb(folio, list); 241 244 242 - lru = !__folio_test_movable(folio); 243 - if (lru) 244 - isolated = folio_isolate_lru(folio); 245 - else 246 - isolated = isolate_movable_ops_page(&folio->page, 247 - ISOLATE_UNEVICTABLE); 248 - 249 - if (!isolated) 250 - return false; 251 - 252 - list_add(&folio->lru, list); 253 - if (lru) 245 + if (page_has_movable_ops(&folio->page)) { 246 + if (!isolate_movable_ops_page(&folio->page, 247 + ISOLATE_UNEVICTABLE)) 248 + return false; 249 + } else { 250 + if (!folio_isolate_lru(folio)) 251 + return false; 254 252 node_stat_add_folio(folio, NR_ISOLATED_ANON + 255 253 folio_is_file_lru(folio)); 256 - 254 + } 255 + list_add(&folio->lru, list); 257 256 return true; 258 257 } 259 258 ··· 1131 1142 static void migrate_folio_done(struct folio *src, 1132 1143 enum migrate_reason reason) 1133 1144 { 1134 - /* 1135 - * Compaction can migrate also non-LRU pages which are 1136 - * not accounted to NR_ISOLATED_*. They can be recognized 1137 - * as __folio_test_movable 1138 - */ 1139 - if (likely(!__folio_test_movable(src)) && reason != MR_DEMOTION) 1145 + if (likely(!page_has_movable_ops(&src->page)) && reason != MR_DEMOTION) 1140 1146 mod_node_page_state(folio_pgdat(src), NR_ISOLATED_ANON + 1141 1147 folio_is_file_lru(src), -folio_nr_pages(src)); 1142 1148 ··· 1150 1166 int rc = -EAGAIN; 1151 1167 int old_page_state = 0; 1152 1168 struct anon_vma *anon_vma = NULL; 1153 - bool is_lru = data_race(!__folio_test_movable(src)); 1154 1169 bool locked = false; 1155 1170 bool dst_locked = false; 1156 1171 ··· 1250 1267 goto out; 1251 1268 dst_locked = true; 1252 1269 1253 - if (unlikely(!is_lru)) { 1270 + if (unlikely(page_has_movable_ops(&src->page))) { 1254 1271 __migrate_folio_record(dst, old_page_state, anon_vma); 1255 1272 return MIGRATEPAGE_UNMAP; 1256 1273 } ··· 1315 1332 prev = dst->lru.prev; 1316 1333 list_del(&dst->lru); 1317 1334 1318 - if (unlikely(__folio_test_movable(src))) { 1335 + if (unlikely(page_has_movable_ops(&src->page))) { 1319 1336 rc = migrate_movable_ops_page(&dst->page, &src->page, mode); 1320 1337 if (rc) 1321 1338 goto out;
+4 -2
mm/vmscan.c
··· 1651 1651 unsigned int noreclaim_flag; 1652 1652 1653 1653 list_for_each_entry_safe(folio, next, folio_list, lru) { 1654 + /* TODO: these pages should not even appear in this list. */ 1655 + if (page_has_movable_ops(&folio->page)) 1656 + continue; 1654 1657 if (!folio_test_hugetlb(folio) && folio_is_file_lru(folio) && 1655 - !folio_test_dirty(folio) && !__folio_test_movable(folio) && 1656 - !folio_test_unevictable(folio)) { 1658 + !folio_test_dirty(folio) && !folio_test_unevictable(folio)) { 1657 1659 folio_clear_active(folio); 1658 1660 list_move(&folio->lru, &clean_folios); 1659 1661 }