]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mm/migration: remove PageMovable()
authorDavid Hildenbrand <david@redhat.com>
Fri, 4 Jul 2025 10:25:09 +0000 (12:25 +0200)
committerAndrew Morton <akpm@linux-foundation.org>
Sun, 13 Jul 2025 23:38:28 +0000 (16:38 -0700)
Previously, if __ClearPageMovable() were invoked on a page, this would
cause __PageMovable() to return false, but due to the continued existence
of page movable ops, PageMovable() would have returned true.

With __ClearPageMovable() gone, the two are exactly equivalent.

So we can replace PageMovable() checks by __PageMovable().  In fact,
__PageMovable() cannot change until a page is freed, so we can turn some
PageMovable() into sanity checks for __PageMovable().

Link: https://lkml.kernel.org/r/20250704102524.326966-16-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>
include/linux/migrate.h
mm/compaction.c
mm/migrate.c

index 6eeda8eb1e0d8c9181ebc218817a56d35758d788..25659a685e2aa244338912f39f493a7a5860dd07 100644 (file)
@@ -104,10 +104,8 @@ static inline int migrate_huge_page_move_mapping(struct address_space *mapping,
 #endif /* CONFIG_MIGRATION */
 
 #ifdef CONFIG_COMPACTION
-bool PageMovable(struct page *page);
 void __SetPageMovable(struct page *page, const struct movable_operations *ops);
 #else
-static inline bool PageMovable(struct page *page) { return false; }
 static inline void __SetPageMovable(struct page *page,
                const struct movable_operations *ops)
 {
index 889ec696ba96a819f607ff1ee647a1cea26fb95e..5c37373017014d42c0972bdd6c57fe5160e16e70 100644 (file)
@@ -114,21 +114,6 @@ static unsigned long release_free_list(struct list_head *freepages)
 }
 
 #ifdef CONFIG_COMPACTION
-bool PageMovable(struct page *page)
-{
-       const struct movable_operations *mops;
-
-       VM_BUG_ON_PAGE(!PageLocked(page), page);
-       if (!__PageMovable(page))
-               return false;
-
-       mops = page_movable_ops(page);
-       if (mops)
-               return true;
-
-       return false;
-}
-
 void __SetPageMovable(struct page *page, const struct movable_operations *mops)
 {
        VM_BUG_ON_PAGE(!PageLocked(page), page);
index 61e98ed46f134490d130f3fe2c208a054e170aa2..1f07c8f1fb74485ac5cb30851ac6780ebee9eb03 100644 (file)
@@ -87,9 +87,12 @@ bool isolate_movable_ops_page(struct page *page, isolate_mode_t mode)
                goto out;
 
        /*
-        * Check movable flag before taking the page lock because
+        * Check for movable_ops pages before taking the page lock because
         * we use non-atomic bitops on newly allocated page flags so
         * unconditionally grabbing the lock ruins page's owner side.
+        *
+        * Note that once a page has movable_ops, it will stay that way
+        * until the page was freed.
         */
        if (unlikely(!__PageMovable(page)))
                goto out_putfolio;
@@ -108,7 +111,8 @@ bool isolate_movable_ops_page(struct page *page, isolate_mode_t mode)
        if (unlikely(!folio_trylock(folio)))
                goto out_putfolio;
 
-       if (!PageMovable(page) || PageIsolated(page))
+       VM_WARN_ON_ONCE_PAGE(!__PageMovable(page), page);
+       if (PageIsolated(page))
                goto out_no_isolated;
 
        mops = page_movable_ops(page);
@@ -149,11 +153,10 @@ static void putback_movable_ops_page(struct page *page)
         */
        struct folio *folio = page_folio(page);
 
+       VM_WARN_ON_ONCE_PAGE(!__PageMovable(page), page);
        VM_WARN_ON_ONCE_PAGE(!PageIsolated(page), page);
        folio_lock(folio);
-       /* If the page was released by it's owner, there is nothing to do. */
-       if (PageMovable(page))
-               page_movable_ops(page)->putback_page(page);
+       page_movable_ops(page)->putback_page(page);
        ClearPageIsolated(page);
        folio_unlock(folio);
        folio_put(folio);
@@ -191,10 +194,9 @@ static int migrate_movable_ops_page(struct page *dst, struct page *src,
 {
        int rc = MIGRATEPAGE_SUCCESS;
 
+       VM_WARN_ON_ONCE_PAGE(!__PageMovable(src), src);
        VM_WARN_ON_ONCE_PAGE(!PageIsolated(src), src);
-       /* If the page was released by it's owner, there is nothing to do. */
-       if (PageMovable(src))
-               rc = page_movable_ops(src)->migrate_page(dst, src, mode);
+       rc = page_movable_ops(src)->migrate_page(dst, src, mode);
        if (rc == MIGRATEPAGE_SUCCESS)
                ClearPageIsolated(src);
        return rc;