FAILED: patch "[PATCH] mm: migrate: requeue destination folio on deferred split" failed to apply to 6.12-stable tree
Subsystems (3)
[email protected]
maintainerThe patch below does not apply to the 6.12-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-6.12.y
git checkout FETCH_HEAD
git cherry-pick -x a2e0c0668a3486f96b86c50e02872c8e94fd4f9c
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '2026042723-large-sedan-f63a@gregkh' --subject-prefix 'PATCH 6.12.y' HEAD^..
Possible dependencies:
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From a2e0c0668a3486f96b86c50e02872c8e94fd4f9c Mon Sep 17 00:00:00 2001
From: Usama Arif <[email protected]>
Date: Thu, 12 Mar 2026 03:47:23 -0700
Subject: [PATCH] mm: migrate: requeue destination folio on deferred split
queue
During folio migration, __folio_migrate_mapping() removes the source folio from the deferred split queue, but the destination folio is never re-queued. This causes underutilized THPs to escape the shrinker after NUMA migration, since they silently drop off the deferred split list.
Fix this by recording whether the source folio was on the deferred split queue and its partially mapped state before move_to_new_folio() unqueues it, and re-queuing the destination folio after a successful migration if it was.
By the time migrate_folio_move() runs, partially mapped folios without a pin have already been split by migrate_pages_batch(). So only two cases remain on the deferred list at this point:
1. Partially mapped folios with a pin (split failed).
2. Fully mapped but potentially underused folios. The recorded partially_mapped state is forwarded to deferred_split_folio() so that the destination folio is correctly re-queued in both cases.
Because THPs are removed from the deferred_list, THP shinker cannot split the underutilized THPs in time. As a result, users will show less free memory than before.
mm/migrate.c +17 -0
@@ -1358,6 +1358,8 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private,int rc;int old_page_state =0 ;struct anon_vma *anon_vma =NULL ; +bool src_deferred_split = false; +bool src_partially_mapped = false;struct list_head *prev;__migrate_folio_extract (dst, &old_page_state, &anon_vma);
@@ -1371,6 +1373,12 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private, goto out_unlock_both; } +if (folio_order (src) >1 && + !data_race (list_empty (&src->_deferred_list))) { + src_deferred_split = true; + src_partially_mapped =folio_test_partially_mapped (src); + } + rc =move_to_new_folio (dst, src, mode);if (rc) goto out;
@@ -1391,6 +1399,15 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private,if (old_page_state &PAGE_WAS_MAPPED )remove_migration_ptes (src, dst,0 ); +/* +* Requeue the destination folio on the deferred split queue if +* the source was on the queue. The source is unqueued in +* __folio_migrate_mapping(), so we recorded the state from +* before move_to_new_folio(). +*/ +if (src_deferred_split) +deferred_split_folio (dst, src_partially_mapped); + out_unlock_both:folio_unlock (dst);folio_set_owner_migrate_reason (dst, reason);
Sasha Levin
maintainerPATCH 1/3 mm/migrate: factor out movable_ops page handling into migrate_movable_ops_page()
From: David Hildenbrand <[email protected]>
[ Upstream commit b9ed00483d4cbacca04edb11984d8daf09e9ae22 ]
Let's factor it out, simplifying the calling code.
Before this change, we would have called flush_dcache_folio() also on movable_ops pages. As documented in Documentation/core-api/cachetlb.rst:
"This routine need only be called for page cache pages which can
potentially ever be mapped into the address space of a user process."
So don't do it for movable_ops pages. If there would ever be such a movable_ops page user, it should do the flushing itself after performing the copy.
Note that we can now change folio_mapping_flags() to folio_test_anon() to make it clearer, because movable_ops pages will never take that path.
Stable-dep-of: a2e0c0668a34 ("mm: migrate: requeue destination folio on deferred split queue")
--- mm/migrate.c | 84 +++++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 37 deletions(-)
mm/migrate.c +47 -37
@@ -130,6 +130,47 @@ static void putback_movable_folio(struct folio *folio)folio_clear_isolated (folio); } +/** +* migrate_movable_ops_page - migrate an isolated movable_ops page +* @dst: The destination page. +* @src: The source page. +* @mode: The migration mode. +* +* Migrate an isolated movable_ops page. +* +* If the src page was already released by its owner, the src page is +* un-isolated (putback) and migration succeeds; the migration core will be the +* owner of both pages. +* +* If the src page was not released by its owner and the migration was +* successful, the owner of the src page and the dst page are swapped and +* the src page is un-isolated. +* +* If migration fails, the ownership stays unmodified and the src page +* remains isolated: migration may be retried later or the page can be putback. +* +* TODO: migration core will treat both pages as folios and lock them before +* this call to unlock them after this call. Further, the folio refcounts on +* src and dst are also released by migration core. These pages will not be +* folios in the future, so that must be reworked. +* +* Returns MIGRATEPAGE_SUCCESS on success, otherwise a negative error +* code. +*/ +static int migrate_movable_ops_page (struct page *dst,struct page *src, +enum migrate_mode mode) +{ +int rc =MIGRATEPAGE_SUCCESS ; + +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); +if (rc ==MIGRATEPAGE_SUCCESS ) +ClearPageIsolated (src); +return rc; +} +/* * Put previously isolated pages back onto the appropriate lists * from where they were once taken off for compaction/migration.
@@ -1044,51 +1085,20 @@ static int move_to_new_folio(struct folio *dst, struct folio *src, mode); else rc =fallback_migrate_folio (mapping, dst, src, mode); - }else { -const struct movable_operations *mops; -/* -* In case of non-lru page, it could be released after -* isolation step. In that case, we shouldn't try migration. -*/ -VM_BUG_ON_FOLIO (!folio_test_isolated (src), src); -if (!folio_test_movable (src)) { - rc =MIGRATEPAGE_SUCCESS ; -folio_clear_isolated (src); +if (rc !=MIGRATEPAGE_SUCCESS ) goto out; - } - - mops =folio_movable_ops (src); - rc = mops->migrate_page (&dst->page, &src->page, mode); -WARN_ON_ONCE (rc ==MIGRATEPAGE_SUCCESS && - !folio_test_isolated (src)); - } - -/* -* When successful, old pagecache src->mapping must be cleared before -* src is freed; but stats require that PageAnon be left as PageAnon. -*/ -if (rc ==MIGRATEPAGE_SUCCESS ) { -if (__folio_test_movable (src)) { -VM_BUG_ON_FOLIO (!folio_test_isolated (src), src); - -/* -* We clear PG_movable under page_lock so any compactor -* cannot try to migrate this page. -*/ -folio_clear_isolated (src); - } -/* -* Anonymous and movable src->mapping will be cleared by -* free_pages_prepare so don't reset it here for keeping -* the type to work PageAnon, for example. +* For pagecache folios, src->mapping must be cleared before src +* is freed. Anonymous folios must stay anonymous until freed. */ -if (!folio_mapping_flags (src)) +if (!folio_test_anon (src)) src->mapping =NULL ;if (likely (!folio_is_zone_device (dst)))flush_dcache_folio (dst); + }else { + rc =migrate_movable_ops_page (&dst->page, &src->page, mode); } out:return rc;
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 2/3 mm/migrate: move movable_ops page handling out of move_to_new_folio()
From: David Hildenbrand <[email protected]>
[ Upstream commit be4a3e9c185264e9ad0fe02c1c5d81b8386bd50c ]
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)
Stable-dep-of: a2e0c0668a34 ("mm: migrate: requeue destination folio on deferred split queue")
--- mm/migrate.c | 63 +++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 33 deletions(-)
mm/migrate.c +30 -33
@@ -1047,11 +1047,12 @@ static int fallback_migrate_folio(struct address_space *mapping, }/* -* Move a page to a newly allocated page -* The page is locked and all ptes have been successfully removed. +* Move a src folio to a newly allocated dst folio. * -* The new page will have replaced the old page if this function -* is successful. +* The src and dst folios are locked and the src folios was unmapped from +* the page tables. +* +* On success, the src folio was replaced by the dst folio. * * Return value: * < 0 - error code
@@ -1060,34 +1061,30 @@ static int fallback_migrate_folio(struct address_space *mapping,static int move_to_new_folio (struct folio *dst,struct folio *src,enum migrate_mode mode) { +struct address_space *mapping =folio_mapping (src);int rc = -EAGAIN ; -bool is_lru = !__folio_test_movable (src);VM_BUG_ON_FOLIO (!folio_test_locked (src), src);VM_BUG_ON_FOLIO (!folio_test_locked (dst), dst); -if (likely (is_lru)) { -struct address_space *mapping =folio_mapping (src); - -if (!mapping) - rc =migrate_folio (mapping, dst, src, mode); -else if (mapping_inaccessible (mapping)) - rc = -EOPNOTSUPP ; -else if (mapping->a_ops->migrate_folio) -/* -* Most folios have a mapping and most filesystems -* provide a migrate_folio callback. Anonymous folios -* are part of swap space which also has its own -* migrate_folio callback. This is the most common path -* for page migration. -*/ - rc = mapping->a_ops->migrate_folio (mapping, dst, src, - mode); -else - rc =fallback_migrate_folio (mapping, dst, src, mode); +if (!mapping) + rc =migrate_folio (mapping, dst, src, mode); +else if (mapping_inaccessible (mapping)) + rc = -EOPNOTSUPP ; +else if (mapping->a_ops->migrate_folio) +/* +* Most folios have a mapping and most filesystems +* provide a migrate_folio callback. Anonymous folios +* are part of swap space which also has its own +* migrate_folio callback. This is the most common path +* for page migration. +*/ + rc = mapping->a_ops->migrate_folio (mapping, dst, src, + mode); +else + rc =fallback_migrate_folio (mapping, dst, src, mode); -if (rc !=MIGRATEPAGE_SUCCESS ) - goto out; +if (rc ==MIGRATEPAGE_SUCCESS ) {/* * For pagecache folios, src->mapping must be cleared before src * is freed. Anonymous folios must stay anonymous until freed.
@@ -1097,10 +1094,7 @@ static int move_to_new_folio(struct folio *dst, struct folio *src,if (likely (!folio_is_zone_device (dst)))flush_dcache_folio (dst); - }else { - rc =migrate_movable_ops_page (&dst->page, &src->page, mode); } -out:return rc; }
@@ -1351,20 +1345,23 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private,int rc;int old_page_state =0 ;struct anon_vma *anon_vma =NULL ; -bool is_lru = !__folio_test_movable (src);struct list_head *prev;__migrate_folio_extract (dst, &old_page_state, &anon_vma); prev = dst->lru.prev;list_del (&dst->lru); +if (unlikely (__folio_test_movable (src))) { + rc =migrate_movable_ops_page (&dst->page, &src->page, mode); +if (rc) + goto out; + goto out_unlock_both; + } + rc =move_to_new_folio (dst, src, mode);if (rc) goto out; -if (unlikely (!is_lru)) - goto out_unlock_both; -/* * When successful, push dst to LRU immediately: so that if it * turns out to be an mlocked page, remove_migration_ptes() will
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 3/3 mm: migrate: requeue destination folio on deferred split queue
In reply to Sasha LevinFrom: Usama Arif <[email protected]>
[ Upstream commit a2e0c0668a3486f96b86c50e02872c8e94fd4f9c ]
During folio migration, __folio_migrate_mapping() removes the source folio from the deferred split queue, but the destination folio is never re-queued. This causes underutilized THPs to escape the shrinker after NUMA migration, since they silently drop off the deferred split list.
Fix this by recording whether the source folio was on the deferred split queue and its partially mapped state before move_to_new_folio() unqueues it, and re-queuing the destination folio after a successful migration if it was.
By the time migrate_folio_move() runs, partially mapped folios without a pin have already been split by migrate_pages_batch(). So only two cases remain on the deferred list at this point:
1. Partially mapped folios with a pin (split failed).
2. Fully mapped but potentially underused folios. The recorded partially_mapped state is forwarded to deferred_split_folio() so that the destination folio is correctly re-queued in both cases.
Because THPs are removed from the deferred_list, THP shinker cannot split the underutilized THPs in time. As a result, users will show less free memory than before.
--- mm/migrate.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
mm/migrate.c +17 -0
@@ -1345,6 +1345,8 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private,int rc;int old_page_state =0 ;struct anon_vma *anon_vma =NULL ; +bool src_deferred_split = false; +bool src_partially_mapped = false;struct list_head *prev;__migrate_folio_extract (dst, &old_page_state, &anon_vma);
@@ -1358,6 +1360,12 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private, goto out_unlock_both; } +if (folio_order (src) >1 && + !data_race (list_empty (&src->_deferred_list))) { + src_deferred_split = true; + src_partially_mapped =folio_test_partially_mapped (src); + } + rc =move_to_new_folio (dst, src, mode);if (rc) goto out;
@@ -1378,6 +1386,15 @@ static int migrate_folio_move(free_folio_t put_new_folio, unsigned long private,if (old_page_state &PAGE_WAS_MAPPED )remove_migration_ptes (src, dst,0 ); +/* +* Requeue the destination folio on the deferred split queue if +* the source was on the queue. The source is unqueued in +* __folio_migrate_mapping(), so we recorded the state from +* before move_to_new_folio(). +*/ +if (src_deferred_split) +deferred_split_folio (dst, src_partially_mapped); + out_unlock_both:folio_unlock (dst);set_page_owner_migrate_reason (&dst->page, reason);
Signature · 1 line
2.53.0