bcachefs: Ratelimiting for writeback IOs
authorKent Overstreet <kent.overstreet@gmail.com>
Wed, 19 May 2021 03:53:43 +0000 (23:53 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:09:03 +0000 (17:09 -0400)
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>
fs/bcachefs/bcachefs.h
fs/bcachefs/fs-io.c
fs/bcachefs/super.c

index c47e69931b8aa3e4a6bf2dd5bb1a6983c91df5bd..c5cafbd6d87a3cba2a742afd83a01c1a2ef51342 100644 (file)
 #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;
index fbf171a4c1914308e373a5b69c39725128da7de3..763195ed0b3c5f552bdb535db698f9af406564b2 100644 (file)
@@ -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);
index 71493b5ff6951d5e9ca30183ef13f417866a6f43..b0bcd3bbb53b847182ef13cdc8fce099a10dcedc 100644 (file)
@@ -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;