From: Christoph Hellwig <hch@infradead.org>
To: Joanne Koong <joannelkoong@gmail.com>
Cc: miklos@szeredi.hu, djwong@kernel.org, brauner@kernel.org,
linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org,
bernd.schubert@fastmail.fm, kernel-team@meta.com
Subject: Re: [PATCH v1 4/8] iomap: add writepages support for IOMAP_IN_MEM iomaps
Date: Sun, 8 Jun 2025 22:32:20 -0700 [thread overview]
Message-ID: <aEZx5FKK13v36wRv@infradead.org> (raw)
In-Reply-To: <20250606233803.1421259-5-joannelkoong@gmail.com>
On Fri, Jun 06, 2025 at 04:37:59PM -0700, Joanne Koong wrote:
> This allows IOMAP_IN_MEM iomaps to use iomap_writepages() for handling
> writeback. This lets IOMAP_IN_MEM iomaps use some of the internal
> features in iomaps such as granular dirty tracking for large folios.
>
> This introduces a new iomap_writeback_ops callback, writeback_folio(),
> callers may pass in which hands off folio writeback logic to the caller
> for writing back dirty pages instead of relying on mapping blocks.
>
> This exposes two apis, iomap_start_folio_write() and
> iomap_finish_folio_write(), which callers may find useful in their
> writeback_folio() callback implementation.
It might also be worth stating what you don't use. One big thing
that springs to mind is ioends. Which are really useful if you
need more than one request to handle a folio, something that is
pretty common in network file systems. I guess you don't need
that for fuse?
> + if (wpc->iomap.type == IOMAP_IN_MEM) {
> + if (wpc->ops->submit_ioend)
> + error = wpc->ops->submit_ioend(wpc, error);
> + return error;
> + }
Given that the patch that moved things around already wrapped the
error propagation to the bio into a helpr, how does this differ
from the main path in the function now?
> + /*
> + * If error is non-zero, it means that we have a situation where some part of
> + * the submission process has failed after we've marked pages for writeback.
> + * We cannot cancel ioend directly in that case, so call the bio end I/O handler
> + * with the error status here to run the normal I/O completion handler to clear
> + * the writeback bit and let the file system process the errors.
> + */
Please add the comment in a separate preparation patch.
> + if (wpc->ops->writeback_folio) {
> + WARN_ON_ONCE(wpc->ops->map_blocks);
> + error = wpc->ops->writeback_folio(wpc, folio, inode,
> + offset_in_folio(folio, pos),
> + rlen);
> + } else {
> + WARN_ON_ONCE(wpc->iomap.type == IOMAP_IN_MEM);
> + error = iomap_writepage_map_blocks(wpc, wbc, folio,
> + inode, pos, end_pos,
> + rlen, &count);
> + }
So instead of having two entirely different methods, can we
refactor the block based code to also use
->writeback_folio?
Basically move all of the code inside the do { } while loop after
the call into ->map_blocks into a helper, and then let the caller
loop and also directly discard the folio if needed. I can give that
a spin if you want.
Note that writeback_folio is misnamed, as it doesn't write back an
entire folio, but just a dirty range.
> } else {
> - if (!count)
> + /*
> + * If wpc->ops->writeback_folio is set, then it is responsible
> + * for ending the writeback itself.
> + */
> + if (!count && !wpc->ops->writeback_folio)
> folio_end_writeback(folio);
This fails to explain why writeback_folio does the unlocking itself.
I also don't see how that would work in case of multiple dirty ranges.
> }
> mapping_set_error(inode->i_mapping, error);
> @@ -1693,3 +1713,25 @@ iomap_writepages(struct address_space *mapping, struct writeback_control *wbc,
> return iomap_submit_ioend(wpc, error);
> }
> EXPORT_SYMBOL_GPL(iomap_writepages);
> +
> +void iomap_start_folio_write(struct inode *inode, struct folio *folio, size_t len)
> +{
> + struct iomap_folio_state *ifs = folio->private;
> +
> + WARN_ON_ONCE(i_blocks_per_folio(inode, folio) > 1 && !ifs);
> + if (ifs)
> + atomic_add(len, &ifs->write_bytes_pending);
> +}
> +EXPORT_SYMBOL_GPL(iomap_start_folio_write);
> +
> +void iomap_finish_folio_write(struct inode *inode, struct folio *folio, size_t len)
> +{
> + struct iomap_folio_state *ifs = folio->private;
> +
> + WARN_ON_ONCE(i_blocks_per_folio(inode, folio) > 1 && !ifs);
> + WARN_ON_ONCE(ifs && atomic_read(&ifs->write_bytes_pending) <= 0);
> +
> + if (!ifs || atomic_sub_and_test(len, &ifs->write_bytes_pending))
> + folio_end_writeback(folio);
Please also use these helpers in the block based code.
next prev parent reply other threads:[~2025-06-09 5:32 UTC|newest]
Thread overview: 70+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-06 23:37 [PATCH v1 0/8] fuse: use iomap for buffered writes + writeback Joanne Koong
2025-06-06 23:37 ` [PATCH v1 1/8] iomap: move buffered io bio logic into separate file Joanne Koong
2025-06-08 19:17 ` Anuj gupta
2025-06-09 4:44 ` Christoph Hellwig
2025-06-09 20:01 ` Joanne Koong
2025-06-06 23:37 ` [PATCH v1 2/8] iomap: add IOMAP_IN_MEM iomap type Joanne Koong
2025-06-09 4:45 ` Christoph Hellwig
2025-06-09 21:45 ` Joanne Koong
2025-06-10 3:39 ` Christoph Hellwig
2025-06-10 13:27 ` Christoph Hellwig
2025-06-10 20:13 ` Joanne Koong
2025-06-11 4:04 ` Christoph Hellwig
2025-06-11 6:00 ` Joanne Koong
2025-06-11 6:08 ` Christoph Hellwig
2025-06-11 18:33 ` Joanne Koong
2025-06-11 18:50 ` Darrick J. Wong
2025-06-11 23:08 ` Joanne Koong
2025-06-12 4:42 ` Christoph Hellwig
2025-06-09 16:24 ` Darrick J. Wong
2025-06-09 21:28 ` Joanne Koong
2025-06-12 3:53 ` Darrick J. Wong
2025-06-06 23:37 ` [PATCH v1 3/8] iomap: add buffered write support for IOMAP_IN_MEM iomaps Joanne Koong
2025-06-09 4:56 ` Christoph Hellwig
2025-06-09 22:45 ` Joanne Koong
2025-06-10 3:44 ` Christoph Hellwig
2025-06-09 16:38 ` Darrick J. Wong
2025-06-09 22:03 ` Joanne Koong
2025-06-12 3:54 ` Darrick J. Wong
2025-06-06 23:37 ` [PATCH v1 4/8] iomap: add writepages " Joanne Koong
2025-06-09 5:32 ` Christoph Hellwig [this message]
2025-06-09 16:57 ` Darrick J. Wong
2025-06-10 3:49 ` Christoph Hellwig
2025-06-12 3:56 ` Darrick J. Wong
2025-06-09 23:15 ` Joanne Koong
2025-06-10 3:58 ` Christoph Hellwig
2025-06-10 18:23 ` Joanne Koong
2025-06-10 18:58 ` Joanne Koong
2025-06-11 4:01 ` Christoph Hellwig
2025-06-06 23:38 ` [PATCH v1 5/8] iomap: add iomap_writeback_dirty_folio() Joanne Koong
2025-06-09 4:51 ` Christoph Hellwig
2025-06-09 17:14 ` Darrick J. Wong
2025-06-09 23:54 ` Joanne Koong
2025-06-10 3:59 ` Christoph Hellwig
2025-06-11 4:34 ` Matthew Wilcox
2025-06-18 4:47 ` does fuse need ->launder_folios, was: " Christoph Hellwig
2025-06-18 12:17 ` Jeff Layton
2025-06-20 18:15 ` Matthew Wilcox
2025-06-25 5:26 ` Joanne Koong
2025-06-25 6:26 ` Christoph Hellwig
2025-06-25 16:44 ` Joanne Koong
2025-07-01 5:41 ` Darrick J. Wong
2025-07-02 21:36 ` Joanne Koong
2025-07-02 21:47 ` Joanne Koong
2025-07-01 6:23 ` Miklos Szeredi
2025-06-09 23:30 ` Joanne Koong
2025-06-10 4:03 ` Christoph Hellwig
2025-06-06 23:38 ` [PATCH v1 6/8] fuse: use iomap for buffered writes Joanne Koong
2025-06-06 23:38 ` [PATCH v1 7/8] fuse: use iomap for writeback Joanne Koong
2025-06-08 19:20 ` Anuj gupta
2025-06-06 23:38 ` [PATCH v1 8/8] fuse: use iomap for folio laundering Joanne Koong
2025-06-08 19:12 ` [PATCH v1 0/8] fuse: use iomap for buffered writes + writeback Anuj gupta
2025-06-09 19:59 ` Joanne Koong
2025-06-14 14:22 ` Anuj gupta
2025-06-09 4:40 ` Christoph Hellwig
2025-06-09 12:38 ` Anuj gupta
2025-06-09 19:47 ` Joanne Koong
2025-06-10 4:04 ` Christoph Hellwig
2025-06-10 0:47 ` Dave Chinner
2025-06-10 4:06 ` Christoph Hellwig
2025-06-10 20:33 ` Joanne Koong
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=aEZx5FKK13v36wRv@infradead.org \
--to=hch@infradead.org \
--cc=bernd.schubert@fastmail.fm \
--cc=brauner@kernel.org \
--cc=djwong@kernel.org \
--cc=joannelkoong@gmail.com \
--cc=kernel-team@meta.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-xfs@vger.kernel.org \
--cc=miklos@szeredi.hu \
/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;
as well as URLs for NNTP newsgroup(s).