Re: [PATCH 21/32] mm/migrate_device: mark folios leaving device memory dirty
From: David Hildenbrand (Arm)
Date: Wed Dec 02 2026 - 10:35:32 EST
On 12/2/26 05:15, Alistair Popple wrote:
> On 2026-11-29 at 21:06 +1100, "David Hildenbrand (Arm)" <david@xxxxxxxxxx> wrote...
>> Device-private page table entries are weird: they are non-present page
>> table entries, and the device can write to the memory without the CPU
>> noticing or the CPU page tables reflecting it.
>
> However the device itself could know.
Right.
>
>> So there is no dirty bit on the PTE we could sync to the folio. And
>> usually, nobody cares about the dirty bit for these folios, as these
>> folios are not on the LRU. Device-coherent memory has the same problem:
>> it is mapped through present PTEs, but the device writes through its own
>> page tables and does not set the PTE dirty bit.
>>
>> There is one problem, though: when we migrate such a clean folio back
>> to system RAM, the new folio will be clean, and will be mapped through
>> clean PTEs.
>
> Unless the driver marks it dirty before finalizing migration. So this could
> be part of the driver contract - it has to copy a dirty flag into the folio if
> the page might be dirty. Of course no driver I looked at actually does that, so
> until such a driver comes along I think this fix is fine.
Yeah. But the question is also what it buys us. ZONE_DEVICE doesn't really need
the dirty flag. It's only relevant once we move back to anon memory ... so any
such change would need a proper motivation in why we should care.
Thanks a lot for the review!
--
Cheers,
David