]> git.karo-electronics.de Git - linux-beck.git/commitdiff
bcache: Fix moving_gc deadlocking with a foreground write
authorNicholas Swenson <nks@daterainc.com>
Fri, 10 Jan 2014 00:03:04 +0000 (16:03 -0800)
committerKent Overstreet <kmo@daterainc.com>
Tue, 18 Mar 2014 19:22:33 +0000 (12:22 -0700)
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>
drivers/md/bcache/bcache.h
drivers/md/bcache/movinggc.c
drivers/md/bcache/request.c
drivers/md/bcache/request.h
drivers/md/bcache/super.c

index a4c7306ff43de4f1a928962251ffaea384dcb287..6d814f463d9ef6f6450274696d522dd3ff2b77d1 100644 (file)
@@ -628,6 +628,8 @@ struct cache_set {
        /* Number of moving GC bios in flight */
        struct semaphore        moving_in_flight;
 
+       struct workqueue_struct *moving_gc_wq;
+
        struct btree            *root;
 
 #ifdef CONFIG_BCACHE_DEBUG
index 9eb60d102de84532e3a662390b1ba2934b744673..8c7205186d081edda0d09030f94753009768e0d0 100644 (file)
@@ -115,7 +115,7 @@ static void write_moving(struct closure *cl)
                closure_call(&op->cl, bch_data_insert, NULL, cl);
        }
 
-       continue_at(cl, write_moving_finish, system_wq);
+       continue_at(cl, write_moving_finish, op->wq);
 }
 
 static void read_moving_submit(struct closure *cl)
@@ -125,7 +125,7 @@ static void read_moving_submit(struct closure *cl)
 
        bch_submit_bbio(bio, io->op.c, &io->w->key, 0);
 
-       continue_at(cl, write_moving, system_wq);
+       continue_at(cl, write_moving, io->op.wq);
 }
 
 static void read_moving(struct cache_set *c)
@@ -160,6 +160,7 @@ static void read_moving(struct cache_set *c)
                io->w           = w;
                io->op.inode    = KEY_INODE(&w->key);
                io->op.c        = c;
+               io->op.wq       = c->moving_gc_wq;
 
                moving_init(io);
                bio = &io->bio.bio;
index fc14ba3f6d050971c3f6f7e459b20b3e553915bf..3e880869871f4857150ef8af684643f4dcbc9977 100644 (file)
@@ -248,7 +248,7 @@ static void bch_data_insert_keys(struct closure *cl)
                atomic_dec_bug(journal_ref);
 
        if (!op->insert_data_done)
-               continue_at(cl, bch_data_insert_start, bcache_wq);
+               continue_at(cl, bch_data_insert_start, op->wq);
 
        bch_keylist_free(&op->insert_keys);
        closure_return(cl);
@@ -297,7 +297,7 @@ static void bch_data_invalidate(struct closure *cl)
        op->insert_data_done = true;
        bio_put(bio);
 out:
-       continue_at(cl, bch_data_insert_keys, bcache_wq);
+       continue_at(cl, bch_data_insert_keys, op->wq);
 }
 
 static void bch_data_insert_error(struct closure *cl)
@@ -340,7 +340,7 @@ static void bch_data_insert_endio(struct bio *bio, int error)
                if (op->writeback)
                        op->error = error;
                else if (!op->replace)
-                       set_closure_fn(cl, bch_data_insert_error, bcache_wq);
+                       set_closure_fn(cl, bch_data_insert_error, op->wq);
                else
                        set_closure_fn(cl, NULL, NULL);
        }
@@ -376,7 +376,7 @@ static void bch_data_insert_start(struct closure *cl)
                if (bch_keylist_realloc(&op->insert_keys,
                                        3 + (op->csum ? 1 : 0),
                                        op->c))
-                       continue_at(cl, bch_data_insert_keys, bcache_wq);
+                       continue_at(cl, bch_data_insert_keys, op->wq);
 
                k = op->insert_keys.top;
                bkey_init(k);
@@ -413,7 +413,7 @@ static void bch_data_insert_start(struct closure *cl)
        } while (n != bio);
 
        op->insert_data_done = true;
-       continue_at(cl, bch_data_insert_keys, bcache_wq);
+       continue_at(cl, bch_data_insert_keys, op->wq);
 err:
        /* bch_alloc_sectors() blocks if s->writeback = true */
        BUG_ON(op->writeback);
@@ -442,7 +442,7 @@ err:
                bio_put(bio);
 
                if (!bch_keylist_empty(&op->insert_keys))
-                       continue_at(cl, bch_data_insert_keys, bcache_wq);
+                       continue_at(cl, bch_data_insert_keys, op->wq);
                else
                        closure_return(cl);
        }
@@ -824,6 +824,7 @@ static inline struct search *search_alloc(struct bio *bio,
        s->iop.error            = 0;
        s->iop.flags            = 0;
        s->iop.flush_journal    = (bio->bi_rw & (REQ_FLUSH|REQ_FUA)) != 0;
+       s->iop.wq               = bcache_wq;
 
        return s;
 }
index 39f21dbedc38b43ec7bf4818cfca319d27d27433..c117c4082aa2683ded10901962330fe4c83b2d2e 100644 (file)
@@ -7,6 +7,7 @@ struct data_insert_op {
        struct closure          cl;
        struct cache_set        *c;
        struct bio              *bio;
+       struct workqueue_struct *wq;
 
        unsigned                inode;
        uint16_t                write_point;
index fb343276beef7f2ab176bae1d7347822f3a87bca..ddfde380b49fb7ada3fb57919be24e84a2cecc72 100644 (file)
@@ -1356,6 +1356,8 @@ static void cache_set_free(struct closure *cl)
        bch_bset_sort_state_free(&c->sort);
        free_pages((unsigned long) c->uuids, ilog2(bucket_pages(c)));
 
+       if (c->moving_gc_wq)
+               destroy_workqueue(c->moving_gc_wq);
        if (c->bio_split)
                bioset_free(c->bio_split);
        if (c->fill_iter)
@@ -1522,6 +1524,7 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb)
            !(c->fill_iter = mempool_create_kmalloc_pool(1, iter_size)) ||
            !(c->bio_split = bioset_create(4, offsetof(struct bbio, bio))) ||
            !(c->uuids = alloc_bucket_pages(GFP_KERNEL, c)) ||
+           !(c->moving_gc_wq = create_workqueue("bcache_gc")) ||
            bch_journal_alloc(c) ||
            bch_btree_cache_alloc(c) ||
            bch_open_buckets_alloc(c) ||