Re: [PATCH v2] btrfs: re-attach folio private when a released folio gets dirtied
From: Qu Wenruo
Date: Thu Dec 03 2026 - 15:43:24 EST
在 2026/12/3 23:58, Pedro Falcato 写道:
[...]
When the read completes, the folio is re-dirtied without notifying the
fs:
bio_release_pages()
folio_mark_dirty()
btrfs_data_dirty_folio()
filemap_dirty_folio()
FWIW, this sounds like a variant of
https://lore.kernel.org/linux-mm/20261119-gup-dirty-what-v1-0-236d69f25c24@xxxxxxx/.
(which I will respin soon)
One assumption doesn't meet the current code.
> - ->dirty_folio() relies on buffers/IFS/etc being attached to the
> folios. It _cannot_ attach them itself, as dirty_folio() cannot
> block.
Iomap is already attaching it:
iomap_dirty_folio()
ifs_alloc(inode, folio, 0);
gfp = GFP_NOFS | __GFP_NOFAIL;
ifs = kzalloc_flex(..., gfp);
Either it's already a bug, or we won't hit such folio without private for the non-sleeping routes.
If the folio is beyond EOF by then, btrfs_data_dirty_folio() does not
touch any btrfs state, and the next writeback calls folio_invalidate()
on a folio without private, triggering the above ASSERT() in the
? why is writeback calling folio_invalidate()?
If a folio is beyond EOF, we have no need to write it, thus can go invalidating it directly.
Or is there any better solution from the perspective of MM?
Thanks,
Qu
bs < folio size case. If the folio straddles EOF,
btrfs_folio_set_fixup_dirty() dereferences the NULL folio private
instead.
Fix it by re-attaching the folio private in btrfs_data_dirty_folio()
if it is missing. ->dirty_folio() may not block, so use GFP_NOWAIT.
NAK to this approach. I need to think about folio_invalidate() and its
interaction with GUP a little harder.