Skip to content

Commit 415e510

Browse files
author
Kent Overstreet
committed
bcachefs: Extra kthread_should_stop() calls for copygc
This fixes a bug where going read-only was taking longer than it should have due to copygc forgetting to check kthread_should_stop() Additionally: fix a missing is_kthread check in bch2_move_ratelimit(). Signed-off-by: Kent Overstreet <[email protected]>
1 parent 463086d commit 415e510

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

fs/bcachefs/move.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,24 +441,26 @@ int bch2_move_get_io_opts_one(struct btree_trans *trans,
441441
int bch2_move_ratelimit(struct moving_context *ctxt)
442442
{
443443
struct bch_fs *c = ctxt->trans->c;
444+
bool is_kthread = current->flags & PF_KTHREAD;
444445
u64 delay;
445446

446447
if (ctxt->wait_on_copygc && c->copygc_running) {
447448
bch2_moving_ctxt_flush_all(ctxt);
448449
wait_event_killable(c->copygc_running_wq,
449450
!c->copygc_running ||
450-
kthread_should_stop());
451+
(is_kthread && kthread_should_stop()));
451452
}
452453

453454
do {
454455
delay = ctxt->rate ? bch2_ratelimit_delay(ctxt->rate) : 0;
455456

456-
if ((current->flags & PF_KTHREAD) && kthread_should_stop())
457+
if (is_kthread && kthread_should_stop())
457458
return 1;
458459

459460
if (delay)
460461
move_ctxt_wait_event_timeout(ctxt,
461-
freezing(current) || kthread_should_stop(),
462+
freezing(current) ||
463+
(is_kthread && kthread_should_stop()),
462464
delay);
463465

464466
if (unlikely(freezing(current))) {
@@ -633,6 +635,7 @@ int __bch2_evacuate_bucket(struct moving_context *ctxt,
633635
{
634636
struct btree_trans *trans = ctxt->trans;
635637
struct bch_fs *c = trans->c;
638+
bool is_kthread = current->flags & PF_KTHREAD;
636639
struct bch_io_opts io_opts = bch2_opts_to_inode_opts(c->opts);
637640
struct btree_iter iter;
638641
struct bkey_buf sk;
@@ -678,6 +681,9 @@ int __bch2_evacuate_bucket(struct moving_context *ctxt,
678681
}
679682

680683
while (!(ret = bch2_move_ratelimit(ctxt))) {
684+
if (is_kthread && kthread_should_stop())
685+
break;
686+
681687
bch2_trans_begin(trans);
682688

683689
ret = bch2_get_next_backpointer(trans, bucket, gen,

fs/bcachefs/movinggc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ static int bch2_copygc(struct moving_context *ctxt,
207207
goto err;
208208

209209
darray_for_each(buckets, i) {
210-
if (unlikely(freezing(current)))
210+
if (kthread_should_stop() || freezing(current))
211211
break;
212212

213213
f = move_bucket_in_flight_add(buckets_in_flight, *i);

0 commit comments

Comments
 (0)