Skip to content

RFC mm/migrate: wait for folio refcount during longterm pin migration

John Hubbard linux-mm lkml 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest2 patches 8 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/2mm: wake up folio refcount waiters on folio_put()include/linux/mm.h mm/swap.c+17 -10 replies
2/2mm/migrate: wait for folio refcount during longterm pin migrationmm/migrate.c+30 -03 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH 0/2] mm/migrate: wait for folio refcount during longterm pin migration

Hi,

This adds a bounded sleep to migration so that FOLL_LONGTERM pinning can wait for transient folio references to drain, instead of failing after a fixed number of retries. The wait uses a one-second timeout. An alternative approach would be to call wait_var_event_killable() with no timeout, but that doesn't match as well with migration's "this will probably work" API. In other words, a short sleeping wait is more appropriate here.

When migrating pages for FOLL_LONGTERM pinning, migration can fail with -EAGAIN if a folio has unexpected references. These references are often transient, but the current retry loop gives up too quickly. This series adds wait_var_event_timeout() at the retry points, paired with wake_up_var() in folio_put() to wake the sleeper as soon as the refcount drops.

The wake_up_var() calls in folio_put() are gated behind a static key, disabled by default, so non-migration workloads pay zero cost. migrate_pages() enables the key on entry when the reason is MR_LONGTERM_PIN, and disables it on exit.

Toggling the key is not free. folio_put() is static inline, so every compilation unit that calls it gets its own patch site (roughly 500 in vmlinux, plus modules). On x86, jump label patching is batched (256 sites per batch, 3 IPI rounds per batch), so enabling the key costs 6-9 IPI broadcasts, a few hundred microseconds on a large machine. That cost is paid twice per migrate_pages() call. Migration itself spends several milliseconds per batch on LRU isolation, TLB flushes, and page copies. Concurrent longterm-pin migrations after the first just do an atomic_inc (no patching).

Matthew Brost offered to performance-test this series [1], as Intel has tests that stress migration and good metrics to catch regressions.

[1] https://lore.kernel.org/all/[email protected]/

John Hubbard (2):
mm: wake up folio refcount waiters on folio_put() mm/migrate: wait for folio refcount during longterm pin migration

 include/linux/mm.h |  8 ++++++++
 mm/migrate.c       | 30 ++++++++++++++++++++++++++++++
 mm/swap.c          | 10 +++++++++-
 3 files changed, 47 insertions(+), 1 deletion(-)

base-commit: 9a9c8ce300cd3859cc87b408ef552cd697cc2ab7

Signature · 1 line
2.53.0