Skip to content

Commit be628be

Browse files
koverstreetaxboe
authored andcommitted
bcache: Make gc wakeup sane, remove set_task_state()
Signed-off-by: Kent Overstreet <[email protected]>
1 parent 59331c2 commit be628be

5 files changed

Lines changed: 26 additions & 26 deletions

File tree

drivers/md/bcache/bcache.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ struct cache {
425425
* until a gc finishes - otherwise we could pointlessly burn a ton of
426426
* cpu
427427
*/
428-
unsigned invalidate_needs_gc:1;
428+
unsigned invalidate_needs_gc;
429429

430430
bool discard; /* Get rid of? */
431431

@@ -593,8 +593,8 @@ struct cache_set {
593593

594594
/* Counts how many sectors bio_insert has added to the cache */
595595
atomic_t sectors_to_gc;
596+
wait_queue_head_t gc_wait;
596597

597-
wait_queue_head_t moving_gc_wait;
598598
struct keybuf moving_gc_keys;
599599
/* Number of moving GC bios in flight */
600600
struct semaphore moving_in_flight;

drivers/md/bcache/btree.c

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1757,44 +1757,45 @@ static void bch_btree_gc(struct cache_set *c)
17571757
bch_moving_gc(c);
17581758
}
17591759

1760-
static int bch_gc_thread(void *arg)
1760+
static bool gc_should_run(struct cache_set *c)
17611761
{
1762-
struct cache_set *c = arg;
17631762
struct cache *ca;
17641763
unsigned i;
17651764

1766-
while (1) {
1767-
again:
1768-
bch_btree_gc(c);
1765+
for_each_cache(ca, c, i)
1766+
if (ca->invalidate_needs_gc)
1767+
return true;
17691768

1770-
set_current_state(TASK_INTERRUPTIBLE);
1771-
if (kthread_should_stop())
1772-
break;
1769+
if (atomic_read(&c->sectors_to_gc) < 0)
1770+
return true;
17731771

1774-
mutex_lock(&c->bucket_lock);
1772+
return false;
1773+
}
17751774

1776-
for_each_cache(ca, c, i)
1777-
if (ca->invalidate_needs_gc) {
1778-
mutex_unlock(&c->bucket_lock);
1779-
set_current_state(TASK_RUNNING);
1780-
goto again;
1781-
}
1775+
static int bch_gc_thread(void *arg)
1776+
{
1777+
struct cache_set *c = arg;
17821778

1783-
mutex_unlock(&c->bucket_lock);
1779+
while (1) {
1780+
wait_event_interruptible(c->gc_wait,
1781+
kthread_should_stop() || gc_should_run(c));
17841782

1785-
schedule();
1783+
if (kthread_should_stop())
1784+
break;
1785+
1786+
set_gc_sectors(c);
1787+
bch_btree_gc(c);
17861788
}
17871789

17881790
return 0;
17891791
}
17901792

17911793
int bch_gc_thread_start(struct cache_set *c)
17921794
{
1793-
c->gc_thread = kthread_create(bch_gc_thread, c, "bcache_gc");
1795+
c->gc_thread = kthread_run(bch_gc_thread, c, "bcache_gc");
17941796
if (IS_ERR(c->gc_thread))
17951797
return PTR_ERR(c->gc_thread);
17961798

1797-
set_task_state(c->gc_thread, TASK_INTERRUPTIBLE);
17981799
return 0;
17991800
}
18001801

drivers/md/bcache/btree.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,7 @@ void bch_initial_mark_key(struct cache_set *, int, struct bkey *);
260260

261261
static inline void wake_up_gc(struct cache_set *c)
262262
{
263-
if (c->gc_thread)
264-
wake_up_process(c->gc_thread);
263+
wake_up(&c->gc_wait);
265264
}
266265

267266
#define MAP_DONE 0

drivers/md/bcache/request.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,8 @@ static void bch_data_insert_start(struct closure *cl)
196196
struct data_insert_op *op = container_of(cl, struct data_insert_op, cl);
197197
struct bio *bio = op->bio, *n;
198198

199-
if (atomic_sub_return(bio_sectors(bio), &op->c->sectors_to_gc) < 0) {
200-
set_gc_sectors(op->c);
199+
if (atomic_sub_return(bio_sectors(bio), &op->c->sectors_to_gc) < 0)
201200
wake_up_gc(op->c);
202-
}
203201

204202
if (op->bypass)
205203
return bch_data_invalidate(cl);

drivers/md/bcache/super.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,6 +1489,7 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb)
14891489
mutex_init(&c->bucket_lock);
14901490
init_waitqueue_head(&c->btree_cache_wait);
14911491
init_waitqueue_head(&c->bucket_wait);
1492+
init_waitqueue_head(&c->gc_wait);
14921493
sema_init(&c->uuid_write_mutex, 1);
14931494

14941495
spin_lock_init(&c->btree_gc_time.lock);
@@ -1548,6 +1549,7 @@ static void run_cache_set(struct cache_set *c)
15481549

15491550
for_each_cache(ca, c, i)
15501551
c->nbuckets += ca->sb.nbuckets;
1552+
set_gc_sectors(c);
15511553

15521554
if (CACHE_SYNC(&c->sb)) {
15531555
LIST_HEAD(journal);

0 commit comments

Comments
 (0)