Skip to content

Commit 261af2f

Browse files
author
Kent Overstreet
committed
bcachefs: Make sure bch2_move_ratelimit() also waits for move_ops
This adds move_ctxt_wait_event_timeout(), which can sleep for a timeout while also issueing pending moves as reads complete. Co-developed-by: Daniel Hill <daniel@gluo.nz> Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 50e029c commit 261af2f

2 files changed

Lines changed: 23 additions & 13 deletions

File tree

fs/bcachefs/move.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -500,22 +500,13 @@ int bch2_move_ratelimit(struct moving_context *ctxt)
500500
do {
501501
delay = ctxt->rate ? bch2_ratelimit_delay(ctxt->rate) : 0;
502502

503-
504-
if (delay) {
505-
if (delay > HZ / 10)
506-
bch2_trans_unlock_long(ctxt->trans);
507-
else
508-
bch2_trans_unlock(ctxt->trans);
509-
set_current_state(TASK_INTERRUPTIBLE);
510-
}
511-
512-
if ((current->flags & PF_KTHREAD) && kthread_should_stop()) {
513-
__set_current_state(TASK_RUNNING);
503+
if ((current->flags & PF_KTHREAD) && kthread_should_stop())
514504
return 1;
515-
}
516505

517506
if (delay)
518-
schedule_timeout(delay);
507+
move_ctxt_wait_event_timeout(ctxt,
508+
freezing(current) || kthread_should_stop(),
509+
delay);
519510

520511
if (unlikely(freezing(current))) {
521512
bch2_moving_ctxt_flush_all(ctxt);

fs/bcachefs/move.h

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,25 @@ struct moving_context {
3838
wait_queue_head_t wait;
3939
};
4040

41+
#define move_ctxt_wait_event_timeout(_ctxt, _cond, _timeout) \
42+
({ \
43+
int _ret = 0; \
44+
while (true) { \
45+
bool cond_finished = false; \
46+
bch2_moving_ctxt_do_pending_writes(_ctxt); \
47+
\
48+
if (_cond) \
49+
break; \
50+
bch2_trans_unlock_long((_ctxt)->trans); \
51+
_ret = __wait_event_timeout((_ctxt)->wait, \
52+
bch2_moving_ctxt_next_pending_write(_ctxt) || \
53+
(cond_finished = (_cond)), _timeout); \
54+
if (_ret || ( cond_finished)) \
55+
break; \
56+
} \
57+
_ret; \
58+
})
59+
4160
#define move_ctxt_wait_event(_ctxt, _cond) \
4261
do { \
4362
bool cond_finished = false; \

0 commit comments

Comments
 (0)