Skip to content

Commit 2a4e749

Browse files
Brian FosterKent Overstreet
authored andcommitted
bcachefs: allow writeback to fill bio completely
The bcachefs folio writeback code includes a bio full check as well as a fixed size check to determine when to split off and submit writeback I/O. The inclusive check of the latter against the limit means that writeback can submit slightly prematurely. This is not a functional problem, but results in unnecessarily split I/Os and extent merging. This can be observed with a buffered write sized exactly to the current maximum value (1MB) and with key_merging_disabled=1. The latter prevents the merge from the second write such that a subsequent check of the extent list shows a 1020k extent followed by a contiguous 4k extent. The purpose for the fixed size check is also undocumented and somewhat obscure. Lift this check into a new helper that wraps the bio check, fix the comparison logic, and add a comment to document the purpose and how we might improve on this in the future. Signed-off-by: Brian Foster <bfoster@redhat.com> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 0e91d3a commit 2a4e749

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

fs/bcachefs/fs-io-buffered.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,21 @@ static inline struct bch_writepage_state bch_writepage_state_init(struct bch_fs
389389
return ret;
390390
}
391391

392+
/*
393+
* Determine when a writepage io is full. We have to limit writepage bios to a
394+
* single page per bvec (i.e. 1MB with 4k pages) because that is the limit to
395+
* what the bounce path in bch2_write_extent() can handle. In theory we could
396+
* loosen this restriction for non-bounce I/O, but we don't have that context
397+
* here. Ideally, we can up this limit and make it configurable in the future
398+
* when the bounce path can be enhanced to accommodate larger source bios.
399+
*/
400+
static inline bool bch_io_full(struct bch_writepage_io *io, unsigned len)
401+
{
402+
struct bio *bio = &io->op.wbio.bio;
403+
return bio_full(bio, len) ||
404+
(bio->bi_iter.bi_size + len > BIO_MAX_VECS * PAGE_SIZE);
405+
}
406+
392407
static void bch2_writepage_io_done(struct bch_write_op *op)
393408
{
394409
struct bch_writepage_io *io =
@@ -606,9 +621,7 @@ static int __bch2_writepage(struct folio *folio,
606621

607622
if (w->io &&
608623
(w->io->op.res.nr_replicas != nr_replicas_this_write ||
609-
bio_full(&w->io->op.wbio.bio, sectors << 9) ||
610-
w->io->op.wbio.bio.bi_iter.bi_size + (sectors << 9) >=
611-
(BIO_MAX_VECS * PAGE_SIZE) ||
624+
bch_io_full(w->io, sectors << 9) ||
612625
bio_end_sector(&w->io->op.wbio.bio) != sector))
613626
bch2_writepage_do_io(w);
614627

0 commit comments

Comments
 (0)