Re: [PATCH 2/2] mm: memfd_luo: always dirty all folios
From: Pratyush Yadav
Date: Thu Mar 05 2026 - 03:46:27 EST
Hi Mike,
On Wed, Feb 25 2026, Mike Rapoport wrote:
> On Mon, Feb 23, 2026 at 06:39:29PM +0100, Pratyush Yadav wrote:
[...]
>> - if (folio_test_dirty(folio))
>> - flags |= MEMFD_LUO_FOLIO_DIRTY;
>> + /*
>> + * A dirty folio is one which has been written to. A clean folio
>> + * is its opposite. Since a clean folio does not carry user
>> + * data, it can be freed by page reclaim under memory pressure.
>> + *
>> + * Saving the dirty flag at prepare() time doesn't work since it
>> + * can change later. Saving it at freeze() also won't work
>> + * because the dirty bit is normally synced at unmap and there
>> + * might still be a mapping of the file at freeze().
>> + *
>> + * To see why this is a problem, say a folio is clean at
>> + * preserve, but gets dirtied later. The pfolio flags will mark
>> + * it as clean. After retrieve, the next kernel might try to
>> + * reclaim this folio under memory pressure, losing user data.
>> + *
>> + * Unconditionally mark it dirty to avoid this problem. This
>> + * comes at the cost of making clean folios un-reclaimable after
>> + * live update.
>> + */
>
> Can we make the comment here shorter to only contain the gist of the issue?
Is this any better? Or should I try to make it shorter still?
/*
* Tracking the dirty flag of the folio is difficult since it is
* normally synced at unmap and there might still be mappings of
* the file alive.
*
* Not tracking it correctly can cause a dirty folio to be
* restored as clean after KHO. The next kernel might then try
* to reclaim it, losing user data.
*
* Unconditionally mark the folio dirty to avoid this. This
* comes at the cost of making clean folios un-reclaimable.
*/
[...]
--
Regards,
Pratyush Yadav