fuse: use iomap for buffered writes + writeback
Subsystems (8)
v2 cover fuse: use iomap for buffered writes + writeback
This series adds fuse iomap support for buffered writes and dirty folio writeback. This is needed so that granular uptodate and dirty tracking can be used in fuse when large folios are enabled. This has two big advantages. Now for writes, instead of the entire folio needing to be read into the page cache, only the relevant portions need to be. Now for writeback, only the dirty portions need to be written back instead of the entire folio.
This patchset does 3 things, in order of sequence:
a) Decouple iomap/buffered-io.c code from the CONFIG_BLOCK dependency, as some environments that run fuse may not have CONFIG_BLOCK set
b) Add support to iomap buffered io for generic write and writeback that is not dependent on bios
c) Add fuse integration with iomap
Patches 3 and 5 are obviated by the refactoring done later on in patches 10 and 11 but I left this patchset in this order in the hopes of making it more logically easier to follow.
This series was run through fstests with large folios enabled and through some quick sanity checks on passthrough_hp with a) writing 1 GB in 1 MB chunks and then going back and dirtying a few bytes in each chunk and b) writing 50 MB in 1 MB chunks and going through dirtying the entire chunk for several runs.
a) showed about a 40% speedup increase with iomap support added and b) showed roughly the same performance.
This patchset does not enable large folios yet. That will be sent out in a separate future patchset.
This series is on top of commit 27605c8c0 ("Merge tag 'net-6.16-rc2'...") in the linux tree.
Thanks,
Joanne
Changeset
-------
v1 -> v2:
* Drop IOMAP_IN_MEM type and just use IOMAP_MAPPED for fuse
* Separate out new helper functions added to iomap into separate commits
* Update iomap documentation
* Clean up iomap_writeback_dirty_folio() locking logic w/ christoph's recommendation
* Refactor ->map_blocks() to generic ->writeback_folio()
* Refactor ->submit_ioend() to generic ->writeback_complete()
* Add patch for changing 'count' to 'async_writeback'
* Rebase commits onto linux branch instead of fuse branch
v1: https://lore.kernel.org/linux-fsdevel/[email protected]/
Joanne Koong (16):
iomap: move buffered io CONFIG_BLOCK dependent logic into separate
file
iomap: iomap_read_folio_sync() -> iomap_bio_read_folio_sync()
iomap: iomap_add_to_ioend() -> iomap_bio_add_to_ioend()
iomap: add wrapper function iomap_bio_readpage()
iomap: add wrapper function iomap_bio_ioend_error()
iomap: add wrapper function iomap_submit_bio()
iomap: decouple buffered-io.o from CONFIG_BLOCK
iomap: add read_folio_sync() handler for buffered writes
iomap: change 'count' to 'async_writeback'
iomap: replace ->map_blocks() with generic ->writeback_folio() for
writeback
iomap: replace ->submit_ioend() with generic ->writeback_complete()
for writeback
iomap: support more customized writeback handling
iomap: add iomap_writeback_dirty_folio()
fuse: use iomap for buffered writes
fuse: use iomap for writeback
fuse: use iomap for folio laundering
.../filesystems/iomap/operations.rst | 65 ++- block/fops.c | 7 +- fs/fuse/Kconfig | 1 + fs/fuse/file.c | 308 +++++------- fs/gfs2/bmap.c | 7 +- fs/iomap/Makefile | 5 +- fs/iomap/buffered-io-bio.c | 365 ++++++++++++++ fs/iomap/buffered-io.c | 471 +++--------------- fs/iomap/internal.h | 40 ++ fs/xfs/xfs_aops.c | 28 +- fs/zonefs/file.c | 7 +- include/linux/iomap.h | 88 +++- 12 files changed, 775 insertions(+), 617 deletions(-) create mode 100644 fs/iomap/buffered-io-bio.c
Signature · 1 line
2.47.1
PATCH v2 1/16 iomap: move buffered io CONFIG_BLOCK dependent logic into separate file
Move the bulk of buffered io logic that depends on CONFIG_BLOCK into a separate file, buffered-io-bio.c, in the effort to make it so that callers that do not have CONFIG_BLOCK set may also use iomap for buffered io to hook into some of its internal features such as granular dirty and uptodate tracking for large folios.
No functional changes.
--- fs/iomap/Makefile | 1 + fs/iomap/buffered-io-bio.c | 210 +++++++++++++++++++++++++++++++++++ fs/iomap/buffered-io.c | 222 +------------------------------------ fs/iomap/internal.h | 25 +++++ 4 files changed, 239 insertions(+), 219 deletions(-) create mode 100644 fs/iomap/buffered-io-bio.c
fs/iomap/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-$(CONFIG_FS_IOMAP) += iomap.o iomap-y += trace.o \ iter.o iomap-$(CONFIG_BLOCK) += buffered-io.o \ + buffered-io-bio.o \ direct-io.o \ ioend.o \ fiemap.o \
fs/iomap/buffered-io-bio.c new file +210 -0
210 lines not on this page · raw message
fs/iomap/buffered-io.c +3 -219
258 lines not on this page · raw message
fs/iomap/internal.h +25 -0
@@ -4,7 +4,32 @@#define IOEND_BATCH_SIZE 4096 +/* +* Structure allocated for each folio to track per-block uptodate, dirty state +* and I/O completions. +*/ +struct iomap_folio_state { +spinlock_t state_lock; +unsigned int read_bytes_pending; +atomic_t write_bytes_pending; + +/* +* Each block has two bits in this bitmap: +* Bits [0..blocks_per_folio) has the uptodate status. +* Bits [b_p_f...(2*b_p_f)) has the dirty status. +*/ +unsigned long state[]; +}; +u32 iomap_finish_ioend_buffered (struct iomap_ioend *ioend);u32 iomap_finish_ioend_direct (struct iomap_ioend *ioend); +bool ifs_set_range_uptodate (struct folio *folio,struct iomap_folio_state *ifs, +size_t off,size_t len); +int iomap_submit_ioend (struct iomap_writepage_ctx *wpc,int error); +int iomap_read_folio_sync (loff_t block_start,struct folio *folio,size_t poff, +size_t plen,const struct iomap *iomap); +int iomap_add_to_ioend (struct iomap_writepage_ctx *wpc, +struct writeback_control *wbc,struct folio *folio, +struct inode *inode,loff_t pos,loff_t end_pos,unsigned len);#endif /* _IOMAP_INTERNAL_H */
Signature · 1 line
2.47.1
PATCH v2 2/16 iomap: iomap_read_folio_sync() -> iomap_bio_read_folio_sync()
In reply to Joanne KoongRename from iomap_read_folio_sync() to iomap_bio_read_folio_sync() to indicate the dependency on the block io layer and add a CONFIG_BLOCK check to have iomap_bio_read_folio_sync() return -ENOSYS if the caller calls this in environments where CONFIG_BLOCK is not set.
--- fs/iomap/buffered-io-bio.c | 2 +- fs/iomap/buffered-io.c | 2 +- fs/iomap/internal.h | 9 +++++++-- 3 files changed, 9 insertions(+), 4 deletions(-)
fs/iomap/buffered-io-bio.c +1 -1
@@ -10,7 +10,7 @@#include "internal.h" -int iomap_read_folio_sync (loff_t block_start,struct folio *folio, +int iomap_bio_read_folio_sync (loff_t block_start,struct folio *folio,size_t poff,size_t plen,const struct iomap *iomap) {struct bio_vec bvec;
fs/iomap/buffered-io.c +1 -1
@@ -702,7 +702,7 @@ static int __iomap_write_begin(const struct iomap_iter *iter, size_t len,if (iter->flags &IOMAP_NOWAIT )return -EAGAIN ; - status =iomap_read_folio_sync (block_start, folio, + status =iomap_bio_read_folio_sync (block_start, folio, poff, plen, srcmap);if (status)return status;
fs/iomap/internal.h +7 -2
@@ -26,10 +26,15 @@ u32 iomap_finish_ioend_direct(struct iomap_ioend *ioend);bool ifs_set_range_uptodate (struct folio *folio,struct iomap_folio_state *ifs,size_t off,size_t len);int iomap_submit_ioend (struct iomap_writepage_ctx *wpc,int error); -int iomap_read_folio_sync (loff_t block_start,struct folio *folio,size_t poff, -size_t plen,const struct iomap *iomap);int iomap_add_to_ioend (struct iomap_writepage_ctx *wpc,struct writeback_control *wbc,struct folio *folio,struct inode *inode,loff_t pos,loff_t end_pos,unsigned len); +#ifdef CONFIG_BLOCK +int iomap_bio_read_folio_sync (loff_t block_start,struct folio *folio, +size_t poff,size_t plen,const struct iomap *iomap); +#else +#define iomap_bio_read_folio_sync (...) (-ENOSYS) +#endif /* CONFIG_BLOCK */ +#endif /* _IOMAP_INTERNAL_H */
Signature · 1 line
2.47.1
PATCH v2 3/16 iomap: iomap_add_to_ioend() -> iomap_bio_add_to_ioend()
In reply to Joanne KoongRename from iomap_add_to_ioend() to iomap_bio_add_to_ioend() to indicate the dependency on the block io layer and add a CONFIG_BLOCK check to have iomap_bio_add_to_ioend() return -ENOSYS if the caller calls this in environments where CONFIG_BLOCK is not set.
--- fs/iomap/buffered-io-bio.c | 2 +- fs/iomap/buffered-io.c | 4 ++-- fs/iomap/internal.h | 7 ++++--- 3 files changed, 7 insertions(+), 6 deletions(-)
fs/iomap/buffered-io-bio.c +1 -1
@@ -126,7 +126,7 @@ static bool iomap_can_add_to_ioend(struct iomap_writepage_ctx *wpc, loff_t pos,* At the end of a writeback pass, there will be a cached ioend remaining on the * writepage context that the caller will need to submit. */ -int iomap_add_to_ioend (struct iomap_writepage_ctx *wpc, +int iomap_bio_add_to_ioend (struct iomap_writepage_ctx *wpc,struct writeback_control *wbc,struct folio *folio,struct inode *inode,loff_t pos,loff_t end_pos,unsigned len)
fs/iomap/buffered-io.c +2 -2
@@ -1571,8 +1571,8 @@ static int iomap_writepage_map_blocks(struct iomap_writepage_ctx *wpc,case IOMAP_HOLE :break ;default : - error =iomap_add_to_ioend (wpc, wbc, folio, inode, pos, - end_pos, map_len); + error =iomap_bio_add_to_ioend (wpc, wbc, folio, inode, + pos, end_pos, map_len);if (!error) (*count)++;break ;
fs/iomap/internal.h +4 -3
@@ -26,15 +26,16 @@ u32 iomap_finish_ioend_direct(struct iomap_ioend *ioend);bool ifs_set_range_uptodate (struct folio *folio,struct iomap_folio_state *ifs,size_t off,size_t len);int iomap_submit_ioend (struct iomap_writepage_ctx *wpc,int error); -int iomap_add_to_ioend (struct iomap_writepage_ctx *wpc, -struct writeback_control *wbc,struct folio *folio, -struct inode *inode,loff_t pos,loff_t end_pos,unsigned len);#ifdef CONFIG_BLOCK int iomap_bio_read_folio_sync (loff_t block_start,struct folio *folio,size_t poff,size_t plen,const struct iomap *iomap); +int iomap_bio_add_to_ioend (struct iomap_writepage_ctx *wpc, +struct writeback_control *wbc,struct folio *folio, +struct inode *inode,loff_t pos,loff_t end_pos,unsigned len);#else #define iomap_bio_read_folio_sync (...) (-ENOSYS) +#define iomap_bio_add_to_ioend (...) (-ENOSYS)#endif /* CONFIG_BLOCK */ #endif /* _IOMAP_INTERNAL_H */
Signature · 1 line
2.47.1
PATCH v2 4/16 iomap: add wrapper function iomap_bio_readpage()
In reply to Joanne KoongAdd a wrapper function, iomap_bio_readpage(), around the bio readpage logic so that callers that do not have CONFIG_BLOCK set may also use iomap for buffered io.
No functional changes.
--- fs/iomap/buffered-io-bio.c | 71 ++++++++++++++++++++++++++++++++++++++ fs/iomap/buffered-io.c | 71 +------------------------------------- fs/iomap/internal.h | 11 ++++++ 3 files changed, 83 insertions(+), 70 deletions(-)
fs/iomap/buffered-io-bio.c +71 -0
@@ -10,6 +10,77 @@#include "internal.h" +static void iomap_finish_folio_read (struct folio *folio,size_t off, +size_t len,int error) +{ +struct iomap_folio_state *ifs = folio->private; +bool uptodate = !error; +bool finished = true; + +if (ifs) { +unsigned long flags; + +spin_lock_irqsave (&ifs->state_lock, flags); +if (!error) + uptodate =ifs_set_range_uptodate (folio, ifs, off, len); + ifs->read_bytes_pending -= len; + finished = !ifs->read_bytes_pending; +spin_unlock_irqrestore (&ifs->state_lock, flags); + } + +if (finished) +folio_end_read (folio, uptodate); +} + +static void iomap_read_end_io (struct bio *bio) +{ +int error =blk_status_to_errno (bio->bi_status); +struct folio_iter fi; + +bio_for_each_folio_all (fi, bio) +iomap_finish_folio_read (fi.folio, fi.offset, fi.length, error); +bio_put (bio); +} + +void iomap_bio_readpage (const struct iomap *iomap,loff_t pos, +struct iomap_readpage_ctx *ctx,size_t poff,size_t plen, +loff_t length) +{ +struct folio *folio = ctx->cur_folio; +sector_t sector; + + sector =iomap_sector (iomap, pos); +if (!ctx->bio || +bio_end_sector (ctx->bio) != sector || + !bio_add_folio (ctx->bio, folio, plen, poff)) { +gfp_t gfp =mapping_gfp_constraint (folio->mapping,GFP_KERNEL ); +gfp_t orig_gfp = gfp; +unsigned int nr_vecs =DIV_ROUND_UP (length,PAGE_SIZE ); + +if (ctx->bio) +submit_bio (ctx->bio); + +if (ctx->rac)/* same as readahead_gfp_mask */ + gfp |= __GFP_NORETRY | __GFP_NOWARN; + ctx->bio =bio_alloc (iomap->bdev,bio_max_segs (nr_vecs), +REQ_OP_READ , gfp); +/* +* If the bio_alloc fails, try it again for a single page to +* avoid having to deal with partial page reads. This emulates +* what do_mpage_read_folio does. +*/ +if (!ctx->bio) { + ctx->bio =bio_alloc (iomap->bdev,1 ,REQ_OP_READ , + orig_gfp); + } +if (ctx->rac) + ctx->bio->bi_opf |=REQ_RAHEAD ; + ctx->bio->bi_iter.bi_sector = sector; + ctx->bio->bi_end_io = iomap_read_end_io; +bio_add_folio_nofail (ctx->bio, folio, plen, poff); + } +} +int iomap_bio_read_folio_sync (loff_t block_start,struct folio *folio,size_t poff,size_t plen,const struct iomap *iomap) {
fs/iomap/buffered-io.c +1 -70
89 lines not on this page · raw message
fs/iomap/internal.h +11 -0
@@ -21,6 +21,13 @@ struct iomap_folio_state {unsigned long state[]; }; +struct iomap_readpage_ctx { +struct folio *cur_folio; +bool cur_folio_in_bio; +struct bio *bio; +struct readahead_control *rac; +}; +u32 iomap_finish_ioend_buffered (struct iomap_ioend *ioend);u32 iomap_finish_ioend_direct (struct iomap_ioend *ioend); bool ifs_set_range_uptodate(struct folio *folio, struct iomap_folio_state *ifs,
@@ -33,9 +40,13 @@ int iomap_bio_read_folio_sync(loff_t block_start, struct folio *folio,int iomap_bio_add_to_ioend (struct iomap_writepage_ctx *wpc,struct writeback_control *wbc,struct folio *folio,struct inode *inode,loff_t pos,loff_t end_pos,unsigned len); +void iomap_bio_readpage (const struct iomap *iomap,loff_t pos, +struct iomap_readpage_ctx *ctx,size_t poff,size_t plen, +loff_t length);#else #define iomap_bio_read_folio_sync (...) (-ENOSYS)#define iomap_bio_add_to_ioend (...) (-ENOSYS) +#define iomap_bio_readpage (...) ((void)0)#endif /* CONFIG_BLOCK */ #endif /* _IOMAP_INTERNAL_H */
Signature · 1 line
2.47.1
Re: [PATCH v2 04/16] iomap: add wrapper function iomap_bio_readpage()
Quoted 3 lines · Joanne Koong
Add a wrapper function,
iomap_bio_readpage(), around the bio readpage logic so that callers that do not haveCONFIG_BLOCKset may also use iomap for buffered io.
As far as I can tell nothing in this series actually uses the non-block read path, and I also don't really understand how the current split would facilitate that. Can you explain a bit more where this is going?
Re: [PATCH v2 04/16] iomap: add wrapper function iomap_bio_readpage()
Quoted 10 lines · Christoph Hellwig
Quoted 3 lines · Joanne Koong
Add a wrapper function,
iomap_bio_readpage(), around the bio readpage logic so that callers that do not haveCONFIG_BLOCKset may also use iomap for buffered io.As far as I can tell nothing in this series actually uses the non-block read path, and I also don't really understand how the current split would facilitate that. Can you explain a bit more where this is going?
Nothing in this series uses the iomap read path, but fuse might be used in environments where CONFIG_BLOCK isn't set. What I'm trying to do with this patch is move the logic in iomap readpage that's block / bio dependent out of buffered-io.c and gate that behind a #ifdef CONFIG_BLOCK check so that fuse can use buffered-io.c without breaking compilation for non-CONFIG_BLOCK environments
Re: [PATCH v2 04/16] iomap: add wrapper function iomap_bio_readpage()
Quoted 6 lines · Joanne Koong
Nothing in this series uses the iomap read path, but fuse might be used in environments where
CONFIG_BLOCKisn't set. What I'm trying to do with this patch is move the logic in iomap readpage that's block / bio dependent out ofbuffered-io.cand gate that behind a #ifdefCONFIG_BLOCKcheck so that fuse can usebuffered-io.cwithout breaking compilation for non-CONFIG_BLOCK environments
Ah, ok. Are you fine with getting something that works for fuse first, and then we look into !CONFIG_BLOCK environments as a next step?
Re: [PATCH v2 04/16] iomap: add wrapper function iomap_bio_readpage()
Quoted 11 lines · Christoph Hellwig
Quoted 6 lines · Joanne Koong
Nothing in this series uses the iomap read path, but fuse might be used in environments where
CONFIG_BLOCKisn't set. What I'm trying to do with this patch is move the logic in iomap readpage that's block / bio dependent out ofbuffered-io.cand gate that behind a #ifdefCONFIG_BLOCKcheck so that fuse can usebuffered-io.cwithout breaking compilation for non-CONFIG_BLOCK environmentsAh, ok. Are you fine with getting something that works for fuse first, and then we look into !CONFIG_BLOCK environments as a next step?
I think the fuse iomap work has a hard dependency on the CONFIG_BLOCK work else it would break backwards compatibility for fuse (eg non-CONFIG_BLOCK environments wouldn't be able to compile/use fuse anymore)
Re: [PATCH v2 04/16] iomap: add wrapper function iomap_bio_readpage()
Quoted 7 lines · Joanne Koong
Quoted 2 lines
Ah, ok. Are you fine with getting something that works for fuse first, and then we look into !CONFIG_BLOCK environments as a next step?
I think the fuse iomap work has a hard dependency on the
CONFIG_BLOCKwork else it would break backwards compatibility for fuse (eg non-CONFIG_BLOCK environments wouldn't be able to compile/use fuse anymore)
Sure. What I mean is that I want to do this last before getting the series ready to merge. I.e. don't bother with until we have something we're all fine with on a conceptual level.
Re: [PATCH v2 04/16] iomap: add wrapper function iomap_bio_readpage()
Quoted 5 lines · Christoph Hellwig
Quoted 3 lines · Joanne Koong
Quoted 2 lines
Ah, ok. Are you fine with getting something that works for fuse first, and then we look into !CONFIG_BLOCK environments as a next step?
Quoted 8 lines
Quoted 4 lines
I think the fuse iomap work has a hard dependency on the
CONFIG_BLOCKwork else it would break backwards compatibility for fuse (eg non-CONFIG_BLOCK environments wouldn't be able to compile/use fuse anymore)Sure. What I mean is that I want to do this last before getting the series ready to merge. I.e. don't bother with until we have something we're all fine with on a conceptual level.
I'm pausing this patchset until yours lands and then I was planning to rebase this (the CONFIG_BLOCK and fuse specifics) on top of yours. Not sure if that's what you mean or not, but yes, happy to go with whatever you think works best.
Re: [PATCH v2 04/16] iomap: add wrapper function iomap_bio_readpage()
Quoted 8 lines · Joanne Koong
Quoted 3 lines
Sure. What I mean is that I want to do this last before getting the series ready to merge. I.e. don't bother with until we have something we're all fine with on a conceptual level.
I'm pausing this patchset until yours lands and then I was planning to rebase this (the
CONFIG_BLOCKand fuse specifics) on top of yours. Not sure if that's what you mean or not, but yes, happy to go with whatever you think works best.
It's not going to land without a user..
At some point we'll need to fuse side of this to go ahead. I'm happy to either hand control of the series to you, or work with you on a common tree to make that happen.
Re: [PATCH v2 04/16] iomap: add wrapper function iomap_bio_readpage()
Quoted 11 lines · Christoph Hellwig
Quoted 8 lines · Joanne Koong
Quoted 3 lines
Sure. What I mean is that I want to do this last before getting the series ready to merge. I.e. don't bother with until we have something we're all fine with on a conceptual level.
I'm pausing this patchset until yours lands and then I was planning to rebase this (the
CONFIG_BLOCKand fuse specifics) on top of yours. Not sure if that's what you mean or not, but yes, happy to go with whatever you think works best.
Quoted 5 lines
It's not going to land without a user..
At some point we'll need to fuse side of this to go ahead. I'm happy to either hand control of the series to you, or work with you on a common tree to make that happen.
I will send v3 today with:
Patches 1 to 11: the patches in your patchset in [1]
Patches 12 to 15: the fuse patches in this patchset (14/16, 15/16, and 16/16)
and temporarily drop the CONFIG_BLOCK patches until the series is ready to merge.
[1] https://lore.kernel.org/linux-fsdevel/[email protected]/
PATCH v2 5/16 iomap: add wrapper function iomap_bio_ioend_error()
In reply to Joanne KoongAdd a wrapper function, iomap_bio_ioend_error(), around the bio error handling so that callers that do not have CONFIG_BLOCK set may also use iomap for buffered io.
No functional changes.
--- fs/iomap/buffered-io-bio.c | 6 ++++++ fs/iomap/buffered-io.c | 6 ++---- fs/iomap/internal.h | 2 ++ 3 files changed, 10 insertions(+), 4 deletions(-)
fs/iomap/buffered-io-bio.c +6 -0
@@ -145,6 +145,12 @@ static void iomap_writepage_end_bio(struct bio *bio)iomap_finish_ioend_buffered (ioend); } +void iomap_bio_ioend_error (struct iomap_writepage_ctx *wpc,int error) +{ + wpc->ioend->io_bio.bi_status =errno_to_blk_status (error); +bio_endio (&wpc->ioend->io_bio); +} +static struct iomap_ioend *iomap_alloc_ioend (struct iomap_writepage_ctx *wpc,struct writeback_control *wbc,struct inode *inode,loff_t pos,u16 ioend_flags)
fs/iomap/buffered-io.c +2 -4
@@ -1466,10 +1466,8 @@ int iomap_submit_ioend(struct iomap_writepage_ctx *wpc, int error)submit_bio (&wpc->ioend->io_bio); } -if (error) { - wpc->ioend->io_bio.bi_status =errno_to_blk_status (error); -bio_endio (&wpc->ioend->io_bio); - } +if (error) +iomap_bio_ioend_error (wpc, error); wpc->ioend =NULL ;return error;
fs/iomap/internal.h +2 -0
@@ -43,10 +43,12 @@ int iomap_bio_add_to_ioend(struct iomap_writepage_ctx *wpc,void iomap_bio_readpage (const struct iomap *iomap,loff_t pos,struct iomap_readpage_ctx *ctx,size_t poff,size_t plen,loff_t length); +void iomap_bio_ioend_error (struct iomap_writepage_ctx *wpc,int error);#else #define iomap_bio_read_folio_sync (...) (-ENOSYS)#define iomap_bio_add_to_ioend (...) (-ENOSYS)#define iomap_bio_readpage (...) ((void)0) +#define iomap_bio_ioend_error (...) ((void)0)#endif /* CONFIG_BLOCK */ #endif /* _IOMAP_INTERNAL_H */
Signature · 1 line
2.47.1
PATCH v2 6/16 iomap: add wrapper function iomap_submit_bio()
In reply to Joanne KoongAdd a wrapper function, iomap_submit_bio(), around bio submission so that callers that do not have CONFIG_BLOCK set may also use iomap for buffered io.
--- fs/iomap/buffered-io-bio.c | 5 +++++ fs/iomap/buffered-io.c | 6 +++--- fs/iomap/internal.h | 2 ++ 3 files changed, 10 insertions(+), 3 deletions(-)
fs/iomap/buffered-io-bio.c +5 -0
@@ -81,6 +81,11 @@ void iomap_bio_readpage(const struct iomap *iomap, loff_t pos, } } +void iomap_submit_bio (struct bio *bio) +{ +submit_bio (bio); +} +int iomap_bio_read_folio_sync (loff_t block_start,struct folio *folio,size_t poff,size_t plen,const struct iomap *iomap) {
fs/iomap/buffered-io.c +3 -3
@@ -388,7 +388,7 @@ int iomap_read_folio(struct folio *folio, const struct iomap_ops *ops) iter.status =iomap_read_folio_iter (&iter, &ctx);if (ctx.bio) { -submit_bio (ctx.bio); +iomap_submit_bio (ctx.bio);WARN_ON_ONCE (!ctx.cur_folio_in_bio); }else {WARN_ON_ONCE (ctx.cur_folio_in_bio);
@@ -460,7 +460,7 @@ void iomap_readahead(struct readahead_control *rac, const struct iomap_ops *ops) iter.status =iomap_readahead_iter (&iter, &ctx);if (ctx.bio) -submit_bio (ctx.bio); +iomap_submit_bio (ctx.bio);if (ctx.cur_folio) {if (!ctx.cur_folio_in_bio)folio_unlock (ctx.cur_folio);
@@ -1463,7 +1463,7 @@ int iomap_submit_ioend(struct iomap_writepage_ctx *wpc, int error)if (WARN_ON_ONCE (wpc->iomap.flags &IOMAP_F_ANON_WRITE )) error = -EIO ;if (!error) -submit_bio (&wpc->ioend->io_bio); +iomap_submit_bio (&wpc->ioend->io_bio); }if (error)
fs/iomap/internal.h +2 -0
@@ -44,11 +44,13 @@ void iomap_bio_readpage(const struct iomap *iomap, loff_t pos, struct iomap_readpage_ctx *ctx, size_t poff, size_t plen, loff_t length);void iomap_bio_ioend_error (struct iomap_writepage_ctx *wpc,int error); +void iomap_submit_bio (struct bio *bio);#else #define iomap_bio_read_folio_sync (...) (-ENOSYS)#define iomap_bio_add_to_ioend (...) (-ENOSYS)#define iomap_bio_readpage (...) ((void)0)#define iomap_bio_ioend_error (...) ((void)0) +#define iomap_submit_bio (...) ((void)0)#endif /* CONFIG_BLOCK */ #endif /* _IOMAP_INTERNAL_H */
Signature · 1 line
2.47.1
PATCH v2 7/16 iomap: decouple buffered-io.o from CONFIG_BLOCK
In reply to Joanne KoongNow that buffered-io.o is not dependent on CONFIG_BLOCK, decouple it from CONFIG_BLOCK in the Makefile so that filesystems that do not have CONFIG_BLOCK dependencies may still use iomap for buffered io.
--- fs/iomap/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
fs/iomap/Makefile +3 -3
@@ -9,9 +9,9 @@ ccflags-y += -I $(src) # needed for trace events obj-$(CONFIG_FS_IOMAP) += iomap.o iomap-y += trace.o \ - iter.o -iomap-$(CONFIG_BLOCK) += buffered-io.o \ - buffered-io-bio.o \ + iter.o \ + buffered-io.o +iomap-$(CONFIG_BLOCK) += buffered-io-bio.o \ direct-io.o \ ioend.o \ fiemap.o \
Signature · 1 line
2.47.1
PATCH v2 8/16 iomap: add read_folio_sync() handler for buffered writes
In reply to Joanne KoongAdd a read_folio_sync() handler for buffered writes that filesystems may pass in if they wish to provide a custom handler for synchronously reading in the contents of a folio.
--- .../filesystems/iomap/operations.rst | 7 +++++++ fs/iomap/buffered-io.c | 19 ++++++++++++++++--- include/linux/iomap.h | 11 +++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-)
Documentation/filesystems/iomap/operations.rst +7 -0
@@ -72,6 +72,9 @@ default behaviors of iomap: void (*put_folio)(struct inode *inode, loff_t pos, unsigned copied, struct folio *folio); bool (*iomap_valid)(struct inode *inode, const struct iomap *iomap); + int (*read_folio_sync)(loff_t block_start, struct folio *folio, + size_t off, size_t len, + const struct iomap *iomap, void *private); }; iomap calls these functions:
@@ -102,6 +105,10 @@ iomap calls these functions: <https://lore.kernel.org/all/[email protected]/>`_ to allocate, install, and lock that folio. + - ``read_folio_sync``: Called to synchronously read in the range that will + be written to. If this function is not provided, iomap will default to + submitting a bio read request. + For the pagecache, races can happen if writeback doesn't take ``i_rwsem`` or ``invalidate_lock`` and updates mapping information. Races can also happen if the filesystem allows concurrent writes.
fs/iomap/buffered-io.c +16 -3
@@ -581,10 +581,23 @@ iomap_write_failed(struct inode *inode, loff_t pos, unsigned len) pos + len - 1); } +static int iomap_read_folio_sync (const struct iomap_iter *iter, +loff_t block_start,struct folio *folio,size_t poff, +size_t plen) +{ +const struct iomap_folio_ops *folio_ops = iter->iomap.folio_ops; +const struct iomap *srcmap =iomap_iter_srcmap (iter); + +if (folio_ops && folio_ops->read_folio_sync) +return folio_ops->read_folio_sync (block_start, folio, poff, + plen, srcmap, iter->private); + +return iomap_bio_read_folio_sync (block_start, folio, poff, plen, srcmap); +} +static int __iomap_write_begin (const struct iomap_iter *iter,size_t len,struct folio *folio) { -const struct iomap *srcmap =iomap_iter_srcmap (iter);struct iomap_folio_state *ifs;loff_t pos = iter->pos;loff_t block_size =i_blocksize (iter->inode);
@@ -633,8 +646,8 @@ static int __iomap_write_begin(const struct iomap_iter *iter, size_t len,if (iter->flags &IOMAP_NOWAIT )return -EAGAIN ; - status =iomap_bio_read_folio_sync (block_start, folio, - poff, plen, srcmap); + status =iomap_read_folio_sync (iter, block_start, folio, + poff, plen);if (status)return status; }
include/linux/iomap.h +11 -0
@@ -174,6 +174,17 @@ struct iomap_folio_ops {* locked by the iomap code. */ bool (*iomap_valid)(struct inode *inode,const struct iomap *iomap); + +/* +* Optional if the filesystem wishes to provide a custom handler for +* reading in the contents of a folio, otherwise iomap will default to +* submitting a bio read request. +* +* The read must be done synchronously. +*/ +int (*read_folio_sync)(loff_t block_start,struct folio *folio, +size_t off,size_t len,const struct iomap *iomap, +void *private); };/*
Signature · 1 line
2.47.1
PATCH v2 9/16 iomap: change 'count' to 'async_writeback'
In reply to Joanne KoongRename "count" to "async_writeback" to better reflect its function and since it is used as a boolean, change its type from unsigned to bool.
--- fs/iomap/buffered-io.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
fs/iomap/buffered-io.c +6 -6
@@ -1489,7 +1489,7 @@ int iomap_submit_ioend(struct iomap_writepage_ctx *wpc, int error)static int iomap_writepage_map_blocks (struct iomap_writepage_ctx *wpc,struct writeback_control *wbc,struct folio *folio,struct inode *inode,u64 pos,u64 end_pos, -unsigned dirty_len,unsigned *count) +unsigned dirty_len,bool *async_writeback) {int error;
@@ -1516,7 +1516,7 @@ static int iomap_writepage_map_blocks(struct iomap_writepage_ctx *wpc, error =iomap_bio_add_to_ioend (wpc, wbc, folio, inode, pos, end_pos, map_len);if (!error) - (*count)++; + *async_writeback = true;break ; } dirty_len -= map_len;
@@ -1603,7 +1603,7 @@ static int iomap_writepage_map(struct iomap_writepage_ctx *wpc,u64 pos =folio_pos (folio);u64 end_pos = pos +folio_size (folio);u64 end_aligned =0 ; -unsigned count =0 ; +bool async_writeback = false;int error =0 ;u32 rlen;
@@ -1647,13 +1647,13 @@ static int iomap_writepage_map(struct iomap_writepage_ctx *wpc, end_aligned =round_up (end_pos,i_blocksize (inode));while ((rlen =iomap_find_dirty_range (folio, &pos, end_aligned))) { error =iomap_writepage_map_blocks (wpc, wbc, folio, inode, - pos, end_pos, rlen, &count); + pos, end_pos, rlen, &async_writeback);if (error)break ; pos += rlen; } -if (count) +if (async_writeback) wpc->nr_folios++;/*
@@ -1675,7 +1675,7 @@ static int iomap_writepage_map(struct iomap_writepage_ctx *wpc,if (atomic_dec_and_test (&ifs->write_bytes_pending))folio_end_writeback (folio); }else { -if (!count) +if (!async_writeback)folio_end_writeback (folio); }mapping_set_error (inode->i_mapping, error);
Signature · 1 line
2.47.1
Re: [PATCH v2 09/16] iomap: change 'count' to 'async_writeback'
Quoted 2 lines · Joanne Koong
Rename "count" to "
async_writeback" to better reflect its function and since it is used as a boolean, change its type from unsigned to bool.
Not sure async_writeback is really the right name here, the way it is used is just that there is any writeback going on. Which generally is asynchronous as otherwise performance would suck, but the important bit is that the responsibility for finishing the folio writeback shifted to the caller.
Re: [PATCH v2 09/16] iomap: change 'count' to 'async_writeback'
Quoted 10 lines · Christoph Hellwig
Quoted 2 lines · Joanne Koong
Rename "count" to "
async_writeback" to better reflect its function and since it is used as a boolean, change its type from unsigned to bool.Not sure
async_writebackis really the right name here, the way it is used is just that there is any writeback going on. Which generally is asynchronous as otherwise performance would suck, but the important bit is that the responsibility for finishing the folio writeback shifted to the caller.
I like your name "wb_pending" a lot better.
PATCH v2 10/16 iomap: replace ->map_blocks() with generic ->writeback_folio() for writeback
In reply to Joanne KoongAs part of the larger effort to have iomap buffered io code support generic io, replace map_blocks() with writeback_folio() and move the bio writeback code into a helper function, iomap_bio_writeback_folio(), that callers using bios can directly invoke.
No functional changes.
--- .../filesystems/iomap/operations.rst | 38 +++++----- block/fops.c | 7 +- fs/gfs2/bmap.c | 7 +- fs/iomap/buffered-io-bio.c | 49 +++++++++++- fs/iomap/buffered-io.c | 74 +++++-------------- fs/iomap/internal.h | 4 - fs/xfs/xfs_aops.c | 14 +++- fs/zonefs/file.c | 7 +- include/linux/iomap.h | 42 ++++++++--- 9 files changed, 148 insertions(+), 94 deletions(-)
Documentation/filesystems/iomap/operations.rst +21 -17
@@ -278,7 +278,7 @@ writeback. It does not lock ``i_rwsem`` or ``invalidate_lock``. The dirty bit will be cleared for all folios run through the -``->map_blocks`` machinery described below even if the writeback fails. +``->writeback_folio`` machinery described below even if the writeback fails. This is to prevent dirty folio clots when storage devices fail; an ``-EIO`` is recorded for userspace to collect via ``fsync``.
@@ -290,29 +290,33 @@ The ``ops`` structure must be specified and is as follows: .. code-block:: c struct iomap_writeback_ops { - int (*map_blocks)(struct iomap_writepage_ctx *wpc, struct inode *inode, - loff_t offset, unsigned len); + int (*writeback_folio)(struct iomap_writeback_folio_range *ctx); int (*submit_ioend)(struct iomap_writepage_ctx *wpc, int status); void (*discard_folio)(struct folio *folio, loff_t pos); }; The fields are as follows: - - ``map_blocks``: Sets ``wpc->iomap`` to the space mapping of the file - range (in bytes) given by ``offset`` and ``len``. - iomap calls this function for each dirty fs block in each dirty folio, - though it will `reuse mappings + - ``writeback_folio``: iomap calls this function for each dirty fs block + in each dirty folio, though it will `reuse mappings <https://lore.kernel.org/all/[email protected]/>`_ for runs of contiguous dirty fsblocks within a folio. - Do not return ``IOMAP_INLINE`` mappings here; the ``->iomap_end`` - function must deal with persisting written data. - Do not return ``IOMAP_DELALLOC`` mappings here; iomap currently - requires mapping to allocated space. - Filesystems can skip a potentially expensive mapping lookup if the - mappings have not changed. - This revalidation must be open-coded by the filesystem; it is - unclear if ``iomap::validity_cookie`` can be reused for this - purpose. + For blocks that need to be mapped first, please take a look at + ``iomap_bio_writeback_folio`` which takes in a ``iomap_map_blocks_t`` + mapping function. For that mapping function, + + * Set ``wpc->iomap`` to the space mapping of the file range (in bytes) + given by ``offset`` and ``len``. + * Do not return ``IOMAP_INLINE`` mappings here; the ``->iomap_end`` + function must deal with persisting written data. + * Do not return ``IOMAP_DELALLOC`` mappings here; iomap currently + requires mapping to allocated space. + * Filesystems can skip a potentially expensive mapping lookup if the + mappings have not changed. + * This revalidation must be open-coded by the filesystem; it is + unclear if ``iomap::validity_cookie`` can be reused for this + purpose. + This function must be supplied by the filesystem. - ``submit_ioend``: Allows the file systems to hook into writeback bio
@@ -323,7 +327,7 @@ The fields are as follows: transactions from process context before submitting the bio. This function is optional. - - ``discard_folio``: iomap calls this function after ``->map_blocks`` + - ``discard_folio``: iomap calls this function after ``->writeback_folio`` fails to schedule I/O for any part of a dirty folio. The function should throw away any reservations that may have been made for the write.
block/fops.c +6 -1
@@ -551,8 +551,13 @@ static int blkdev_map_blocks(struct iomap_writepage_ctx *wpc, IOMAP_WRITE, &wpc->iomap, NULL); } +static int blkdev_writeback_folio (struct iomap_writeback_folio_range *ctx) +{ +return iomap_bio_writeback_folio (ctx, blkdev_map_blocks); +} +static const struct iomap_writeback_ops blkdev_writeback_ops = { - .map_blocks = blkdev_map_blocks, + .writeback_folio = blkdev_writeback_folio, }; static int blkdev_writepages(struct address_space *mapping,
fs/gfs2/bmap.c +6 -1
@@ -2486,6 +2486,11 @@ static int gfs2_map_blocks(struct iomap_writepage_ctx *wpc, struct inode *inode,return ret; } +static int gfs2_writeback_folio (struct iomap_writeback_folio_range *ctx) +{ +return iomap_bio_writeback_folio (ctx, gfs2_map_blocks); +} +const struct iomap_writeback_ops gfs2_writeback_ops = { - .map_blocks = gfs2_map_blocks, + .writeback_folio = gfs2_writeback_folio, };
fs/iomap/buffered-io-bio.c +48 -1
64 lines not on this page · raw message
fs/iomap/buffered-io.c +17 -57
104 lines not on this page · raw message
fs/iomap/internal.h +0 -4
@@ -37,9 +37,6 @@ int iomap_submit_ioend(struct iomap_writepage_ctx *wpc, int error);#ifdef CONFIG_BLOCK int iomap_bio_read_folio_sync (loff_t block_start,struct folio *folio,size_t poff,size_t plen,const struct iomap *iomap); -int iomap_bio_add_to_ioend (struct iomap_writepage_ctx *wpc, -struct writeback_control *wbc,struct folio *folio, -struct inode *inode,loff_t pos,loff_t end_pos,unsigned len);void iomap_bio_readpage (const struct iomap *iomap,loff_t pos,struct iomap_readpage_ctx *ctx,size_t poff,size_t plen,loff_t length);
@@ -47,7 +44,6 @@ void iomap_bio_ioend_error(struct iomap_writepage_ctx *wpc, int error);void iomap_submit_bio (struct bio *bio);#else #define iomap_bio_read_folio_sync (...) (-ENOSYS) -#define iomap_bio_add_to_ioend (...) (-ENOSYS)#define iomap_bio_readpage (...) ((void)0)#define iomap_bio_ioend_error (...) ((void)0)#define iomap_submit_bio (...) ((void)0)
fs/xfs/xfs_aops.c +12 -2
@@ -455,6 +455,11 @@ xfs_ioend_needs_wq_completion(return false; } +static int xfs_writeback_folio (struct iomap_writeback_folio_range *ctx) +{ +return iomap_bio_writeback_folio (ctx, xfs_map_blocks); +} + static int xfs_submit_ioend( struct iomap_writepage_ctx *wpc,
@@ -526,7 +531,7 @@ xfs_discard_folio( }static const struct iomap_writeback_ops xfs_writeback_ops = { - .map_blocks = xfs_map_blocks, + .writeback_folio = xfs_writeback_folio, .submit_ioend = xfs_submit_ioend, .discard_folio = xfs_discard_folio, };
@@ -608,6 +613,11 @@ xfs_zoned_map_blocks(return 0 ; } +static int xfs_zoned_writeback_folio (struct iomap_writeback_folio_range *ctx) +{ +return iomap_bio_writeback_folio (ctx, xfs_zoned_map_blocks); +} + static int xfs_zoned_submit_ioend( struct iomap_writepage_ctx *wpc,
@@ -621,7 +631,7 @@ xfs_zoned_submit_ioend( }static const struct iomap_writeback_ops xfs_zoned_writeback_ops = { - .map_blocks = xfs_zoned_map_blocks, + .writeback_folio = xfs_zoned_writeback_folio, .submit_ioend = xfs_zoned_submit_ioend, .discard_folio = xfs_discard_folio, };
fs/zonefs/file.c +6 -1
@@ -145,8 +145,13 @@ static int zonefs_write_map_blocks(struct iomap_writepage_ctx *wpc, IOMAP_WRITE, &wpc->iomap, NULL); } +static int zonefs_writeback_folio (struct iomap_writeback_folio_range *ctx) +{ +return iomap_bio_writeback_folio (ctx, zonefs_write_map_blocks); +} +static const struct iomap_writeback_ops zonefs_writeback_ops = { - .map_blocks = zonefs_write_map_blocks, + .writeback_folio = zonefs_writeback_folio, }; static int zonefs_writepages(struct address_space *mapping,
include/linux/iomap.h +32 -10
66 lines not on this page · raw message
Signature · 1 line
2.47.1
Re: [PATCH v2 10/16] iomap: replace ->map_blocks() with generic ->writeback_folio() for writeback
Quoted 4 lines · Joanne Koong
As part of the larger effort to have iomap buffered io code support generic io, replace
map_blocks()withwriteback_folio()and move the bio writeback code into a helper function,iomap_bio_writeback_folio(), that callers using bios can directly invoke.
Hmm, what I had in mind with my suggestion was to only have a single callback, where the guts of the current code are just called by the block based file systems.
I ended up implementing this this morning to see if it's feasible, and it works fine so far. Let me send out what I've got.
PATCH v2 11/16 iomap: replace ->submit_ioend() with generic ->writeback_complete() for writeback
In reply to Joanne KoongAs part of the larger effort to have iomap buffered io code support generic io, replace submit_ioend() with writeback_complete() and move the bio ioend code into a helper function, iomap_bio_writeback_complete(), that callers using bios can directly invoke.
No functional changes.
--- .../filesystems/iomap/operations.rst | 18 ++++---- fs/iomap/buffered-io-bio.c | 42 ++++++++++++++++++- fs/iomap/buffered-io.c | 38 +++-------------- fs/iomap/internal.h | 4 +- fs/xfs/xfs_aops.c | 14 ++++++- include/linux/iomap.h | 26 ++++++++---- 6 files changed, 88 insertions(+), 54 deletions(-)
Documentation/filesystems/iomap/operations.rst +10 -8
@@ -291,7 +291,7 @@ The ``ops`` structure must be specified and is as follows: struct iomap_writeback_ops { int (*writeback_folio)(struct iomap_writeback_folio_range *ctx); - int (*submit_ioend)(struct iomap_writepage_ctx *wpc, int status); + int (*writeback_complete)(struct iomap_writepage_ctx *wpc, int status); void (*discard_folio)(struct folio *folio, loff_t pos); };
@@ -319,13 +319,15 @@ The fields are as follows: This function must be supplied by the filesystem. - - ``submit_ioend``: Allows the file systems to hook into writeback bio - submission. - This might include pre-write space accounting updates, or installing - a custom ``->bi_end_io`` function for internal purposes, such as - deferring the ioend completion to a workqueue to run metadata update - transactions from process context before submitting the bio. - This function is optional. + - ``writeback_complete``: Allows the file systems to execute any logic that + needs to happen after ``->writeback_folio`` has been called for all dirty + folios. This might include hooking into writeback bio submission for + pre-write space accounting updates, or installing a custom ``->bi_end_io`` + function for internal purposes, such as deferring the ioend completion to + a workqueue to run metadata update transactions from process context + before submitting the bio. + This function is optional. If this function is not provided, iomap will + default to ``iomap_bio_writeback_complete``. - ``discard_folio``: iomap calls this function after ``->writeback_folio`` fails to schedule I/O for any part of a dirty folio.
fs/iomap/buffered-io-bio.c +40 -2
57 lines not on this page · raw message
fs/iomap/buffered-io.c +6 -32
@@ -1450,39 +1450,13 @@ vm_fault_t iomap_page_mkwrite(struct vm_fault *vmf, const struct iomap_ops *ops, }EXPORT_SYMBOL_GPL (iomap_page_mkwrite); -/* -* Submit an ioend. -* -* 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 proess the errors. -*/ -int iomap_submit_ioend (struct iomap_writepage_ctx *wpc,int error) +int iomap_writeback_complete (struct iomap_writepage_ctx *wpc,int error) { -if (!wpc->ioend) -return error; - -/* -* Let the file systems prepare the I/O submission and hook in an I/O -* comletion handler. This also needs to happen in case after a -* failure happened so that the file system end I/O handler gets called -* to clean up. -*/ -if (wpc->ops->submit_ioend) { - error = wpc->ops->submit_ioend (wpc, error); - }else { -if (WARN_ON_ONCE (wpc->iomap.flags &IOMAP_F_ANON_WRITE )) - error = -EIO ; -if (!error) -iomap_submit_bio (&wpc->ioend->io_bio); - } - -if (error) -iomap_bio_ioend_error (wpc, error); +if (wpc->ops->writeback_complete) + error = wpc->ops->writeback_complete (wpc, error); +else + error =iomap_bio_writeback_complete (wpc, error,NULL ); - wpc->ioend =NULL ;return error; }
@@ -1661,6 +1635,6 @@ iomap_writepages(struct address_space *mapping, struct writeback_control *wbc, wpc->ops = ops;while ((folio =writeback_iter (mapping, wbc, folio, &error))) error =iomap_writepage_map (wpc, wbc, folio); -return iomap_submit_ioend (wpc, error); +return iomap_writeback_complete (wpc, error); }EXPORT_SYMBOL_GPL (iomap_writepages);
fs/iomap/internal.h +1 -3
@@ -32,7 +32,7 @@ u32 iomap_finish_ioend_buffered(struct iomap_ioend *ioend);u32 iomap_finish_ioend_direct (struct iomap_ioend *ioend);bool ifs_set_range_uptodate (struct folio *folio,struct iomap_folio_state *ifs,size_t off,size_t len); -int iomap_submit_ioend (struct iomap_writepage_ctx *wpc,int error); +int iomap_writeback_complete (struct iomap_writepage_ctx *wpc,int error);#ifdef CONFIG_BLOCK int iomap_bio_read_folio_sync(loff_t block_start, struct folio *folio,
@@ -40,12 +40,10 @@ int iomap_bio_read_folio_sync(loff_t block_start, struct folio *folio,void iomap_bio_readpage (const struct iomap *iomap,loff_t pos,struct iomap_readpage_ctx *ctx,size_t poff,size_t plen,loff_t length); -void iomap_bio_ioend_error (struct iomap_writepage_ctx *wpc,int error);void iomap_submit_bio (struct bio *bio);#else #define iomap_bio_read_folio_sync (...) (-ENOSYS)#define iomap_bio_readpage (...) ((void)0) -#define iomap_bio_ioend_error (...) ((void)0)#define iomap_submit_bio (...) ((void)0)#endif /* CONFIG_BLOCK */
fs/xfs/xfs_aops.c +12 -2
@@ -493,6 +493,11 @@ xfs_submit_ioend(return 0 ; } +static int xfs_writeback_complete (struct iomap_writepage_ctx *wpc,int error) +{ +return iomap_bio_writeback_complete (wpc, error, xfs_submit_ioend); +} +/* * If the folio has delalloc blocks on it, the caller is asking us to punch them * out. If we don't, we can leave a stale delalloc mapping covered by a clean
@@ -532,7 +537,7 @@ xfs_discard_folio(static const struct iomap_writeback_ops xfs_writeback_ops = { .writeback_folio = xfs_writeback_folio, - .submit_ioend = xfs_submit_ioend, + .writeback_complete = xfs_writeback_complete, .discard_folio = xfs_discard_folio, };
@@ -630,9 +635,14 @@ xfs_zoned_submit_ioend(return 0 ; } +static int xfs_zoned_writeback_complete (struct iomap_writepage_ctx *wpc,int error) +{ +return iomap_bio_writeback_complete (wpc, error, xfs_zoned_submit_ioend); +} +static const struct iomap_writeback_ops xfs_zoned_writeback_ops = { .writeback_folio = xfs_zoned_writeback_folio, - .submit_ioend = xfs_zoned_submit_ioend, + .writeback_complete = xfs_zoned_writeback_complete, .discard_folio = xfs_discard_folio, };
include/linux/iomap.h +19 -7
@@ -437,14 +437,10 @@ struct iomap_writeback_ops {int (*writeback_folio)(struct iomap_writeback_folio_range *ctx);/* -* Optional, allows the file systems to hook into bio submission, -* including overriding the bi_end_io handler. -* -* Returns 0 if the bio was successfully submitted, or a negative -* error code if status was non-zero or another error happened and -* the bio could not be submitted. +* Optional, allows the file system to call into this once +* ->writeback_folio() on all dirty ranges have been issued. */ -int (*submit_ioend)(struct iomap_writepage_ctx *wpc,int status); +int (*writeback_complete)(struct iomap_writepage_ctx *wpc,int status);/* * Optional, allows the file system to discard state on a page where
@@ -563,4 +559,20 @@ typedef int iomap_map_blocks_t(struct iomap_writepage_ctx *wpc,int iomap_bio_writeback_folio (struct iomap_writeback_folio_range *ctx,iomap_map_blocks_t map_blocks); +#ifdef CONFIG_BLOCK +/* +* Allows the file systems to hook into bio submission, including overriding +* the bi_end_io handler. +* +* Returns 0 if the bio was successfully submitted, or a negative +* error code if status was non-zero or another error happened and +* the bio could not be submitted. +*/ +typedef int iomap_submit_ioend_t (struct iomap_writepage_ctx *wpc,int error); +int iomap_bio_writeback_complete (struct iomap_writepage_ctx *wpc,int error, +iomap_submit_ioend_t submit_ioend); +#else +#define iomap_bio_writeback_complete (...) (-ENOSYS) +#endif /* CONFIG_BLOCK */ +#endif /* LINUX_IOMAP_H */
Signature · 1 line
2.47.1
PATCH v2 12/16 iomap: support more customized writeback handling
In reply to Joanne KoongAdd convenience helpers for more customized writeback handling. For example, the caller may wish to use iomap_start_folio_write() and iomap_finish_folio_write() for tracking when writeback state needs to be ended on the folio.
Add a void *private field as well that callers can pass into the ->writeback_folio() handler.
--- fs/iomap/buffered-io-bio.c | 12 ------------ fs/iomap/buffered-io.c | 24 ++++++++++++++++++++++++ include/linux/iomap.h | 6 ++++++ 3 files changed, 30 insertions(+), 12 deletions(-)
fs/iomap/buffered-io-bio.c +0 -12
@@ -99,18 +99,6 @@ int iomap_bio_read_folio_sync(loff_t block_start, struct folio *folio,return submit_bio_wait (&bio); } -static 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); -} -/* * We're now finished for good with this ioend structure. Update the page * state, release holds on bios, and finally free up memory. Do not use the
fs/iomap/buffered-io.c +24 -0
@@ -1638,3 +1638,27 @@ iomap_writepages(struct address_space *mapping, struct writeback_control *wbc,return iomap_writeback_complete (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); +} +EXPORT_SYMBOL_GPL (iomap_finish_folio_write);
include/linux/iomap.h +6 -0
@@ -454,6 +454,7 @@ struct iomap_writepage_ctx {struct iomap_ioend *ioend;const struct iomap_writeback_ops *ops;u32 nr_folios;/* folios added to the ioend */ +void *private; };struct iomap_writeback_folio_range {
@@ -575,4 +576,9 @@ int iomap_bio_writeback_complete(struct iomap_writepage_ctx *wpc, int error,#define iomap_bio_writeback_complete (...) (-ENOSYS)#endif /* CONFIG_BLOCK */ +void iomap_start_folio_write (struct inode *inode,struct folio *folio, +size_t len); +void iomap_finish_folio_write (struct inode *inode,struct folio *folio, +size_t len); +#endif /* LINUX_IOMAP_H */
Signature · 1 line
2.47.1
PATCH v2 13/16 iomap: add iomap_writeback_dirty_folio()
In reply to Joanne KoongAdd iomap_writeback_dirty_folio() for writing back a dirty folio. One use case of this is for laundering a folio.
--- fs/iomap/buffered-io.c | 27 +++++++++++++++++++-------- include/linux/iomap.h | 3 +++ 2 files changed, 22 insertions(+), 8 deletions(-)
fs/iomap/buffered-io.c +19 -8
@@ -1518,7 +1518,7 @@ static bool iomap_writepage_handle_eof(struct folio *folio, struct inode *inode,return true; } -static int iomap_writepage_map (struct iomap_writepage_ctx *wpc, +static int iomap_writeback (struct iomap_writepage_ctx *wpc,struct writeback_control *wbc,struct folio *folio) {struct iomap_folio_state *ifs = folio->private;
@@ -1541,10 +1541,8 @@ static int iomap_writepage_map(struct iomap_writepage_ctx *wpc,trace_iomap_writepage (inode, pos,folio_size (folio)); -if (!iomap_writepage_handle_eof (folio, inode, &end_pos)) { -folio_unlock (folio); +if (!iomap_writepage_handle_eof (folio, inode, &end_pos))return 0 ; - }WARN_ON_ONCE (end_pos <= pos);if (i_blocks_per_folio (inode, folio) >1 ) {
@@ -1602,9 +1600,8 @@ static int iomap_writepage_map(struct iomap_writepage_ctx *wpc,* But we may end up either not actually writing any blocks, or (when * there are multiple blocks in a folio) all I/O might have finished * already at this point. In that case we need to clear the writeback -* bit ourselves right after unlocking the page. +* bit ourselves. */ -folio_unlock (folio);if (ifs) {if (atomic_dec_and_test (&ifs->write_bytes_pending))folio_end_writeback (folio);
@@ -1633,12 +1630,26 @@ iomap_writepages(struct address_space *mapping, struct writeback_control *wbc,return -EIO ; wpc->ops = ops; -while ((folio =writeback_iter (mapping, wbc, folio, &error))) - error =iomap_writepage_map (wpc, wbc, folio); +while ((folio =writeback_iter (mapping, wbc, folio, &error))) { + error =iomap_writeback (wpc, wbc, folio); +folio_unlock (folio); + }return iomap_writeback_complete (wpc, error); }EXPORT_SYMBOL_GPL (iomap_writepages); +int iomap_writeback_dirty_folio (struct folio *folio, +struct writeback_control *wbc,struct iomap_writepage_ctx *wpc, +const struct iomap_writeback_ops *ops) +{ +int error; + + wpc->ops = ops; + error =iomap_writeback (wpc, wbc, folio); +return iomap_writeback_complete (wpc, error); +} +EXPORT_SYMBOL_GPL (iomap_writeback_dirty_folio); +void iomap_start_folio_write (struct inode *inode,struct folio *folio,size_t len) {
include/linux/iomap.h +3 -0
@@ -478,6 +478,9 @@ void iomap_sort_ioends(struct list_head *ioend_list);int iomap_writepages (struct address_space *mapping,struct writeback_control *wbc,struct iomap_writepage_ctx *wpc,const struct iomap_writeback_ops *ops); +int iomap_writeback_dirty_folio (struct folio *folio, +struct writeback_control *wbc,struct iomap_writepage_ctx *wpc, +const struct iomap_writeback_ops *ops);/* * Flags for direct I/O ->end_io:
Signature · 1 line
2.47.1
PATCH v2 14/16 fuse: use iomap for buffered writes
In reply to Joanne KoongHave buffered writes go through iomap. This has two advantages:
* granular large folio synchronous reads
* granular large folio dirty tracking
If for example there is a 1 MB large folio and a write issued at pos 1 to pos 1 MB - 2, only the head and tail pages will need to be read in and marked uptodate instead of the entire folio needing to be read in. Non-relevant trailing pages are also skipped (eg if for a 1 MB large folio a write is issued at pos 1 to 4097, only the first two pages are read in and the ones after that are skipped).
iomap also has granular dirty tracking. This is useful in that when it comes to writeback time, only the dirty portions of the large folio will be written instead of having to write out the entire folio. For example if there is a 1 MB large folio and only 2 bytes in it are dirty, only the page for those dirty bytes will be written out. Please note that granular writeback is only done once fuse also uses iomap in writeback (separate commit).
--- fs/fuse/Kconfig | 1 + fs/fuse/file.c | 141 ++++++++++++++++++------------------------------ 2 files changed, 53 insertions(+), 89 deletions(-)
fs/fuse/Kconfig +1 -0
@@ -2,6 +2,7 @@ config FUSE_FS tristate "FUSE (Filesystem in Userspace) support" select FS_POSIX_ACL + select FS_IOMAP help With FUSE it is possible to implement a fully functional filesystem in a userspace program.
fs/fuse/file.c +52 -89
213 lines not on this page · raw message
Signature · 1 line
2.47.1
PATCH v2 15/16 fuse: use iomap for writeback
In reply to Joanne KoongUse iomap for dirty folio writeback in ->writepages(). This allows for granular dirty writeback of large folios.
Only the dirty portions of the large folio will be written instead of having to write out the entire folio. For example if there is a 1 MB large folio and only 2 bytes in it are dirty, only the page for those dirty bytes will be written out.
--- fs/fuse/file.c | 118 +++++++++++++++++++++++++++++-------------------- 1 file changed, 70 insertions(+), 48 deletions(-)
fs/fuse/file.c +70 -48
@@ -1835,7 +1835,7 @@ static void fuse_writepage_finish(struct fuse_writepage_args *wpa)* scope of the fi->lock alleviates xarray lock * contention and noticeably improves performance. */ -folio_end_writeback (ap->folios[i]); +iomap_finish_folio_write (inode, ap->folios[i],1 );dec_wb_stat (&bdi->wb,WB_WRITEBACK );wb_writeout_inc (&bdi->wb); }
@@ -2022,19 +2022,20 @@ static void fuse_writepage_add_to_bucket(struct fuse_conn *fc, }static void fuse_writepage_args_page_fill (struct fuse_writepage_args *wpa,struct folio *folio, -uint32_t folio_index) +uint32_t folio_index,loff_t offset,unsigned len) {struct inode *inode = folio->mapping->host;struct fuse_args_pages *ap = &wpa->ia.ap; ap->folios[folio_index] = folio; - ap->descs[folio_index].offset =0 ; - ap->descs[folio_index].length =folio_size (folio); + ap->descs[folio_index].offset = offset; + ap->descs[folio_index].length = len;inc_wb_stat (&inode_to_bdi (inode)->wb,WB_WRITEBACK ); }static struct fuse_writepage_args *fuse_writepage_args_setup (struct folio *folio, +size_t offset,struct fuse_file *ff) {struct inode *inode = folio->mapping->host;
@@ -2047,7 +2048,7 @@ static struct fuse_writepage_args *fuse_writepage_args_setup(struct folio *folioreturn NULL ;fuse_writepage_add_to_bucket (fc, wpa); -fuse_write_args_fill (&wpa->ia, ff,folio_pos (folio),0 ); +fuse_write_args_fill (&wpa->ia, ff,folio_pos (folio) + offset,0 ); wpa->ia.write.in.write_flags |=FUSE_WRITE_CACHE ; wpa->inode = inode; wpa->ia.ff = ff;
@@ -2103,7 +2104,7 @@ struct fuse_fill_wb_data {struct fuse_file *ff;struct inode *inode;unsigned int max_folios; -unsigned int nr_pages; +unsigned int nr_bytes; };static bool fuse_pages_realloc (struct fuse_fill_wb_data *data)
@@ -2145,21 +2146,28 @@ static void fuse_writepages_send(struct fuse_fill_wb_data *data) }static bool fuse_writepage_need_send (struct fuse_conn *fc,struct folio *folio, +loff_t offset,unsigned len,struct fuse_args_pages *ap,struct fuse_fill_wb_data *data) { +struct folio *prev_folio; +struct fuse_folio_desc prev_desc; +WARN_ON (!ap->num_folios);/* Reached max pages */ -if (data->nr_pages +folio_nr_pages (folio) > fc->max_pages) +if ((data->nr_bytes + len) /PAGE_SIZE > fc->max_pages)return true;/* Reached max write bytes */ -if ((data->nr_pages *PAGE_SIZE ) +folio_size (folio) > fc->max_write) +if (data->nr_bytes + len > fc->max_write)return true;/* Discontinuity */ -if (folio_next_index (ap->folios[ap->num_folios -1 ]) != folio->index) + prev_folio = ap->folios[ap->num_folios -1 ]; + prev_desc = ap->descs[ap->num_folios -1 ]; +if ((folio_pos (prev_folio) + prev_desc.offset + prev_desc.length) != +folio_pos (folio) + offset)return true;/* Need to grow the pages array? If so, did the expansion fail? */
@@ -2169,85 +2177,99 @@ static bool fuse_writepage_need_send(struct fuse_conn *fc, struct folio *folio,return false; } -static int fuse_writepages_fill (struct folio *folio, -struct writeback_control *wbc,void *_data) +static int fuse_iomap_writeback_folio (struct iomap_writeback_folio_range *ctx) { -struct fuse_fill_wb_data *data = _data; +struct fuse_fill_wb_data *data = ctx->wpc->private;struct fuse_writepage_args *wpa = data->wpa; +struct folio *folio = ctx->folio;struct fuse_args_pages *ap = &wpa->ia.ap; -struct inode *inode = data->inode; -struct fuse_inode *fi =get_fuse_inode (inode); +struct inode *inode = folio->mapping->host;struct fuse_conn *fc =get_fuse_conn (inode); -int err; +struct fuse_inode *fi =get_fuse_inode (inode); +loff_t offset =offset_in_folio (folio, ctx->pos); +unsigned len = ctx->dirty_len; + +/* len will always be page aligned */ +WARN_ON_ONCE (len & (PAGE_SIZE -1 ));if (!data->ff) { - err = -EIO ; data->ff =fuse_write_file_get (fi);if (!data->ff) - goto out_unlock; +return -EIO ; } -if (wpa &&fuse_writepage_need_send (fc, folio, ap, data)) { +iomap_start_folio_write (inode, folio,1 ); + ctx->async_writeback = true; + +if (wpa &&fuse_writepage_need_send (fc, folio, offset, len, ap, data)) {fuse_writepages_send (data); data->wpa =NULL ; - data->nr_pages =0 ; + data->nr_bytes =0 ; }if (data->wpa ==NULL ) { - err = -ENOMEM ; - wpa =fuse_writepage_args_setup (folio, data->ff); + wpa =fuse_writepage_args_setup (folio, offset, data->ff);if (!wpa) - goto out_unlock; +return -ENOMEM ;fuse_file_get (wpa->ia.ff); data->max_folios =1 ; ap = &wpa->ia.ap; } -folio_start_writeback (folio); -fuse_writepage_args_page_fill (wpa, folio, ap->num_folios); - data->nr_pages +=folio_nr_pages (folio); +fuse_writepage_args_page_fill (wpa, folio, ap->num_folios, + offset, len); + data->nr_bytes += len; - err =0 ; ap->num_folios++;if (!data->wpa) data->wpa = wpa; -out_unlock: -folio_unlock (folio); -return err; +return 0 ; +} + +static int fuse_iomap_writeback_complete (struct iomap_writepage_ctx *wpc,int error) +{ +struct fuse_fill_wb_data *data = wpc->private; + +WARN_ON_ONCE (!data); + +if (data->wpa) { +WARN_ON (!data->wpa->ia.ap.num_folios); +fuse_writepages_send (data); + } + +if (data->ff) +fuse_file_put (data->ff, false); + +return error; } +static const struct iomap_writeback_ops fuse_writeback_ops = { + .writeback_folio = fuse_iomap_writeback_folio, + .writeback_complete = fuse_iomap_writeback_complete, +}; +static int fuse_writepages (struct address_space *mapping,struct writeback_control *wbc) {struct inode *inode = mapping->host;struct fuse_conn *fc =get_fuse_conn (inode); -struct fuse_fill_wb_data data; -int err; +struct fuse_fill_wb_data data = { + .inode = inode, + }; +struct iomap_writepage_ctx wpc = { + .iomap.type =IOMAP_MAPPED , + .private = &data, + }; - err = -EIO ;if (fuse_is_bad (inode)) - goto out; +return -EIO ;if (wbc->sync_mode ==WB_SYNC_NONE && fc->num_background >= fc->congestion_threshold)return 0 ; - data.inode = inode; - data.wpa =NULL ; - data.ff =NULL ; - data.nr_pages =0 ; - - err =write_cache_pages (mapping, wbc, fuse_writepages_fill, &data); -if (data.wpa) { -WARN_ON (!data.wpa->ia.ap.num_folios); -fuse_writepages_send (&data); - } -if (data.ff) -fuse_file_put (data.ff, false); - -out: -return err; +return iomap_writepages (mapping, wbc, &wpc, &fuse_writeback_ops); }static int fuse_launder_folio (struct folio *folio)
Signature · 1 line
2.47.1
PATCH v2 16/16 fuse: use iomap for folio laundering
In reply to Joanne KoongUse iomap for folio laundering, which will do granular dirty writeback when laundering a large folio.
--- fs/fuse/file.c | 49 +++++++++---------------------------------------- 1 file changed, 9 insertions(+), 40 deletions(-)
fs/fuse/file.c +9 -40
@@ -2060,45 +2060,6 @@ static struct fuse_writepage_args *fuse_writepage_args_setup(struct folio *folioreturn wpa; } -static int fuse_writepage_locked (struct folio *folio) -{ -struct address_space *mapping = folio->mapping; -struct inode *inode = mapping->host; -struct fuse_inode *fi =get_fuse_inode (inode); -struct fuse_writepage_args *wpa; -struct fuse_args_pages *ap; -struct fuse_file *ff; -int error = -EIO ; - - ff =fuse_write_file_get (fi); -if (!ff) - goto err; - - wpa =fuse_writepage_args_setup (folio, ff); - error = -ENOMEM ; -if (!wpa) - goto err_writepage_args; - - ap = &wpa->ia.ap; - ap->num_folios =1 ; - -folio_start_writeback (folio); -fuse_writepage_args_page_fill (wpa, folio,0 ); - -spin_lock (&fi->lock); -list_add_tail (&wpa->queue_entry, &fi->queued_writes); -fuse_flush_writepages (inode); -spin_unlock (&fi->lock); - -return 0 ; - -err_writepage_args: -fuse_file_put (ff, false); -err: -mapping_set_error (folio->mapping, error); -return error; -} -struct fuse_fill_wb_data {struct fuse_writepage_args *wpa;struct fuse_file *ff;
@@ -2275,8 +2236,16 @@ static int fuse_writepages(struct address_space *mapping,static int fuse_launder_folio (struct folio *folio) {int err =0 ; +struct fuse_fill_wb_data data = { + .inode = folio->mapping->host, + }; +struct iomap_writepage_ctx wpc = { + .iomap.type =IOMAP_MAPPED , + .private = &data, + }; +if (folio_clear_dirty_for_io (folio)) { - err =fuse_writepage_locked (folio); + err =iomap_writeback_dirty_folio (folio,NULL , &wpc, &fuse_writeback_ops);if (!err)folio_wait_writeback (folio); }
Signature · 1 line
2.47.1