Re: [PATCH 2/2] mm: memfd_luo: always dirty all folios
From: Mike Rapoport
Date: Thu Mar 05 2026 - 05:46:10 EST
On Thu, Mar 05, 2026 at 09:44:27AM +0100, Pratyush Yadav wrote:
> 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?
Yep, thanks! :)
I don't think it can be made shorter without loosing information. What we
might do is to add a larger comment in what state we preserve folios on top
of memfd_luo_preserve_folios() and leave the code inside the function
alone. Can't say I have strong feelings about it.
> /*
> * 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
--
Sincerely yours,
Mike.