summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2020-06-09 20:27:33 -0400
committerKent Overstreet <kent.overstreet@gmail.com>2020-06-09 21:32:47 -0400
commita5ae460b0b11ab1ffbc5d08235c125b60d183574 (patch)
treeea77f53adffebf357d49c74ddfc0fef8767aa852
parent0512dfd6eb84f7cf365b801ef1be2f9092a02a84 (diff)
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 <kent.overstreet@gmail.com>
-rw-r--r--fs/bcachefs/bcachefs.h1
-rw-r--r--fs/bcachefs/io.c4
-rw-r--r--fs/bcachefs/super.c2
3 files changed, 7 insertions, 0 deletions
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;