Skip to contentSkip to conversation

mm: migrate: requeue destination folio on deferred split queue

PATCH Applied Usama Arif 6 participants 10 messages Mar 12 – Mar 20

Subsystems (3)
lore
Share & tools
lore

Usama Arif

author
#0 lore raw

PATCH v3 1/1 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.

---
v2 -> v3:
- Remove redundant folio_test_large_rmappable() check (David).
- Check order > 1 (replaced folio_test_large()) (Wei Yang)

---
 mm/migrate.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
mm/migrate.c +17 -0
index ece77ccb2ec0..f5169a9f8f24 100644
@@ -1360,6 +1360,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);
@@ -1373,6 +1375,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;
@@ -1393,6 +1401,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);
Signature · 1 line
2.52.0
Acked-by on v3 1/1
#1 lore raw
Quoted 18 lines · Usama Arif

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.

Quoted 5 lines
Acked-by on v3 1/1
#2 lore raw
In reply to Usama Arif
Quoted 18 lines · On Thu, 12 Mar 2026 03:47:23 -0700 Usama Arif <[email protected]> wrote:

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.

Quoted 2 lines
Fixes dafff3f4c850 ("mm: split underused THPs")

Seems the commit is merged in 6.12. And I assume the user impact on THP-shrinker enabled systems is visible. If so, should we Cc stable@ ?

Quoted 3 lines

Thanks,
SJ

[...]

maintainer
#3 lore raw
Quoted 8 lines · On Thu, 12 Mar 2026 17:16:30 -0700 SeongJae Park <[email protected]> wrote:
Quoted 8 lines

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.

Quoted 5 lines
Quoted 2 lines
Fixes dafff3f4c850 ("mm: split underused THPs")

Seems the commit is merged in 6.12. And I assume the user impact on THP-shrinker enabled systems is visible. If so, should we Cc stable@ ?

I think the user impact should be visible to backport, but the changelog is elusive on details?

author
#4 lore raw
Quoted 10 lines · Andrew Morton
Quoted 8 lines · On Thu, 12 Mar 2026 17:16:30 -0700 SeongJae Park <[email protected]> wrote:
Quoted 8 lines

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.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
Fixes dafff3f4c850 ("mm: split underused THPs")

Seems the commit is merged in 6.12. And I assume the user impact on THP-shrinker enabled systems is visible. If so, should we Cc stable@ ?

I think the user impact should be visible to backport, but the changelog is elusive on details?

The original patches added THPs to deferred_list at fault/collapse, they got removed but not added back to the list after migration. This patch adds them to the deferred_list on migration. The user would not expect the THPs to get removed from deferred_list on migration, so this fixes user expectations.

I have CC-ed [email protected] to this email. Should I resend the patch with CC stable in commit message?

maintainer
#5 lore raw
Quoted 24 lines · On Fri, 13 Mar 2026 13:40:29 +0300 Usama Arif <[email protected]> wrote:
Quoted 10 lines · Andrew Morton
Quoted 8 lines · On Thu, 12 Mar 2026 17:16:30 -0700 SeongJae Park <[email protected]> wrote:
Quoted 8 lines

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.

Quoted 9 lines
Quoted 5 lines
Quoted 2 lines
Fixes dafff3f4c850 ("mm: split underused THPs")

Seems the commit is merged in 6.12. And I assume the user impact on THP-shrinker enabled systems is visible. If so, should we Cc stable@ ?

I think the user impact should be visible to backport, but the changelog is elusive on details?

Quoted 5 lines

The original patches added THPs to deferred_list at fault/collapse, they got removed but not added back to the list after migration. This patch adds them to the deferred_list on migration. The user would not expect the THPs to get removed from deferred_list on migration, so this fixes user expectations.

Maybe users just won't notice?

If we can't identify any benefit to userspace then I don't think this patch meets the criteria for backporting.

Quoted 2 lines

I have CC-ed [email protected] to this email. Should I resend the patch with CC stable in commit message?

That's OK, I update changelogs. A lot.

#6 lore raw
Quoted 26 lines · On Sat, 14 Mar 2026 15:40:42 -0700 Andrew Morton <[email protected]>…
Quoted 24 lines · On Fri, 13 Mar 2026 13:40:29 +0300 Usama Arif <[email protected]> wrote:
Quoted 19 lines · Andrew Morton
Quoted 8 lines · On Thu, 12 Mar 2026 17:16:30 -0700 SeongJae Park <[email protected]> wrote:
Quoted 8 lines

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.

Quoted 5 lines
Quoted 2 lines
Fixes dafff3f4c850 ("mm: split underused THPs")

Seems the commit is merged in 6.12. And I assume the user impact on THP-shrinker enabled systems is visible. If so, should we Cc stable@ ?

I think the user impact should be visible to backport, but the changelog is elusive on details?

Quoted 7 lines
Quoted 5 lines

The original patches added THPs to deferred_list at fault/collapse, they got removed but not added back to the list after migration. This patch adds them to the deferred_list on migration. The user would not expect the THPs to get removed from deferred_list on migration, so this fixes user expectations.

Maybe users just won't notice?

My guess of the user-visible consequence was like following. 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. I believe I might be wrong and Usama can correct me in the case.

Thanks,
SJ

[...]

maintainer
#7 lore raw
Quoted 3 lines · On Sat, 14 Mar 2026 17:05:54 -0700 SeongJae Park <[email protected]> wrote:

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.

That'll do, thanks ;)

Pasted, added cc:stable. It's been there since 6.12 so I don't see a need to rush this in, so I won't move this into mm-hotfixes - it'll go into mainline for 7.1-rc1 after which -stable should pick it up.

#8 lore raw
Quoted 11 lines · Andrew Morton
Quoted 3 lines · On Sat, 14 Mar 2026 17:05:54 -0700 SeongJae Park <[email protected]> wrote:

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.

That'll do, thanks ;)

Pasted, added cc:stable. It's been there since 6.12 so I don't see a need to rush this in, so I won't move this into mm-hotfixes - it'll go into mainline for 7.1-rc1 after which -stable should pick it up.

Makes sense. I guess using the partially-mapped is only a slight problem, because we usually try to split partially-mapped before migrating.

So it's mostly about over-allocated THPs (mostly 0) not getting scanned and split+reclaimed after they were migrated.

Under memory pressure without swap, that might create a user-visible problem, especially when many such THPs are migrated before being scanned for zeropages that can be reclaimed.

Signature · 3 lines
Cheers,

David
Reviewed-by on v3 1/1
#9 lore raw
In reply to Usama Arif
Quoted 18 lines · Usama Arif

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.

Quoted 5 lines

LGTM, thanks.

Signature · 2 lines
Wei Yang
Help you, Help me