summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKent Overstreet <kent.overstreet@gmail.com>2021-05-18 23:53:43 -0400
committerKent Overstreet <kent.overstreet@linux.dev>2023-10-22 17:09:03 -0400
commitef1b20924b0f584740094fdf7166acfb80338f0c (patch)
treef8abf635aa829ef4e61243ddcd9bac546455cc12
parented34341189478344eb54588ce73f190b86da4d5e (diff)
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 <kent.overstreet@linux.dev>
-rw-r--r--fs/bcachefs/bcachefs.h2
-rw-r--r--fs/bcachefs/fs-io.c4
-rw-r--r--fs/bcachefs/super.c2
3 files changed, 8 insertions, 0 deletions
diff --git a/fs/bcachefs/bcachefs.h b/fs/bcachefs/bcachefs.h
index c47e69931b8a..c5cafbd6d87a 100644
--- a/fs/bcachefs/bcachefs.h
+++ b/fs/bcachefs/bcachefs.h
@@ -191,6 +191,7 @@
#include <linux/percpu-rwsem.h>
#include <linux/rhashtable.h>
#include <linux/rwsem.h>
+#include <linux/semaphore.h>
#include <linux/seqlock.h>
#include <linux/shrinker.h>
#include <linux/srcu.h>
@@ -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 fbf171a4c191..763195ed0b3c 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 71493b5ff695..b0bcd3bbb53b 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;