From: David Hildenbrand <david@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, linux-doc@vger.kernel.org,
linuxppc-dev@lists.ozlabs.org, virtualization@lists.linux.dev,
linux-fsdevel@vger.kernel.org,
"David Hildenbrand" <david@redhat.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Jonathan Corbet" <corbet@lwn.net>,
"Madhavan Srinivasan" <maddy@linux.ibm.com>,
"Michael Ellerman" <mpe@ellerman.id.au>,
"Nicholas Piggin" <npiggin@gmail.com>,
"Christophe Leroy" <christophe.leroy@csgroup.eu>,
"Jerrin Shaji George" <jerrin.shaji-george@broadcom.com>,
"Arnd Bergmann" <arnd@arndb.de>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>,
"Michael S. Tsirkin" <mst@redhat.com>,
"Jason Wang" <jasowang@redhat.com>,
"Xuan Zhuo" <xuanzhuo@linux.alibaba.com>,
"Eugenio Pérez" <eperezma@redhat.com>,
"Alexander Viro" <viro@zeniv.linux.org.uk>,
"Christian Brauner" <brauner@kernel.org>,
"Jan Kara" <jack@suse.cz>, "Zi Yan" <ziy@nvidia.com>,
"Matthew Brost" <matthew.brost@intel.com>,
"Joshua Hahn" <joshua.hahnjy@gmail.com>,
"Rakie Kim" <rakie.kim@sk.com>,
"Byungchul Park" <byungchul@sk.com>,
"Gregory Price" <gourry@gourry.net>,
"Ying Huang" <ying.huang@linux.alibaba.com>,
"Alistair Popple" <apopple@nvidia.com>,
"Lorenzo Stoakes" <lorenzo.stoakes@oracle.com>,
"Liam R. Howlett" <Liam.Howlett@oracle.com>,
"Vlastimil Babka" <vbabka@suse.cz>,
"Mike Rapoport" <rppt@kernel.org>,
"Suren Baghdasaryan" <surenb@google.com>,
"Michal Hocko" <mhocko@suse.com>,
"Matthew Wilcox (Oracle)" <willy@infradead.org>,
"Minchan Kim" <minchan@kernel.org>,
"Sergey Senozhatsky" <senozhatsky@chromium.org>,
"Brendan Jackman" <jackmanb@google.com>,
"Johannes Weiner" <hannes@cmpxchg.org>,
"Jason Gunthorpe" <jgg@ziepe.ca>,
"John Hubbard" <jhubbard@nvidia.com>,
"Peter Xu" <peterx@redhat.com>, "Xu Xin" <xu.xin16@zte.com.cn>,
"Chengming Zhou" <chengming.zhou@linux.dev>,
"Miaohe Lin" <linmiaohe@huawei.com>,
"Naoya Horiguchi" <nao.horiguchi@gmail.com>,
"Oscar Salvador" <osalvador@suse.de>,
"Rik van Riel" <riel@surriel.com>,
"Harry Yoo" <harry.yoo@oracle.com>,
"Qi Zheng" <zhengqi.arch@bytedance.com>,
"Shakeel Butt" <shakeel.butt@linux.dev>
Subject: [PATCH v2 19/29] mm: stop storing migration_ops in page->mapping
Date: Fri, 4 Jul 2025 12:25:13 +0200 [thread overview]
Message-ID: <20250704102524.326966-20-david@redhat.com> (raw)
In-Reply-To: <20250704102524.326966-1-david@redhat.com>
... instead, look them up statically based on the page type. Maybe in the
future we want a registration interface? At least for now, it can be
easily handled using the two page types that actually support page
migration.
The remaining usage of page->mapping is to flag such pages as actually
being movable (having movable_ops), which we will change next.
Reviewed-by: Zi Yan <ziy@nvidia.com>
Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@oracle.com>
Reviewed-by: Harry Yoo <harry.yoo@oracle.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
include/linux/balloon_compaction.h | 2 +-
include/linux/migrate.h | 14 ++------------
include/linux/zsmalloc.h | 2 ++
mm/balloon_compaction.c | 1 -
mm/compaction.c | 5 ++---
mm/migrate.c | 23 +++++++++++++++++++++++
mm/zpdesc.h | 5 ++---
mm/zsmalloc.c | 8 +++-----
8 files changed, 35 insertions(+), 25 deletions(-)
diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h
index 9bce8e9f5018c..a8a1706cc56f3 100644
--- a/include/linux/balloon_compaction.h
+++ b/include/linux/balloon_compaction.h
@@ -92,7 +92,7 @@ static inline void balloon_page_insert(struct balloon_dev_info *balloon,
struct page *page)
{
__SetPageOffline(page);
- __SetPageMovable(page, &balloon_mops);
+ __SetPageMovable(page);
set_page_private(page, (unsigned long)balloon);
list_add(&page->lru, &balloon->pages);
}
diff --git a/include/linux/migrate.h b/include/linux/migrate.h
index e04035f70e36f..6aece3f3c8be8 100644
--- a/include/linux/migrate.h
+++ b/include/linux/migrate.h
@@ -104,23 +104,13 @@ static inline int migrate_huge_page_move_mapping(struct address_space *mapping,
#endif /* CONFIG_MIGRATION */
#ifdef CONFIG_COMPACTION
-void __SetPageMovable(struct page *page, const struct movable_operations *ops);
+void __SetPageMovable(struct page *page);
#else
-static inline void __SetPageMovable(struct page *page,
- const struct movable_operations *ops)
+static inline void __SetPageMovable(struct page *page)
{
}
#endif
-static inline
-const struct movable_operations *page_movable_ops(struct page *page)
-{
- VM_WARN_ON_ONCE_PAGE(!page_has_movable_ops(page), page);
-
- return (const struct movable_operations *)
- ((unsigned long)page->mapping - PAGE_MAPPING_MOVABLE);
-}
-
#ifdef CONFIG_NUMA_BALANCING
int migrate_misplaced_folio_prepare(struct folio *folio,
struct vm_area_struct *vma, int node);
diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h
index 13e9cc5490f71..f3ccff2d966cd 100644
--- a/include/linux/zsmalloc.h
+++ b/include/linux/zsmalloc.h
@@ -46,4 +46,6 @@ void zs_obj_read_end(struct zs_pool *pool, unsigned long handle,
void zs_obj_write(struct zs_pool *pool, unsigned long handle,
void *handle_mem, size_t mem_len);
+extern const struct movable_operations zsmalloc_mops;
+
#endif
diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c
index e4f1a122d786b..2a4a649805c11 100644
--- a/mm/balloon_compaction.c
+++ b/mm/balloon_compaction.c
@@ -253,6 +253,5 @@ const struct movable_operations balloon_mops = {
.isolate_page = balloon_page_isolate,
.putback_page = balloon_page_putback,
};
-EXPORT_SYMBOL_GPL(balloon_mops);
#endif /* CONFIG_BALLOON_COMPACTION */
diff --git a/mm/compaction.c b/mm/compaction.c
index 41fd6a1fe9a33..348eb754cb227 100644
--- a/mm/compaction.c
+++ b/mm/compaction.c
@@ -114,11 +114,10 @@ static unsigned long release_free_list(struct list_head *freepages)
}
#ifdef CONFIG_COMPACTION
-void __SetPageMovable(struct page *page, const struct movable_operations *mops)
+void __SetPageMovable(struct page *page)
{
VM_BUG_ON_PAGE(!PageLocked(page), page);
- VM_BUG_ON_PAGE((unsigned long)mops & PAGE_MAPPING_MOVABLE, page);
- page->mapping = (void *)((unsigned long)mops | PAGE_MAPPING_MOVABLE);
+ page->mapping = (void *)(PAGE_MAPPING_MOVABLE);
}
EXPORT_SYMBOL(__SetPageMovable);
diff --git a/mm/migrate.c b/mm/migrate.c
index e307b142ab41a..fde6221562399 100644
--- a/mm/migrate.c
+++ b/mm/migrate.c
@@ -43,6 +43,8 @@
#include <linux/sched/sysctl.h>
#include <linux/memory-tiers.h>
#include <linux/pagewalk.h>
+#include <linux/balloon_compaction.h>
+#include <linux/zsmalloc.h>
#include <asm/tlbflush.h>
@@ -51,6 +53,27 @@
#include "internal.h"
#include "swap.h"
+static const struct movable_operations *page_movable_ops(struct page *page)
+{
+ VM_WARN_ON_ONCE_PAGE(!page_has_movable_ops(page), page);
+
+ /*
+ * If we enable page migration for a page of a certain type by marking
+ * it as movable, the page type must be sticky until the page gets freed
+ * back to the buddy.
+ */
+#ifdef CONFIG_BALLOON_COMPACTION
+ if (PageOffline(page))
+ /* Only balloon compaction sets PageOffline pages movable. */
+ return &balloon_mops;
+#endif /* CONFIG_BALLOON_COMPACTION */
+#if defined(CONFIG_ZSMALLOC) && defined(CONFIG_COMPACTION)
+ if (PageZsmalloc(page))
+ return &zsmalloc_mops;
+#endif /* defined(CONFIG_ZSMALLOC) && defined(CONFIG_COMPACTION) */
+ return NULL;
+}
+
/**
* isolate_movable_ops_page - isolate a movable_ops page for migration
* @page: The page.
diff --git a/mm/zpdesc.h b/mm/zpdesc.h
index 5763f36039736..6855d9e2732d8 100644
--- a/mm/zpdesc.h
+++ b/mm/zpdesc.h
@@ -152,10 +152,9 @@ static inline struct zpdesc *pfn_zpdesc(unsigned long pfn)
return page_zpdesc(pfn_to_page(pfn));
}
-static inline void __zpdesc_set_movable(struct zpdesc *zpdesc,
- const struct movable_operations *mops)
+static inline void __zpdesc_set_movable(struct zpdesc *zpdesc)
{
- __SetPageMovable(zpdesc_page(zpdesc), mops);
+ __SetPageMovable(zpdesc_page(zpdesc));
}
static inline void __zpdesc_set_zsmalloc(struct zpdesc *zpdesc)
diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c
index b12250e219bb7..4aaff7c26ea96 100644
--- a/mm/zsmalloc.c
+++ b/mm/zsmalloc.c
@@ -1685,8 +1685,6 @@ static void lock_zspage(struct zspage *zspage)
#ifdef CONFIG_COMPACTION
-static const struct movable_operations zsmalloc_mops;
-
static void replace_sub_page(struct size_class *class, struct zspage *zspage,
struct zpdesc *newzpdesc, struct zpdesc *oldzpdesc)
{
@@ -1709,7 +1707,7 @@ static void replace_sub_page(struct size_class *class, struct zspage *zspage,
set_first_obj_offset(newzpdesc, first_obj_offset);
if (unlikely(ZsHugePage(zspage)))
newzpdesc->handle = oldzpdesc->handle;
- __zpdesc_set_movable(newzpdesc, &zsmalloc_mops);
+ __zpdesc_set_movable(newzpdesc);
}
static bool zs_page_isolate(struct page *page, isolate_mode_t mode)
@@ -1819,7 +1817,7 @@ static void zs_page_putback(struct page *page)
{
}
-static const struct movable_operations zsmalloc_mops = {
+const struct movable_operations zsmalloc_mops = {
.isolate_page = zs_page_isolate,
.migrate_page = zs_page_migrate,
.putback_page = zs_page_putback,
@@ -1882,7 +1880,7 @@ static void SetZsPageMovable(struct zs_pool *pool, struct zspage *zspage)
do {
WARN_ON(!zpdesc_trylock(zpdesc));
- __zpdesc_set_movable(zpdesc, &zsmalloc_mops);
+ __zpdesc_set_movable(zpdesc);
zpdesc_unlock(zpdesc);
} while ((zpdesc = get_next_zpdesc(zpdesc)) != NULL);
}
--
2.49.0
next prev parent reply other threads:[~2025-07-04 10:26 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-04 10:24 [PATCH v2 00/29] mm/migration: rework movable_ops page migration (part 1) David Hildenbrand
2025-07-04 10:24 ` [PATCH v2 01/29] mm/balloon_compaction: we cannot have isolated pages in the balloon list David Hildenbrand
2025-07-04 10:24 ` [PATCH v2 02/29] mm/balloon_compaction: convert balloon_page_delete() to balloon_page_finalize() David Hildenbrand
2025-07-04 10:24 ` [PATCH v2 03/29] mm/zsmalloc: drop PageIsolated() related VM_BUG_ONs David Hildenbrand
2025-07-04 10:24 ` [PATCH v2 04/29] mm/page_alloc: let page freeing clear any set page type David Hildenbrand
2025-07-04 10:24 ` [PATCH v2 05/29] mm/balloon_compaction: make PageOffline sticky until the page is freed David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 06/29] mm/zsmalloc: make PageZsmalloc() " David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 07/29] mm/migrate: rename isolate_movable_page() to isolate_movable_ops_page() David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 08/29] mm/migrate: rename putback_movable_folio() to putback_movable_ops_page() David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 09/29] mm/migrate: factor out movable_ops page handling into migrate_movable_ops_page() David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 10/29] mm/migrate: remove folio_test_movable() and folio_movable_ops() David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 11/29] mm/migrate: move movable_ops page handling out of move_to_new_folio() David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 12/29] mm/zsmalloc: stop using __ClearPageMovable() David Hildenbrand
2025-07-07 2:39 ` Sergey Senozhatsky
2025-07-04 10:25 ` [PATCH v2 13/29] mm/balloon_compaction: " David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 14/29] mm/migrate: remove __ClearPageMovable() David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 15/29] mm/migration: remove PageMovable() David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 16/29] mm: rename __PageMovable() to page_has_movable_ops() David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 17/29] mm/page_isolation: drop __folio_test_movable() check for large folios David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 18/29] mm: remove __folio_test_movable() David Hildenbrand
2025-07-04 10:25 ` David Hildenbrand [this message]
2025-07-04 10:25 ` [PATCH v2 20/29] mm: convert "movable" flag in page->mapping to a page flag David Hildenbrand
2025-07-11 9:58 ` David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 21/29] mm: rename PG_isolated to PG_movable_ops_isolated David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 22/29] mm/page-flags: rename PAGE_MAPPING_MOVABLE to PAGE_MAPPING_ANON_KSM David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 23/29] mm/page-alloc: remove PageMappingFlags() David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 24/29] mm/page-flags: remove folio_mapping_flags() David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 25/29] mm: simplify folio_expected_ref_count() David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 26/29] mm: rename PAGE_MAPPING_* to FOLIO_MAPPING_* David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 27/29] docs/mm: convert from "Non-LRU page migration" to "movable_ops page migration" David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 28/29] mm/balloon_compaction: "movable_ops" doc updates David Hildenbrand
2025-07-04 10:25 ` [PATCH v2 29/29] mm/balloon_compaction: provide single balloon_page_insert() and balloon_mapping_gfp_mask() David Hildenbrand
2025-07-04 21:06 ` [PATCH v2 00/29] mm/migration: rework movable_ops page migration (part 1) Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250704102524.326966-20-david@redhat.com \
--to=david@redhat.com \
--cc=Liam.Howlett@oracle.com \
--cc=akpm@linux-foundation.org \
--cc=apopple@nvidia.com \
--cc=arnd@arndb.de \
--cc=brauner@kernel.org \
--cc=byungchul@sk.com \
--cc=chengming.zhou@linux.dev \
--cc=christophe.leroy@csgroup.eu \
--cc=corbet@lwn.net \
--cc=eperezma@redhat.com \
--cc=gourry@gourry.net \
--cc=gregkh@linuxfoundation.org \
--cc=hannes@cmpxchg.org \
--cc=harry.yoo@oracle.com \
--cc=jack@suse.cz \
--cc=jackmanb@google.com \
--cc=jasowang@redhat.com \
--cc=jerrin.shaji-george@broadcom.com \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=joshua.hahnjy@gmail.com \
--cc=linmiaohe@huawei.com \
--cc=linux-doc@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=lorenzo.stoakes@oracle.com \
--cc=maddy@linux.ibm.com \
--cc=matthew.brost@intel.com \
--cc=mhocko@suse.com \
--cc=minchan@kernel.org \
--cc=mpe@ellerman.id.au \
--cc=mst@redhat.com \
--cc=nao.horiguchi@gmail.com \
--cc=npiggin@gmail.com \
--cc=osalvador@suse.de \
--cc=peterx@redhat.com \
--cc=rakie.kim@sk.com \
--cc=riel@surriel.com \
--cc=rppt@kernel.org \
--cc=senozhatsky@chromium.org \
--cc=shakeel.butt@linux.dev \
--cc=surenb@google.com \
--cc=vbabka@suse.cz \
--cc=viro@zeniv.linux.org.uk \
--cc=virtualization@lists.linux.dev \
--cc=willy@infradead.org \
--cc=xu.xin16@zte.com.cn \
--cc=xuanzhuo@linux.alibaba.com \
--cc=ying.huang@linux.alibaba.com \
--cc=zhengqi.arch@bytedance.com \
--cc=ziy@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).