From: Matthew Wilcox <willy@infradead.org>
To: Boris Burkov <boris@bur.io>
Cc: Pedro Falcato <pfalcato@suse.de>, Christoph Hellwig <hch@lst.de>,
Jann Horn <jannh@google.com>, David Howells <dhowells@redhat.com>,
John Hubbard <jhubbard@nvidia.com>, Jan Kara <jack@suse.cz>,
Rik van Riel <riel@surriel.com>, Qu Wenruo <wqu@suse.com>,
"Darrick J. Wong" <djwong@kernel.org>,
linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org,
linux-mm@kvack.org, linux-xfs@vger.kernel.org
Subject: Re: Removing ->dirty_folio
Date: Tue, 25 Aug 2026 20:47:03 +0100 [thread overview]
Message-ID: <ao3xN89JJoAqwt52@casper.infradead.org> (raw)
In-Reply-To: <20260824212727.GA3664690@zen.localdomain>
On Mon, Aug 24, 2026 at 02:27:27PM -0700, Boris Burkov wrote:
> On Mon, Aug 24, 2026 at 08:08:06PM +0100, Matthew Wilcox wrote:
> > I think it's time to remove folio_mark_dirty(), ->dirty_folio() and so on.
> >
> > This is not how filesystems want to be informed of folio dirtying.
> > It was fine for ext2, but anything that's journalled or COW has work
> > to do before the folio is made dirty, and it's hard to do that work
> > under the page table spinlock (not all callers hold that lock, but the
> > filesystem has to be able to handle the cases where it is.
> >
> > Filesystems want the page_mkwrite() entry point to be how they find out
> > about a folio being dirtied -- and that works great! Except that we
> > can writeback the folio for a number of reasons. If it's been dirtied
> > due to a shared writable mmap, that's fine; we map the folio read-only
> > and any subsequent writes will re-enter the page_mkwrite path.
>
> Can you elaborate on this part a bit more? I can't tell if you are
> proposing a change or saying the existing behavior is fine if we drop
> ->dirty_folio(). I am also confused about exactly what sort of folio
> dirtying you are referring to. Sorry if I am being obtuse.
Sorry for not being clearer. This is what happens today. We first
tell the FS that we're going to write to the page through
page_mkwrite(), then we transfer the dirty bit from the PTE to
the folio through ->dirty_folio() ... but it's already there, thanks
to the call to page_mkwrite()!
> When I was recently adding ->dirty_folio() to btrfs, one of the main
> cases was the call to folio_mark_dirty() that came via
> __iomap_dio_bio_end_io() calling bio_check_pages_dirty() which schedules
> bio_dirty_fn(). (i.e., completion of a dio read into a shared mmap)
>
> Is that the case you are referring to here, or are you referring to
> someone just modifying a byte they faulted in from a shared mmap? The
> latter I would expect to have called page_mkwrite in the fault and done
> fs-specific work, so I assume it's the former that you are referring to?
Right. The former, I _believe_ already calls page_mkwrite() today, and so
the call to dirty_folio() is redundant. Except if writeback came in
while the I/O was in progress. So if we preserve the dirty bit for
pinned pages in the writeback code, the caall to dirty_folio() will
always be redundant and can be removed.
> Either way, I do believe that for the dio read endio case pinning is not
> involved and btrfs relies on the ->dirty_folio() call, so I think
> something would need to be done about that case too.
I traced that code path down into iov_iter_extract_user_pages() which
calls pin_user_pages_fast(), so I do think the pages you're talking
about are pinned and would be handled through page_mkwrite() already.
iomap_dio_rw
__iomap_dio_rw
iomap_dio_iter
iomap_dio_bio_iter
iomap_dio_bio_iter_one
bio_iov_iter_get_pages
iov_iter_extract_bvecs
iov_iter_extract_pages
iov_iter_extract_user_pages
> I believe you saw this patch since it was your idea for us to use
> ->dirty_folio(), but just for reference for anyone else who didn't see
> it, the btrfs patch adding ->dirty_folio():
> https://lore.kernel.org/linux-btrfs/69d0043e0f6a3d17048dfde857127ab0bf331154.1785190866.git.boris@bur.io/
Yes, I want you to be able to revert that patch ;-)
>
next prev parent reply other threads:[~2026-08-25 19:47 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-24 19:08 Removing ->dirty_folio Matthew Wilcox
2026-08-24 19:25 ` John Hubbard
2026-08-24 19:43 ` Matthew Wilcox
2026-08-24 19:51 ` John Hubbard
2026-08-24 21:05 ` Matthew Wilcox
2026-08-25 7:59 ` Pedro Falcato
2026-08-24 19:33 ` Rik van Riel
2026-08-25 8:21 ` David Hildenbrand (Arm)
2026-08-24 21:27 ` Boris Burkov
2026-08-25 19:47 ` Matthew Wilcox [this message]
2026-08-24 22:38 ` Qu Wenruo
2026-08-25 19:26 ` Matthew Wilcox
2026-08-25 22:33 ` Qu Wenruo
2026-08-26 4:53 ` Christoph Hellwig
2026-08-26 8:01 ` Christoph Hellwig
2026-08-25 6:48 ` David Howells
2026-08-25 19:16 ` Matthew Wilcox
2026-08-25 7:39 ` Christoph Hellwig
2026-08-25 19:14 ` Matthew Wilcox
2026-08-25 8:25 ` Pedro Falcato
2026-08-25 18:35 ` Matthew Wilcox
2026-08-26 7:54 ` Christoph Hellwig
2026-08-25 19:35 ` Jann Horn
2026-08-25 19:54 ` Matthew Wilcox
2026-08-25 20:06 ` Jann Horn
2026-08-26 0:02 ` Matthew Wilcox
2026-08-26 5:07 ` Christoph Hellwig
2026-08-26 7:42 ` Christoph Hellwig
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=ao3xN89JJoAqwt52@casper.infradead.org \
--to=willy@infradead.org \
--cc=boris@bur.io \
--cc=dhowells@redhat.com \
--cc=djwong@kernel.org \
--cc=hch@lst.de \
--cc=jack@suse.cz \
--cc=jannh@google.com \
--cc=jhubbard@nvidia.com \
--cc=linux-btrfs@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=linux-xfs@vger.kernel.org \
--cc=pfalcato@suse.de \
--cc=riel@surriel.com \
--cc=wqu@suse.com \
/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