]> git.karo-electronics.de Git - linux-beck.git/commitdiff
bcache: Make gc wakeup sane, remove set_task_state()
authorKent Overstreet <kent.overstreet@gmail.com>
Thu, 27 Oct 2016 03:31:17 +0000 (20:31 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 23 Feb 2017 16:44:36 +0000 (17:44 +0100)
commit be628be09563f8f6e81929efbd7cf3f45c344416 upstream.

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Cc: Coly Li <colyli@suse.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/md/bcache/bcache.h
drivers/md/bcache/btree.c
drivers/md/bcache/btree.h
drivers/md/bcache/request.c
drivers/md/bcache/super.c

index 6b420a55c7459f1af42b9dd9c920dce63bd7d089..c3ea03c9a1a8ef603a25934ccbe32ea4bfca3d66 100644 (file)
@@ -425,7 +425,7 @@ struct cache {
         * until a gc finishes - otherwise we could pointlessly burn a ton of
         * cpu
         */
-       unsigned                invalidate_needs_gc:1;
+       unsigned                invalidate_needs_gc;
 
        bool                    discard; /* Get rid of? */
 
@@ -593,8 +593,8 @@ struct cache_set {
 
        /* Counts how many sectors bio_insert has added to the cache */
        atomic_t                sectors_to_gc;
+       wait_queue_head_t       gc_wait;
 
-       wait_queue_head_t       moving_gc_wait;
        struct keybuf           moving_gc_keys;
        /* Number of moving GC bios in flight */
        struct semaphore        moving_in_flight;
index 81d3db40cd7be634ca7697a928654a89650ef804..2efdce07247cca54db812dd64e82146fb0526d07 100644 (file)
@@ -1757,32 +1757,34 @@ static void bch_btree_gc(struct cache_set *c)
        bch_moving_gc(c);
 }
 
-static int bch_gc_thread(void *arg)
+static bool gc_should_run(struct cache_set *c)
 {
-       struct cache_set *c = arg;
        struct cache *ca;
        unsigned i;
 
-       while (1) {
-again:
-               bch_btree_gc(c);
+       for_each_cache(ca, c, i)
+               if (ca->invalidate_needs_gc)
+                       return true;
 
-               set_current_state(TASK_INTERRUPTIBLE);
-               if (kthread_should_stop())
-                       break;
+       if (atomic_read(&c->sectors_to_gc) < 0)
+               return true;
 
-               mutex_lock(&c->bucket_lock);
+       return false;
+}
 
-               for_each_cache(ca, c, i)
-                       if (ca->invalidate_needs_gc) {
-                               mutex_unlock(&c->bucket_lock);
-                               set_current_state(TASK_RUNNING);
-                               goto again;
-                       }
+static int bch_gc_thread(void *arg)
+{
+       struct cache_set *c = arg;
 
-               mutex_unlock(&c->bucket_lock);
+       while (1) {
+               wait_event_interruptible(c->gc_wait,
+                          kthread_should_stop() || gc_should_run(c));
 
-               schedule();
+               if (kthread_should_stop())
+                       break;
+
+               set_gc_sectors(c);
+               bch_btree_gc(c);
        }
 
        return 0;
@@ -1790,11 +1792,10 @@ again:
 
 int bch_gc_thread_start(struct cache_set *c)
 {
-       c->gc_thread = kthread_create(bch_gc_thread, c, "bcache_gc");
+       c->gc_thread = kthread_run(bch_gc_thread, c, "bcache_gc");
        if (IS_ERR(c->gc_thread))
                return PTR_ERR(c->gc_thread);
 
-       set_task_state(c->gc_thread, TASK_INTERRUPTIBLE);
        return 0;
 }
 
index 5c391fa01bedbfba3f1dea062605460ccadc1c6a..9b80417cd547f52c264c1b4b993f3ee2155405f2 100644 (file)
@@ -260,8 +260,7 @@ void bch_initial_mark_key(struct cache_set *, int, struct bkey *);
 
 static inline void wake_up_gc(struct cache_set *c)
 {
-       if (c->gc_thread)
-               wake_up_process(c->gc_thread);
+       wake_up(&c->gc_wait);
 }
 
 #define MAP_DONE       0
index 40ffe5e424b3025d562a63e5bae9fd1c1d78f2a3..a37c1776f2e36c05e1a3824e2c416030e57b326c 100644 (file)
@@ -196,10 +196,8 @@ static void bch_data_insert_start(struct closure *cl)
        struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
        struct bio *bio = op->bio, *n;
 
-       if (atomic_sub_return(bio_sectors(bio), &op->c->sectors_to_gc) < 0) {
-               set_gc_sectors(op->c);
+       if (atomic_sub_return(bio_sectors(bio), &op->c->sectors_to_gc) < 0)
                wake_up_gc(op->c);
-       }
 
        if (op->bypass)
                return bch_data_invalidate(cl);
index 849ad441cd76ba6b04ba2fa2aaac51471acdfd67..66669c8f41610db3728119cf603dcab073ccaaf2 100644 (file)
@@ -1491,6 +1491,7 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb)
        mutex_init(&c->bucket_lock);
        init_waitqueue_head(&c->btree_cache_wait);
        init_waitqueue_head(&c->bucket_wait);
+       init_waitqueue_head(&c->gc_wait);
        sema_init(&c->uuid_write_mutex, 1);
 
        spin_lock_init(&c->btree_gc_time.lock);
@@ -1550,6 +1551,7 @@ static void run_cache_set(struct cache_set *c)
 
        for_each_cache(ca, c, i)
                c->nbuckets += ca->sb.nbuckets;
+       set_gc_sectors(c);
 
        if (CACHE_SYNC(&c->sb)) {
                LIST_HEAD(journal);