diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2019-01-22 20:04:06 -0500 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2019-04-03 12:44:03 -0400 |
commit | 8e5e355eaa8145e0260b8c9fdb3c90471f2b67be (patch) | |
tree | 9d786c7a02549048d5701eb289cb21b9c6bb880e | |
parent | ba21597ffc0efa828b41f93158d87668db605b1f (diff) |
bcachefs: Fix fifo overflow in allocator startup
-rw-r--r-- | fs/bcachefs/alloc_background.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/fs/bcachefs/alloc_background.c b/fs/bcachefs/alloc_background.c index 6de6e26384b2..eb6b22177d26 100644 --- a/fs/bcachefs/alloc_background.c +++ b/fs/bcachefs/alloc_background.c @@ -1333,6 +1333,24 @@ static void allocator_start_issue_discards(struct bch_fs *c) ca->mi.bucket_size, GFP_NOIO, 0); } +static int resize_free_inc(struct bch_dev *ca) +{ + alloc_fifo free_inc; + + if (!fifo_full(&ca->free_inc)) + return 0; + + if (!init_fifo(&free_inc, + ca->free_inc.size * 2, + GFP_KERNEL)) + return -ENOMEM; + + fifo_move(&free_inc, &ca->free_inc); + swap(free_inc, ca->free_inc); + free_fifo(&free_inc); + return 0; +} + static int __bch2_fs_allocator_start(struct bch_fs *c) { struct bch_dev *ca; @@ -1408,6 +1426,12 @@ not_enough: while (!fifo_full(&ca->free[RESERVE_BTREE]) && (bu = next_alloc_bucket(ca)) >= 0) { + ret = resize_free_inc(ca); + if (ret) { + percpu_ref_put(&ca->io_ref); + return ret; + } + bch2_invalidate_one_bucket(c, ca, bu, &journal_seq); |