diff options
author | Tang Junhui <tang.junhui@zte.com.cn> | 2017-09-06 02:25:59 -0400 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2017-09-06 10:17:33 -0400 |
commit | 9baf30972b5568d8b5bc8b3c46a6ec5b58100463 (patch) | |
tree | 5e1e3c3180452c32d95a4c4e6aa98d1bd3229c41 | |
parent | 89b1fc54c257104df007c5888e3705e52b973d45 (diff) |
bcache: fix for gc and write-back race
gc and write-back get raced (see the email "bcache get stucked" I sended
before):
gc thread write-back thread
| |bch_writeback_thread()
|bch_gc_thread() |
| |==>read_dirty()
|==>bch_btree_gc() |
|==>btree_root() //get btree root |
| //node write locker |
|==>bch_btree_gc_root() |
| |==>read_dirty_submit()
| |==>write_dirty()
| |==>continue_at(cl,
| | write_dirty_finish,
| | system_wq);
| |==>write_dirty_finish()//excute
| | //in system_wq
| |==>bch_btree_insert()
| |==>bch_btree_map_leaf_nodes()
| |==>__bch_btree_map_nodes()
| |==>btree_root //try to get btree
| | //root node read
| | //lock
| |-----stuck here
|==>bch_btree_set_root()
|==>bch_journal_meta()
|==>bch_journal()
|==>journal_try_write()
|==>journal_write_unlocked() //journal_full(&c->journal)
| //condition satisfied
|==>continue_at(cl, journal_write, system_wq); //try to excute
| //journal_write in system_wq
| //but work queue is excuting
| //write_dirty_finish()
|==>closure_sync(); //wait journal_write execute
| //over and wake up gc,
|-------------stuck here
|==>release root node write locker
This patch alloc a separate work-queue for write-back thread to avoid such
race.
(Commit log re-organized by Coly Li to pass checkpatch.pl checking)
Signed-off-by: Tang Junhui <tang.junhui@zte.com.cn>
Acked-by: Coly Li <colyli@suse.de>
Cc: stable@vger.kernel.org
Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r-- | drivers/md/bcache/bcache.h | 1 | ||||
-rw-r--r-- | drivers/md/bcache/super.c | 2 | ||||
-rw-r--r-- | drivers/md/bcache/writeback.c | 9 |
3 files changed, 10 insertions, 2 deletions
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index dee542fff68e..2ed9bd231d84 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h | |||
@@ -333,6 +333,7 @@ struct cached_dev { | |||
333 | /* Limit number of writeback bios in flight */ | 333 | /* Limit number of writeback bios in flight */ |
334 | struct semaphore in_flight; | 334 | struct semaphore in_flight; |
335 | struct task_struct *writeback_thread; | 335 | struct task_struct *writeback_thread; |
336 | struct workqueue_struct *writeback_write_wq; | ||
336 | 337 | ||
337 | struct keybuf writeback_keys; | 338 | struct keybuf writeback_keys; |
338 | 339 | ||
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index c3fedd265d18..3b724fa2b68d 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c | |||
@@ -1059,6 +1059,8 @@ static void cached_dev_free(struct closure *cl) | |||
1059 | cancel_delayed_work_sync(&dc->writeback_rate_update); | 1059 | cancel_delayed_work_sync(&dc->writeback_rate_update); |
1060 | if (!IS_ERR_OR_NULL(dc->writeback_thread)) | 1060 | if (!IS_ERR_OR_NULL(dc->writeback_thread)) |
1061 | kthread_stop(dc->writeback_thread); | 1061 | kthread_stop(dc->writeback_thread); |
1062 | if (dc->writeback_write_wq) | ||
1063 | destroy_workqueue(dc->writeback_write_wq); | ||
1062 | 1064 | ||
1063 | mutex_lock(&bch_register_lock); | 1065 | mutex_lock(&bch_register_lock); |
1064 | 1066 | ||
diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c index 5abe6472b66b..34131439e28c 100644 --- a/drivers/md/bcache/writeback.c +++ b/drivers/md/bcache/writeback.c | |||
@@ -187,7 +187,7 @@ static void write_dirty(struct closure *cl) | |||
187 | 187 | ||
188 | closure_bio_submit(&io->bio, cl); | 188 | closure_bio_submit(&io->bio, cl); |
189 | 189 | ||
190 | continue_at(cl, write_dirty_finish, system_wq); | 190 | continue_at(cl, write_dirty_finish, io->dc->writeback_write_wq); |
191 | } | 191 | } |
192 | 192 | ||
193 | static void read_dirty_endio(struct bio *bio) | 193 | static void read_dirty_endio(struct bio *bio) |
@@ -207,7 +207,7 @@ static void read_dirty_submit(struct closure *cl) | |||
207 | 207 | ||
208 | closure_bio_submit(&io->bio, cl); | 208 | closure_bio_submit(&io->bio, cl); |
209 | 209 | ||
210 | continue_at(cl, write_dirty, system_wq); | 210 | continue_at(cl, write_dirty, io->dc->writeback_write_wq); |
211 | } | 211 | } |
212 | 212 | ||
213 | static void read_dirty(struct cached_dev *dc) | 213 | static void read_dirty(struct cached_dev *dc) |
@@ -516,6 +516,11 @@ void bch_cached_dev_writeback_init(struct cached_dev *dc) | |||
516 | 516 | ||
517 | int bch_cached_dev_writeback_start(struct cached_dev *dc) | 517 | int bch_cached_dev_writeback_start(struct cached_dev *dc) |
518 | { | 518 | { |
519 | dc->writeback_write_wq = alloc_workqueue("bcache_writeback_wq", | ||
520 | WQ_MEM_RECLAIM, 0); | ||
521 | if (!dc->writeback_write_wq) | ||
522 | return -ENOMEM; | ||
523 | |||
519 | dc->writeback_thread = kthread_create(bch_writeback_thread, dc, | 524 | dc->writeback_thread = kthread_create(bch_writeback_thread, dc, |
520 | "bcache_writeback"); | 525 | "bcache_writeback"); |
521 | if (IS_ERR(dc->writeback_thread)) | 526 | if (IS_ERR(dc->writeback_thread)) |