Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Coly Li and committed by
Jens Axboe
cb07ad63 f383ae30

+20 -15
+18
drivers/md/bcache/btree.h
··· 266 266 wake_up(&c->gc_wait); 267 267 } 268 268 269 + static inline void force_wake_up_gc(struct cache_set *c) 270 + { 271 + /* 272 + * Garbage collection thread only works when sectors_to_gc < 0, 273 + * calling wake_up_gc() won't start gc thread if sectors_to_gc is 274 + * not a nagetive value. 275 + * Therefore sectors_to_gc is set to -1 here, before waking up 276 + * gc thread by calling wake_up_gc(). Then gc_should_run() will 277 + * give a chance to permit gc thread to run. "Give a chance" means 278 + * before going into gc_should_run(), there is still possibility 279 + * that c->sectors_to_gc being set to other positive value. So 280 + * this routine won't 100% make sure gc thread will be woken up 281 + * to run. 282 + */ 283 + atomic_set(&c->sectors_to_gc, -1); 284 + wake_up_gc(c); 285 + } 286 + 269 287 #define MAP_DONE 0 270 288 #define MAP_CONTINUE 1 271 289
+2 -15
drivers/md/bcache/sysfs.c
··· 742 742 bch_cache_accounting_clear(&c->accounting); 743 743 } 744 744 745 - if (attr == &sysfs_trigger_gc) { 746 - /* 747 - * Garbage collection thread only works when sectors_to_gc < 0, 748 - * when users write to sysfs entry trigger_gc, most of time 749 - * they want to forcibly triger gargage collection. Here -1 is 750 - * set to c->sectors_to_gc, to make gc_should_run() give a 751 - * chance to permit gc thread to run. "give a chance" means 752 - * before going into gc_should_run(), there is still chance 753 - * that c->sectors_to_gc being set to other positive value. So 754 - * writing sysfs entry trigger_gc won't always make sure gc 755 - * thread takes effect. 756 - */ 757 - atomic_set(&c->sectors_to_gc, -1); 758 - wake_up_gc(c); 759 - } 745 + if (attr == &sysfs_trigger_gc) 746 + force_wake_up_gc(c); 760 747 761 748 if (attr == &sysfs_prune_cache) { 762 749 struct shrink_control sc;