diff options
author | Coly Li <colyli@suse.de> | 2018-12-13 15:53:52 +0100 |
---|---|---|
committer | Jens Axboe <axboe@kernel.dk> | 2018-12-13 16:15:54 +0100 |
commit | cb07ad63682ffcce10e9beaed7828a26780e3df9 (patch) | |
tree | 57601385261e5eb438c86454ebc7e88e373baec1 /drivers/md/bcache/btree.h | |
parent | bcache: cannot set writeback_running via sysfs if no writeback kthread created (diff) | |
download | linux-cb07ad63682ffcce10e9beaed7828a26780e3df9.tar.xz linux-cb07ad63682ffcce10e9beaed7828a26780e3df9.zip |
bcache: introduce force_wake_up_gc()
Garbage collection thread starts to work when c->sectors_to_gc is
negative value, otherwise nothing will happen even the gc thread is
woken up by wake_up_gc().
force_wake_up_gc() sets c->sectors_to_gc to -1 before calling
wake_up_gc(), then gc thread may have chance to run if no one else sets
c->sectors_to_gc to a positive value before gc_should_run().
This routine can be called where the gc thread is woken up and required
to run in force.
Signed-off-by: Coly Li <colyli@suse.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'drivers/md/bcache/btree.h')
-rw-r--r-- | drivers/md/bcache/btree.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/drivers/md/bcache/btree.h b/drivers/md/bcache/btree.h index a68d6c55783b..d1c72ef64edf 100644 --- a/drivers/md/bcache/btree.h +++ b/drivers/md/bcache/btree.h @@ -266,6 +266,24 @@ static inline void wake_up_gc(struct cache_set *c) wake_up(&c->gc_wait); } +static inline void force_wake_up_gc(struct cache_set *c) +{ + /* + * Garbage collection thread only works when sectors_to_gc < 0, + * calling wake_up_gc() won't start gc thread if sectors_to_gc is + * not a nagetive value. + * Therefore sectors_to_gc is set to -1 here, before waking up + * gc thread by calling wake_up_gc(). Then gc_should_run() will + * give a chance to permit gc thread to run. "Give a chance" means + * before going into gc_should_run(), there is still possibility + * that c->sectors_to_gc being set to other positive value. So + * this routine won't 100% make sure gc thread will be woken up + * to run. + */ + atomic_set(&c->sectors_to_gc, -1); + wake_up_gc(c); +} + #define MAP_DONE 0 #define MAP_CONTINUE 1 |