[RFC PATCH 07/10] mm/migrate: no filesystem reclaim under the batch's folio locks

From: Daniel Byrne

Date: Tue Dec 01 2026 - 09:20:06 EST


migrate_offload_batch_copy() calls the provider with the folios of the
batch locked. A provider may allocate there. An allocation that enters
filesystem reclaim can prune an inode whose truncate then waits for one
of those folios, and the migration waits for the allocation.

Call the provider in a memalloc_nofs_save() scope.

This is a fix to "mm/migrate: add copy offload registration
infrastructure" and is meant to be folded into it.

Signed-off-by: Daniel Byrne <daniel1.byrne@xxxxxxxxx>
---
A fix to patch 3. For folding into v7.

mm/migrate_copy_offload.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/mm/migrate_copy_offload.c b/mm/migrate_copy_offload.c
index 335db8e80556..3d0784a8f047 100644
--- a/mm/migrate_copy_offload.c
+++ b/mm/migrate_copy_offload.c
@@ -6,6 +6,7 @@
#include <linux/migrate_copy_offload.h>
#include <linux/mm.h>
#include <linux/module.h>
+#include <linux/sched/mm.h>
#include <linux/slab.h>
#include <linux/srcu.h>
#include <linux/static_call.h>
@@ -121,11 +122,19 @@ EXPORT_SYMBOL_GPL(migrate_offload_reason_mask_format);
int migrate_offload_batch_copy(struct list_head *dst_batch,
struct list_head *src_batch, unsigned int nr_batch)
{
+ unsigned int nofs;
int idx, rc;

+ /*
+ * The batch's folios are locked. An allocation of the provider's
+ * that reclaims could prune an inode whose truncate then waits for
+ * one of them: no filesystem reclaim from here.
+ */
+ nofs = memalloc_nofs_save();
idx = srcu_read_lock(&migrate_offload_srcu);
rc = static_call(migrate_offload_batch_copy_fn)(dst_batch, src_batch, nr_batch);
srcu_read_unlock(&migrate_offload_srcu, idx);
+ memalloc_nofs_restore(nofs);
return rc;
}

--
2.43.0