Merge branch 'for-4.15/block' of git://git.kernel.dk/linux-block
[linux-2.6-microblaze.git] / drivers / md / bcache / alloc.c
index 0803563..a27d852 100644 (file)
@@ -407,7 +407,8 @@ long bch_bucket_alloc(struct cache *ca, unsigned reserve, bool wait)
 
        finish_wait(&ca->set->bucket_wait, &w);
 out:
-       wake_up_process(ca->alloc_thread);
+       if (ca->alloc_thread)
+               wake_up_process(ca->alloc_thread);
 
        trace_bcache_alloc(ca, reserve);
 
@@ -442,6 +443,11 @@ out:
                b->prio = INITIAL_PRIO;
        }
 
+       if (ca->set->avail_nbuckets > 0) {
+               ca->set->avail_nbuckets--;
+               bch_update_bucket_in_use(ca->set, &ca->set->gc_stats);
+       }
+
        return r;
 }
 
@@ -449,6 +455,11 @@ void __bch_bucket_free(struct cache *ca, struct bucket *b)
 {
        SET_GC_MARK(b, 0);
        SET_GC_SECTORS_USED(b, 0);
+
+       if (ca->set->avail_nbuckets < ca->set->nbuckets) {
+               ca->set->avail_nbuckets++;
+               bch_update_bucket_in_use(ca->set, &ca->set->gc_stats);
+       }
 }
 
 void bch_bucket_free(struct cache_set *c, struct bkey *k)
@@ -601,7 +612,7 @@ bool bch_alloc_sectors(struct cache_set *c, struct bkey *k, unsigned sectors,
 
        /*
         * If we had to allocate, we might race and not need to allocate the
-        * second time we call find_data_bucket(). If we allocated a bucket but
+        * second time we call pick_data_bucket(). If we allocated a bucket but
         * didn't use it, drop the refcount bch_bucket_alloc_set() took:
         */
        if (KEY_PTRS(&alloc.key))