From: Qu Wenruo <wqu@suse.com>
To: Pedro Falcato <pfalcato@suse.de>
Cc: Brahmajit Das <listout@listout.xyz>,
dsterba@suse.com, linux-btrfs@vger.kernel.org, clm@fb.com,
mason@kernel.org, david@kernel.org, jgg@ziepe.ca,
jhubbard@nvidia.com, peterx@redhat.com, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com,
Brahmajit Das <bdas@suse.de>,
syzbot+d6f123d4060990f0f3ff@syzkaller.appspotmail.com,
willy@infradead.org, jack@suse.cz, hch@lst.de
Subject: Re: [PATCH v2] btrfs: re-attach folio private when a released folio gets dirtied
Date: Sat, 5 Dec 2026 07:35:03 +1030 [thread overview]
Message-ID: <c2e37660-b33f-4c31-b5cd-268ca20ea167@suse.com> (raw)
In-Reply-To: <axKGJtCg4ZrHlqqA@pedro-suse.tail5790ac.ts.net>
在 2026/12/4 20:35, Pedro Falcato 写道:
> +CC willy, jack, hch
>
> On Fri, Dec 04, 2026 at 07:13:08AM +1030, Qu Wenruo wrote:
>>
>>
>> 在 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@suse.de/.
>>> (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.
>
> This is, strictly speaking, a bug. Per Documentation/filesystems/locking.rst:
>
> locking rules:
> All except dirty_folio and free_folio may block
>
> I think currently, de facto, it's not very likely to be hit[1]. Mostly because,
> for writenotify filesystems/VMAs, you'll always trip over ->page_mkwrite()
> (marking the folio dirty), and cleaning will always write-protect it before
> clearing the dirty flag off the folio.
>
> [1] I _think_ there are ways to hit it, if you go down funky folio_cancel_dirty()
> paths.
>
>>
>>>
>>>>
>>>> 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.
>
> Why would you not rely on truncation itself to invalidate it?
The truncation did try to invalidate the folio, by even removing the
folio private.
But the folio can not be removed from filemap because it's pinned by the
direct IO.
Did you mean we just skip the write, and let future truncation to
invalidate it again?
That also feels a little weird, yes the folio will eventually be
truncated when evicting the inode, but still doesn't feel so correct.
And this also means, we need to manually copy the invalidating handling
to release reserved space, just not try to detach the private.
I guess for now, following the not-so-correct iomap behavior is the most
simple solution from the perspective of fs, but it still leave a pretty
bad taste.
>
>>
>> Or is there any better solution from the perspective of MM?
>
> My understanding is that the truncation logic should correctly handle
> the semantics you want.
>
> As for the GUP problem, yes, this is yet another issue. It is known.
> ->dirty_folio() implementations cannot assume the memory allocation will
> succeed. And there's no possible fallback to "failure to dirty a folio".
>
> The real solution (in my series) is to simply not discard this at-will.
> invalidate_folio() seems to be yet another variant of this issue.
>
> For what it's worth, I observed a similar issue in mm/truncate code. I don't
> know what the correct approach would be. Keep the private around for GUP pins?
> Reject the truncate altogether?
>
> (I don't think it's possible to do this last option; keeping the private is
> also weird, and I don't see how you can possibly ditch it after the folio is
> orphaned)
I had a not-so-good idea, that will require invalidate_folio() callback
to be split into two parts:
- invalidate_folio_fs()
The usual fs specific part.
- invalidate_folio_detach()
The private detaching part.
The second part is only called after the folio is properly removed from
the filemap.
So this ensures all folios in the filemap still have their private attached.
But again, I'm not an expert in MM. So this can just be a stupid idea
and can conflict with other things like large folio splitting.
Thanks,
Qu
next prev parent reply other threads:[~2026-12-04 21:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 4:18 [PATCH v2] btrfs: re-attach folio private when a released folio gets dirtied Brahmajit Das
2026-12-03 13:28 ` Pedro Falcato
2026-12-03 20:43 ` Qu Wenruo
2026-12-04 10:05 ` Pedro Falcato
2026-12-04 12:48 ` Brahmajit Das
2026-12-04 21:05 ` Qu Wenruo [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-12-02 4:11 Brahmajit Das
2026-12-02 4:08 Brahmajit Das
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=c2e37660-b33f-4c31-b5cd-268ca20ea167@suse.com \
--to=wqu@suse.com \
--cc=bdas@suse.de \
--cc=clm@fb.com \
--cc=david@kernel.org \
--cc=dsterba@suse.com \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=jgg@ziepe.ca \
--cc=jhubbard@nvidia.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=listout@listout.xyz \
--cc=mason@kernel.org \
--cc=peterx@redhat.com \
--cc=pfalcato@suse.de \
--cc=syzbot+d6f123d4060990f0f3ff@syzkaller.appspotmail.com \
--cc=syzkaller-bugs@googlegroups.com \
--cc=willy@infradead.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