From: Kent Overstreet Date: Wed, 19 May 2021 03:53:43 +0000 (-0400) Subject: bcachefs: Ratelimiting for writeback IOs X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=ef1b20924b0f584740094fdf7166acfb80338f0c;p=linux.git bcachefs: Ratelimiting for writeback IOs Writeback throttling is a kernel config option and not always enabled. When it's not enabled we need a fallback, to avoid unbounded memory pinning and work item backlogs. Signed-off-by: Kent Overstreet --- diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index c47e69931b8aa..c5cafbd6d87a3 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -191,6 +191,7 @@ #include #include #include +#include #include #include #include @@ -746,6 +747,7 @@ struct bch_fs { struct rw_semaphore gc_lock; /* IO PATH */ + struct semaphore io_in_flight; struct bio_set bio_read; struct bio_set bio_read_split; struct bio_set bio_write; diff --git a/fs/bcachefs/fs-io.c b/fs/bcachefs/fs-io.c index fbf171a4c1914..763195ed0b3c5 100644 --- a/fs/bcachefs/fs-io.c +++ b/fs/bcachefs/fs-io.c @@ -997,6 +997,8 @@ static void bch2_writepage_io_done(struct closure *cl) struct bio_vec *bvec; unsigned i; + up(&io->op.c->io_in_flight); + if (io->op.error) { set_bit(EI_INODE_ERROR, &io->inode->ei_flags); @@ -1059,6 +1061,8 @@ static void bch2_writepage_do_io(struct bch_writepage_state *w) { struct bch_writepage_io *io = w->io; + down(&io->op.c->io_in_flight); + w->io = NULL; closure_call(&io->op.cl, bch2_write, NULL, &io->cl); continue_at(&io->cl, bch2_writepage_io_done, NULL); diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index 71493b5ff6951..b0bcd3bbb53b8 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -717,6 +717,8 @@ static struct bch_fs *bch2_fs_alloc(struct bch_sb *sb, struct bch_opts opts) seqcount_init(&c->usage_lock); + sema_init(&c->io_in_flight, 128); + c->copy_gc_enabled = 1; c->rebalance.enabled = 1; c->promote_whole_extents = true;