From: Mike Rapoport <rppt@kernel.org>
To: Pratyush Yadav <pratyush@kernel.org>
Cc: Pasha Tatashin <pasha.tatashin@soleen.com>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
stable@vger.kernel.org
Subject: Re: [PATCH 2/2] mm: memfd_luo: always dirty all folios
Date: Wed, 25 Feb 2026 10:58:34 +0200 [thread overview]
Message-ID: <aZ65uvOrTDndpic6@kernel.org> (raw)
In-Reply-To: <20260223173931.2221759-3-pratyush@kernel.org>
On Mon, Feb 23, 2026 at 06:39:29PM +0100, Pratyush Yadav wrote:
> From: "Pratyush Yadav (Google)" <pratyush@kernel.org>
>
> A dirty folio is one which has been written to. A clean folio is its
> opposite. Since a clean folio has no user data, it can be freed under
> memory pressure.
>
> memfd preservation with LUO saves the flag at preserve(). This is
> problematic. The folio might get dirtied later. Saving it at freeze()
> also doesn't work, since the dirty bit from PTE is normally synced at
> unmap and there might still be mappings of the file at freeze().
>
> To see why this is a problem, say a folio is clean at preserve, but gets
> dirtied later. The serialized state of the folio will mark it as clean.
> After retrieve, the next kernel will see the folio as clean and might
> try to reclaim it under memory pressure. This will result in losing user
> data.
>
> Mark all folios of the file as dirty, and always set the
> MEMFD_LUO_FOLIO_DIRTY flag. This comes with the side effect of making
> all clean folios un-reclaimable. This is a cost that has to be paid for
> participants of live update. It is not expected to be a common use case
> to preserve a lot of clean folios anyway.
>
> Since the value of pfolio->flags is a constant now, drop the flags
> variable and set it directly.
>
> Fixes: b3749f174d68 ("mm: memfd_luo: allow preserving memfd")
> Cc: stable@vger.kernel.org
> Signed-off-by: Pratyush Yadav (Google) <pratyush@kernel.org>
Reviewed-by: Mike Rapoport (Microsoft) <rppt@kernel.org>
> ---
> mm/memfd_luo.c | 26 +++++++++++++++++++++-----
> 1 file changed, 21 insertions(+), 5 deletions(-)
>
> diff --git a/mm/memfd_luo.c b/mm/memfd_luo.c
> index ccbf1337f650..9eac02d06b5a 100644
> --- a/mm/memfd_luo.c
> +++ b/mm/memfd_luo.c
> @@ -146,7 +146,6 @@ static int memfd_luo_preserve_folios(struct file *file,
> for (i = 0; i < nr_folios; i++) {
> struct memfd_luo_folio_ser *pfolio = &folios_ser[i];
> struct folio *folio = folios[i];
> - unsigned int flags = 0;
>
> err = kho_preserve_folio(folio);
> if (err)
> @@ -154,8 +153,26 @@ static int memfd_luo_preserve_folios(struct file *file,
>
> folio_lock(folio);
>
> - 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?
> + folio_mark_dirty(folio);
>
> /*
> * If the folio is not uptodate, it was fallocated but never
> @@ -174,12 +191,11 @@ static int memfd_luo_preserve_folios(struct file *file,
> flush_dcache_folio(folio);
> folio_mark_uptodate(folio);
> }
> - flags |= MEMFD_LUO_FOLIO_UPTODATE;
>
> folio_unlock(folio);
>
> pfolio->pfn = folio_pfn(folio);
> - pfolio->flags = flags;
> + pfolio->flags = MEMFD_LUO_FOLIO_DIRTY | MEMFD_LUO_FOLIO_UPTODATE;
> pfolio->index = folio->index;
> }
>
> --
> 2.53.0.371.g1d285c8824-goog
>
--
Sincerely yours,
Mike.
prev parent reply other threads:[~2026-02-25 8:58 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-23 17:39 [PATCH 0/2] mm: memfd_luo: fixes for folio flag preservation Pratyush Yadav
2026-02-23 17:39 ` [PATCH 1/2] mm: memfd_luo: always make all folios uptodate Pratyush Yadav
2026-02-25 8:53 ` Mike Rapoport
2026-02-23 17:39 ` [PATCH 2/2] mm: memfd_luo: always dirty all folios Pratyush Yadav
2026-02-25 8:58 ` Mike Rapoport [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aZ65uvOrTDndpic6@kernel.org \
--to=rppt@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=pasha.tatashin@soleen.com \
--cc=pratyush@kernel.org \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox