From a5ae460b0b11ab1ffbc5d08235c125b60d183574 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Tue, 9 Jun 2020 20:27:33 -0400 Subject: bcachefs: Hacky io-in-flight throttling We've been seeing btree updates get stuck, due to some sort of bug; when this happens, buffered writeback will keep queueing up writes that lead to the system running out of memory. Not sure if this kind of throttling is something we'll want to keep and improve, or get rid of when the bug with btree updates getting stuck is fixed. For now it should make debugging easier. Signed-off-by: Kent Overstreet --- fs/bcachefs/bcachefs.h | 1 + fs/bcachefs/io.c | 4 ++++ fs/bcachefs/super.c | 2 ++ 3 files changed, 7 insertions(+) diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h index 61000459659f..1adea7910883 100644 --- a/fs/bcachefs/bcachefs.h +++ b/fs/bcachefs/bcachefs.h @@ -723,6 +723,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/io.c b/fs/bcachefs/io.c index 4f39132d04ab..6287b04931ba 100644 --- a/fs/bcachefs/io.c +++ b/fs/bcachefs/io.c @@ -500,6 +500,8 @@ static void bch2_write_done(struct closure *cl) bch2_time_stats_update(&c->times[BCH_TIME_data_write], op->start_time); + up(&c->io_in_flight); + if (op->end_io) { EBUG_ON(cl->parent); closure_debug_destroy(cl); @@ -1258,6 +1260,8 @@ void bch2_write(struct closure *cl) goto err; } + down(&c->io_in_flight); + bch2_increment_clock(c, bio_sectors(bio), WRITE); data_len = min_t(u64, bio->bi_iter.bi_size, diff --git a/fs/bcachefs/super.c b/fs/bcachefs/super.c index 319f43acad92..18c23ab1e5d9 100644 --- a/fs/bcachefs/super.c +++ b/fs/bcachefs/super.c @@ -714,6 +714,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, 64); + c->copy_gc_enabled = 1; c->rebalance.enabled = 1; c->promote_whole_extents = true; -- cgit v1.2.3