[PATCH v1 19/29] mm: stop storing migration_ops in page->mapping

David Hildenbrand david at redhat.com
Tue Jul 1 22:41:03 AEST 2025


On 01.07.25 14:12, Lorenzo Stoakes wrote:
> On Mon, Jun 30, 2025 at 03:00:00PM +0200, David Hildenbrand wrote:
>> ... 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 at nvidia.com>
>> Signed-off-by: David Hildenbrand <david at redhat.com>
> 
> See comment below, this feels iffy in the long run but ok as an interim measure.
> 
> So:
> 
> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes at oracle.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 15d3c1031530c..c6c9998014ec8 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.
>> +	 */
> 
> Ah now this makes more sense...
> 
>> +#ifdef CONFIG_BALLOON_COMPACTION
>> +	if (PageOffline(page))
>> +		/* Only balloon compaction sets PageOffline pages movable. */
>> +		return &balloon_mops;
> 
> So it's certain that if we try to invoke movable ops, and it's the balloon
> compaction case, the page will be offline?

Yes. The page must be marked as having movable_ops by the user. The next 
patch reworks that as well.

A PageOffline page without movable_ops will never end up here 
(page_has_movable_ops() == false).

> 
>> +#endif /* CONFIG_BALLOON_COMPACTION */
>> +#if defined(CONFIG_ZSMALLOC) && defined(CONFIG_COMPACTION)
>> +	if (PageZsmalloc(page))
> 
> And same question only for ZS malloc.

Same thing.

> 
>> +		return &zsmalloc_mops;
>> +#endif /* defined(CONFIG_ZSMALLOC) && defined(CONFIG_COMPACTION) */
>> +	return NULL;
>> +}
> 
> This is kind of sketchy as it's baking in assumptions implicitly, so I hope we
> can find an improved way of doing this later, even if it's about providing
> e.g. is_ballon_movable_ops_page() and is_zsmalloc_movable_ops_page() predicates
> that abstract this code + placing them in the relevant code so it's at least
> obvious to people working on this stuff that this needs to be considered.
> 
> But ok as a means of getting away from having to have the hook object encoded.

Yeah, not sure yet how to clean that up in the future. As I stated 
somewhere, maybe we just want a registration interface to handle a 
specific page type. But for handling the two known in-tree users, this 
should get us going.

Thanks!

-- 
Cheers,

David / dhildenb



More information about the Linuxppc-dev mailing list