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/migrate: move movable_ops page handling out of move_to_new_folio()

Let's move that handling directly into migrate_folio_move(), so we can
simplify move_to_new_folio(). While at it, fixup the documentation a bit.

Note that unmap_and_move_huge_page() does not care, because it only deals
with actual folios. (we only support migration of individual movable_ops
pages)

Link: https://lkml.kernel.org/r/20250704102524.326966-12-david@redhat.com
Signed-off-by: David Hildenbrand <david@redhat.com>
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@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
be4a3e9c 07e5355e

+30 -33
+30 -33
mm/migrate.c
··· 1026 1026 } 1027 1027 1028 1028 /* 1029 - * Move a page to a newly allocated page 1030 - * The page is locked and all ptes have been successfully removed. 1029 + * Move a src folio to a newly allocated dst folio. 1031 1030 * 1032 - * The new page will have replaced the old page if this function 1033 - * is successful. 1031 + * The src and dst folios are locked and the src folios was unmapped from 1032 + * the page tables. 1033 + * 1034 + * On success, the src folio was replaced by the dst folio. 1034 1035 * 1035 1036 * Return value: 1036 1037 * < 0 - error code ··· 1040 1039 static int move_to_new_folio(struct folio *dst, struct folio *src, 1041 1040 enum migrate_mode mode) 1042 1041 { 1042 + struct address_space *mapping = folio_mapping(src); 1043 1043 int rc = -EAGAIN; 1044 - bool is_lru = !__folio_test_movable(src); 1045 1044 1046 1045 VM_BUG_ON_FOLIO(!folio_test_locked(src), src); 1047 1046 VM_BUG_ON_FOLIO(!folio_test_locked(dst), dst); 1048 1047 1049 - if (likely(is_lru)) { 1050 - struct address_space *mapping = folio_mapping(src); 1048 + if (!mapping) 1049 + rc = migrate_folio(mapping, dst, src, mode); 1050 + else if (mapping_inaccessible(mapping)) 1051 + rc = -EOPNOTSUPP; 1052 + else if (mapping->a_ops->migrate_folio) 1053 + /* 1054 + * Most folios have a mapping and most filesystems 1055 + * provide a migrate_folio callback. Anonymous folios 1056 + * are part of swap space which also has its own 1057 + * migrate_folio callback. This is the most common path 1058 + * for page migration. 1059 + */ 1060 + rc = mapping->a_ops->migrate_folio(mapping, dst, src, 1061 + mode); 1062 + else 1063 + rc = fallback_migrate_folio(mapping, dst, src, mode); 1051 1064 1052 - if (!mapping) 1053 - rc = migrate_folio(mapping, dst, src, mode); 1054 - else if (mapping_inaccessible(mapping)) 1055 - rc = -EOPNOTSUPP; 1056 - else if (mapping->a_ops->migrate_folio) 1057 - /* 1058 - * Most folios have a mapping and most filesystems 1059 - * provide a migrate_folio callback. Anonymous folios 1060 - * are part of swap space which also has its own 1061 - * migrate_folio callback. This is the most common path 1062 - * for page migration. 1063 - */ 1064 - rc = mapping->a_ops->migrate_folio(mapping, dst, src, 1065 - mode); 1066 - else 1067 - rc = fallback_migrate_folio(mapping, dst, src, mode); 1068 - 1069 - if (rc != MIGRATEPAGE_SUCCESS) 1070 - goto out; 1065 + if (rc == MIGRATEPAGE_SUCCESS) { 1071 1066 /* 1072 1067 * For pagecache folios, src->mapping must be cleared before src 1073 1068 * is freed. Anonymous folios must stay anonymous until freed. ··· 1073 1076 1074 1077 if (likely(!folio_is_zone_device(dst))) 1075 1078 flush_dcache_folio(dst); 1076 - } else { 1077 - rc = migrate_movable_ops_page(&dst->page, &src->page, mode); 1078 1079 } 1079 - out: 1080 1080 return rc; 1081 1081 } 1082 1082 ··· 1324 1330 int rc; 1325 1331 int old_page_state = 0; 1326 1332 struct anon_vma *anon_vma = NULL; 1327 - bool is_lru = !__folio_test_movable(src); 1328 1333 struct list_head *prev; 1329 1334 1330 1335 __migrate_folio_extract(dst, &old_page_state, &anon_vma); 1331 1336 prev = dst->lru.prev; 1332 1337 list_del(&dst->lru); 1333 1338 1339 + if (unlikely(__folio_test_movable(src))) { 1340 + rc = migrate_movable_ops_page(&dst->page, &src->page, mode); 1341 + if (rc) 1342 + goto out; 1343 + goto out_unlock_both; 1344 + } 1345 + 1334 1346 rc = move_to_new_folio(dst, src, mode); 1335 1347 if (rc) 1336 1348 goto out; 1337 - 1338 - if (unlikely(!is_lru)) 1339 - goto out_unlock_both; 1340 1349 1341 1350 /* 1342 1351 * When successful, push dst to LRU immediately: so that if it