RE: [PATCH] mm/migrate: drop the fault lock and wait killably for migration entries
From: 차준호
Date: Tue Nov 17 2026 - 19:37:22 EST
Hi David, Lorenzo,
Yes to both. I came across it while prototyping and only reproduced it
with artificial delays in move_pages() and test_hmm; it was not hit in
production. An LLM assistant wrote most of the code and the changelog,
and I should have said so in the patch. Sorry about that.
Understood on the migration rework. I'll drop this patch.
Thanks,
Junho
-----Original Message-----
From: David Hildenbrand (Arm) <david@xxxxxxxxxx>
Sent: Tuesday, November 17, 2026 6:46 PM
To: 차준호 <junho.cha@xxxxxxxxx>; Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx>
Cc: Matthew Wilcox (Oracle) <willy@xxxxxxxxxxxxx>; Jan Kara <jack@xxxxxxx>; Zi Yan <ziy@xxxxxxxxxx>; Alistair Popple <apopple@xxxxxxxxxx>; Matthew Brost <matthew.brost@xxxxxxxxx>; Thomas Hellström <thomas.hellstrom@xxxxxxxxxxxxxxx>; Lorenzo Stoakes <ljs@xxxxxxxxxx>; Liam R. Howlett <liam@xxxxxxxxxxxxx>; Vlastimil Babka <vbabka@xxxxxxxxxx>; Mike Rapoport <rppt@xxxxxxxxxx>; Suren Baghdasaryan <surenb@xxxxxxxxxx>; Michal Hocko <mhocko@xxxxxxxx>; linux-mm@xxxxxxxxx; linux-kernel@xxxxxxxxxxxxxxx
Subject: Re: [PATCH] mm/migrate: drop the fault lock and wait killably for migration entries
On 11/17/26 10:26, Junho Cha via B4 Relay wrote:
> From: Junho Cha <junho.cha@xxxxxxxxx>
>
> A fault that finds a migration entry sleeps in
> softleaf_entry_wait_on_locked() until the entry goes away. So does a
> fault on a device-private entry whose folio is locked by another
> thread, since commit b570f37a2ce4 ("mm: Fix a hmm_range_fault()
> livelock / starvation problem"). The wait is in TASK_UNINTERRUPTIBLE
> and keeps the mmap_lock or per-VMA lock held throughout.
>
> That is fine while a migration takes microseconds. It is not when the
> migration is slow:
>
> - The wait cannot be killed. The signal_pending_state() check in the
> wait loop never fires, because TASK_UNINTERRUPTIBLE contains neither
> TASK_INTERRUPTIBLE nor TASK_WAKEKILL. For example, if the
> migrate_to_ram() handler of a device-private folio waits for a
> device that has stalled, every other thread that faults on the page
> sits in D state, and the only symptom is a hung task warning.
>
> - The fault lock is held across the wait. This matters when the
> migration itself runs without that lock, as for move_pages(),
> compaction or memory offlining. A writer that arrives in the
> meantime, such as munmap() of another page in the same VMA, waits
> for the migration to finish, and faults that come after the writer
> queue behind it. migrate_to_ram() is called with the fault lock
> held, so for device-private folios only the first point applies.
>
> Making the wait killable alone is not enough. A fault that returns 0
> is retried, so a kernel-mode fault from a uaccess routine would fault
> again on the same entry, return at once because the signal is still
> pending, and spin until the migration completes. The fault has to
> return VM_FAULT_RETRY so that fault_signal_pending() can end it.
>
> Handle the fault lock the way __folio_lock_or_retry() does. Pass the
> vm_fault to softleaf_entry_wait_on_locked() from do_swap_page(). On
> the first attempt of a retryable fault, drop the fault lock before
> sleeping and return VM_FAULT_RETRY, or return at once for
> FAULT_FLAG_RETRY_NOWAIT. A FAULT_FLAG_KILLABLE fault sleeps in
> TASK_KILLABLE, and if a fatal signal ends a wait that still holds the
> lock, drop it and return VM_FAULT_RETRY.
>
> Dropping the lock there is safe. The wait entry is queued before the
> ptl is released, and the entry can only be removed under that ptl, so
> no wake up is missed. Nothing after that uses the vma, and
> folio_waitqueue() points into a global hash table, not into the folio.
>
> Callers outside the fault path (hmm, userfaultfd, huge_memory) and the
> PMD and hugetlb waits pass NULL and keep the current behaviour.
>
> Tested by holding the migration entries for 8 seconds, with a delay
> added after the unmap step of move_pages() and in test_hmm's
> migrate_to_ram():
>
> - SIGKILL to a process waiting on the entry, from user mode or from a
> write() that copies from the page, ends it within a millisecond
> instead of after the migration. The same holds for a thread waiting
> on a device-private folio.
> - munmap() of another page in the same VMA no longer waits for the
> migration.
> - Without a signal, the write() completes after the migration with
> the right data, using under a millisecond of system time.
> - hmm-tests results are unchanged, and lockdep reports nothing.
>
> Signed-off-by: Junho Cha <junho.cha@xxxxxxxxx>
> ---
Hi,
I assume
* this was not hit in the wild but found with an LLM.
* Most of the code and patch description were written with an LLM.
Correct?
--
Cheers,
David