Commit da415a096fc06e49d1a15f7a06bcfe6ad44c5d38
Committed by
Kent Overstreet
1 parent
90db6919f5
Exists in
master
and in
13 other branches
bcache: Fix moving_gc deadlocking with a foreground write
Deadlock happened because a foreground write slept, waiting for a bucket to be allocated. Normally the gc would mark buckets available for invalidation. But the moving_gc was stuck waiting for outstanding writes to complete. These writes used the bcache_wq, the same queue foreground writes used. This fix gives moving_gc its own work queue, so it was still finish moving even if foreground writes are stuck waiting for allocation. It also makes work queue a parameter to the data_insert path, so moving_gc can use its workqueue for writes. Signed-off-by: Nicholas Swenson <nks@daterainc.com> Signed-off-by: Kent Overstreet <kmo@daterainc.com>
Showing 5 changed files with 16 additions and 8 deletions Side-by-side Diff
drivers/md/bcache/bcache.h
drivers/md/bcache/movinggc.c
... | ... | @@ -115,7 +115,7 @@ |
115 | 115 | closure_call(&op->cl, bch_data_insert, NULL, cl); |
116 | 116 | } |
117 | 117 | |
118 | - continue_at(cl, write_moving_finish, system_wq); | |
118 | + continue_at(cl, write_moving_finish, op->wq); | |
119 | 119 | } |
120 | 120 | |
121 | 121 | static void read_moving_submit(struct closure *cl) |
... | ... | @@ -125,7 +125,7 @@ |
125 | 125 | |
126 | 126 | bch_submit_bbio(bio, io->op.c, &io->w->key, 0); |
127 | 127 | |
128 | - continue_at(cl, write_moving, system_wq); | |
128 | + continue_at(cl, write_moving, io->op.wq); | |
129 | 129 | } |
130 | 130 | |
131 | 131 | static void read_moving(struct cache_set *c) |
... | ... | @@ -160,6 +160,7 @@ |
160 | 160 | io->w = w; |
161 | 161 | io->op.inode = KEY_INODE(&w->key); |
162 | 162 | io->op.c = c; |
163 | + io->op.wq = c->moving_gc_wq; | |
163 | 164 | |
164 | 165 | moving_init(io); |
165 | 166 | bio = &io->bio.bio; |
drivers/md/bcache/request.c
... | ... | @@ -248,7 +248,7 @@ |
248 | 248 | atomic_dec_bug(journal_ref); |
249 | 249 | |
250 | 250 | if (!op->insert_data_done) |
251 | - continue_at(cl, bch_data_insert_start, bcache_wq); | |
251 | + continue_at(cl, bch_data_insert_start, op->wq); | |
252 | 252 | |
253 | 253 | bch_keylist_free(&op->insert_keys); |
254 | 254 | closure_return(cl); |
... | ... | @@ -297,7 +297,7 @@ |
297 | 297 | op->insert_data_done = true; |
298 | 298 | bio_put(bio); |
299 | 299 | out: |
300 | - continue_at(cl, bch_data_insert_keys, bcache_wq); | |
300 | + continue_at(cl, bch_data_insert_keys, op->wq); | |
301 | 301 | } |
302 | 302 | |
303 | 303 | static void bch_data_insert_error(struct closure *cl) |
... | ... | @@ -340,7 +340,7 @@ |
340 | 340 | if (op->writeback) |
341 | 341 | op->error = error; |
342 | 342 | else if (!op->replace) |
343 | - set_closure_fn(cl, bch_data_insert_error, bcache_wq); | |
343 | + set_closure_fn(cl, bch_data_insert_error, op->wq); | |
344 | 344 | else |
345 | 345 | set_closure_fn(cl, NULL, NULL); |
346 | 346 | } |
... | ... | @@ -376,7 +376,7 @@ |
376 | 376 | if (bch_keylist_realloc(&op->insert_keys, |
377 | 377 | 3 + (op->csum ? 1 : 0), |
378 | 378 | op->c)) |
379 | - continue_at(cl, bch_data_insert_keys, bcache_wq); | |
379 | + continue_at(cl, bch_data_insert_keys, op->wq); | |
380 | 380 | |
381 | 381 | k = op->insert_keys.top; |
382 | 382 | bkey_init(k); |
... | ... | @@ -413,7 +413,7 @@ |
413 | 413 | } while (n != bio); |
414 | 414 | |
415 | 415 | op->insert_data_done = true; |
416 | - continue_at(cl, bch_data_insert_keys, bcache_wq); | |
416 | + continue_at(cl, bch_data_insert_keys, op->wq); | |
417 | 417 | err: |
418 | 418 | /* bch_alloc_sectors() blocks if s->writeback = true */ |
419 | 419 | BUG_ON(op->writeback); |
... | ... | @@ -442,7 +442,7 @@ |
442 | 442 | bio_put(bio); |
443 | 443 | |
444 | 444 | if (!bch_keylist_empty(&op->insert_keys)) |
445 | - continue_at(cl, bch_data_insert_keys, bcache_wq); | |
445 | + continue_at(cl, bch_data_insert_keys, op->wq); | |
446 | 446 | else |
447 | 447 | closure_return(cl); |
448 | 448 | } |
... | ... | @@ -824,6 +824,7 @@ |
824 | 824 | s->iop.error = 0; |
825 | 825 | s->iop.flags = 0; |
826 | 826 | s->iop.flush_journal = (bio->bi_rw & (REQ_FLUSH|REQ_FUA)) != 0; |
827 | + s->iop.wq = bcache_wq; | |
827 | 828 | |
828 | 829 | return s; |
829 | 830 | } |
drivers/md/bcache/request.h
drivers/md/bcache/super.c
... | ... | @@ -1356,6 +1356,8 @@ |
1356 | 1356 | bch_bset_sort_state_free(&c->sort); |
1357 | 1357 | free_pages((unsigned long) c->uuids, ilog2(bucket_pages(c))); |
1358 | 1358 | |
1359 | + if (c->moving_gc_wq) | |
1360 | + destroy_workqueue(c->moving_gc_wq); | |
1359 | 1361 | if (c->bio_split) |
1360 | 1362 | bioset_free(c->bio_split); |
1361 | 1363 | if (c->fill_iter) |
... | ... | @@ -1522,6 +1524,7 @@ |
1522 | 1524 | !(c->fill_iter = mempool_create_kmalloc_pool(1, iter_size)) || |
1523 | 1525 | !(c->bio_split = bioset_create(4, offsetof(struct bbio, bio))) || |
1524 | 1526 | !(c->uuids = alloc_bucket_pages(GFP_KERNEL, c)) || |
1527 | + !(c->moving_gc_wq = create_workqueue("bcache_gc")) || | |
1525 | 1528 | bch_journal_alloc(c) || |
1526 | 1529 | bch_btree_cache_alloc(c) || |
1527 | 1530 | bch_open_buckets_alloc(c) || |