Skip to content

Commit 6f26f0b

Browse files
koverstreetgregkh
authored andcommitted
bcache: Make gc wakeup sane, remove set_task_state()
commit be628be09563f8f6e81929efbd7cf3f45c344416 upstream. Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent aee7d04 commit 6f26f0b

5 files changed

Lines changed: 26 additions & 27 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 & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1762,45 +1762,45 @@ static void bch_btree_gc(struct cache_set *c)
17621762
bch_moving_gc(c);
17631763
}
17641764

1765-
static int bch_gc_thread(void *arg)
1765+
static bool gc_should_run(struct cache_set *c)
17661766
{
1767-
struct cache_set *c = arg;
17681767
struct cache *ca;
17691768
unsigned i;
17701769

1771-
while (1) {
1772-
again:
1773-
bch_btree_gc(c);
1770+
for_each_cache(ca, c, i)
1771+
if (ca->invalidate_needs_gc)
1772+
return true;
17741773

1775-
set_current_state(TASK_INTERRUPTIBLE);
1776-
if (kthread_should_stop())
1777-
break;
1774+
if (atomic_read(&c->sectors_to_gc) < 0)
1775+
return true;
17781776

1779-
mutex_lock(&c->bucket_lock);
1777+
return false;
1778+
}
17801779

1781-
for_each_cache(ca, c, i)
1782-
if (ca->invalidate_needs_gc) {
1783-
mutex_unlock(&c->bucket_lock);
1784-
set_current_state(TASK_RUNNING);
1785-
goto again;
1786-
}
1780+
static int bch_gc_thread(void *arg)
1781+
{
1782+
struct cache_set *c = arg;
17871783

1788-
mutex_unlock(&c->bucket_lock);
1784+
while (1) {
1785+
wait_event_interruptible(c->gc_wait,
1786+
kthread_should_stop() || gc_should_run(c));
17891787

1790-
try_to_freeze();
1791-
schedule();
1788+
if (kthread_should_stop())
1789+
break;
1790+
1791+
set_gc_sectors(c);
1792+
bch_btree_gc(c);
17921793
}
17931794

17941795
return 0;
17951796
}
17961797

17971798
int bch_gc_thread_start(struct cache_set *c)
17981799
{
1799-
c->gc_thread = kthread_create(bch_gc_thread, c, "bcache_gc");
1800+
c->gc_thread = kthread_run(bch_gc_thread, c, "bcache_gc");
18001801
if (IS_ERR(c->gc_thread))
18011802
return PTR_ERR(c->gc_thread);
18021803

1803-
set_task_state(c->gc_thread, TASK_INTERRUPTIBLE);
18041804
return 0;
18051805
}
18061806

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);
@@ -1547,6 +1548,7 @@ static void run_cache_set(struct cache_set *c)
15471548

15481549
for_each_cache(ca, c, i)
15491550
c->nbuckets += ca->sb.nbuckets;
1551+
set_gc_sectors(c);
15501552

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

0 commit comments

Comments
 (0)