diff options
author | Kent Overstreet <kent.overstreet@gmail.com> | 2016-10-20 20:55:58 -0800 |
---|---|---|
committer | Kent Overstreet <kent.overstreet@gmail.com> | 2016-10-20 20:55:58 -0800 |
commit | 46cafafafeede8f6e3f8d2f7bd182fc1a8dfdbd7 (patch) | |
tree | d1225fde28ed509a52d9b4e6d12dbcda3c4d6d9b | |
parent | 59209d4374d5183365b726893b4817e184ed5a37 (diff) |
bcache: Make btree coalescing triggerable from sysfs
-rw-r--r-- | drivers/md/bcache/bcache.h | 1 | ||||
-rw-r--r-- | drivers/md/bcache/btree_gc.c | 31 | ||||
-rw-r--r-- | drivers/md/bcache/btree_gc.h | 1 | ||||
-rw-r--r-- | drivers/md/bcache/super.c | 1 | ||||
-rw-r--r-- | drivers/md/bcache/sysfs.c | 10 |
5 files changed, 19 insertions, 25 deletions
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h index 7256c0ebc3b8..3f9294c17cda 100644 --- a/drivers/md/bcache/bcache.h +++ b/drivers/md/bcache/bcache.h @@ -699,7 +699,6 @@ struct cache_set { * it's not while a gc is in progress. */ struct rw_semaphore gc_lock; - struct mutex trigger_gc_lock; /* IO PATH */ struct bio_set bio_read; diff --git a/drivers/md/bcache/btree_gc.c b/drivers/md/bcache/btree_gc.c index 77b6c34b839b..4f4b8c14fefc 100644 --- a/drivers/md/bcache/btree_gc.c +++ b/drivers/md/bcache/btree_gc.c @@ -419,6 +419,13 @@ void bch_gc(struct cache_set *c) up_write(&c->gc_lock); trace_bcache_gc_end(c); bch_time_stats_update(&c->btree_gc_time, start_time); + + /* + * Wake up allocator in case it was waiting for buckets + * because of not being able to inc gens + */ + for_each_cache(ca, c, i) + bch_wake_allocator(ca); } /* Btree coalescing */ @@ -716,9 +723,9 @@ static int bch_coalesce_btree(struct cache_set *c, enum btree_id btree_id) /** * bch_coalesce - coalesce adjacent nodes with low occupancy */ -static void bch_coalesce(struct cache_set *c) +void bch_coalesce(struct cache_set *c) { - u64 start_time = local_clock(); + u64 start_time; enum btree_id id; if (btree_gc_coalesce_disabled(c)) @@ -727,7 +734,9 @@ static void bch_coalesce(struct cache_set *c) if (test_bit(CACHE_SET_GC_FAILURE, &c->flags)) return; + down_read(&c->gc_lock); trace_bcache_gc_coalesce_start(c); + start_time = local_clock(); for (id = 0; id < BTREE_ID_NR; id++) { int ret = c->btree_roots[id].b @@ -743,8 +752,8 @@ static void bch_coalesce(struct cache_set *c) } bch_time_stats_update(&c->btree_coalesce_time, start_time); - trace_bcache_gc_coalesce_end(c); + up_read(&c->gc_lock); } static int bch_gc_thread(void *arg) @@ -753,8 +762,6 @@ static int bch_gc_thread(void *arg) struct io_clock *clock = &c->io_clock[WRITE]; unsigned long last = atomic_long_read(&clock->now); unsigned last_kick = atomic_read(&c->kick_gc); - struct cache *ca; - unsigned i; set_freezable(); @@ -781,22 +788,8 @@ static int bch_gc_thread(void *arg) last = atomic_long_read(&clock->now); last_kick = atomic_read(&c->kick_gc); - /* - * avoid racing with sysfs trigger_gc - gc gets confused if it - * runs concurrently with coalescing - */ - mutex_lock(&c->trigger_gc_lock); bch_gc(c); - - /* - * Wake up allocator in case it was waiting for buckets - * because of not being able to inc gens - */ - for_each_cache(ca, c, i) - bch_wake_allocator(ca); - bch_coalesce(c); - mutex_unlock(&c->trigger_gc_lock); debug_check_no_locks_held(); } diff --git a/drivers/md/bcache/btree_gc.h b/drivers/md/bcache/btree_gc.h index 99c6ccdef2b1..91d31c05c4b9 100644 --- a/drivers/md/bcache/btree_gc.h +++ b/drivers/md/bcache/btree_gc.h @@ -5,6 +5,7 @@ enum bkey_type; +void bch_coalesce(struct cache_set *); void bch_gc(struct cache_set *); void bch_gc_thread_stop(struct cache_set *); int bch_gc_thread_start(struct cache_set *); diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c index ee383193726d..69b44f81495c 100644 --- a/drivers/md/bcache/super.c +++ b/drivers/md/bcache/super.c @@ -1070,7 +1070,6 @@ static struct cache_set *bch_cache_set_alloc(struct cache_sb *sb, mutex_init(&c->mi_lock); init_rwsem(&c->gc_lock); - mutex_init(&c->trigger_gc_lock); #define BCH_TIME_STAT(name, frequency_units, duration_units) \ spin_lock_init(&c->name##_time.lock); diff --git a/drivers/md/bcache/sysfs.c b/drivers/md/bcache/sysfs.c index 8e7e97979fed..9f73b6bc329f 100644 --- a/drivers/md/bcache/sysfs.c +++ b/drivers/md/bcache/sysfs.c @@ -54,6 +54,7 @@ write_attribute(detach); write_attribute(unregister); write_attribute(stop); write_attribute(clear_stats); +write_attribute(trigger_btree_coalesce); write_attribute(trigger_gc); write_attribute(prune_cache); write_attribute(blockdev_volume_create); @@ -832,13 +833,13 @@ STORE(__bch_cache_set) return r; } + if (attr == &sysfs_trigger_btree_coalesce) + bch_coalesce(c); + /* Debugging: */ - if (attr == &sysfs_trigger_gc) { - mutex_lock(&c->trigger_gc_lock); + if (attr == &sysfs_trigger_gc) bch_gc(c); - mutex_unlock(&c->trigger_gc_lock); - } if (attr == &sysfs_prune_cache) { struct shrink_control sc; @@ -942,6 +943,7 @@ static struct attribute *bch_cache_set_internal_files[] = { &sysfs_writeback_keys_done, &sysfs_writeback_keys_failed, + &sysfs_trigger_btree_coalesce, &sysfs_trigger_gc, &sysfs_prune_cache, &sysfs_foreground_write_ratelimit_enabled, |