From e77e4efce31f3739fa85a84c5197b7cd18747a64 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Tue, 7 Apr 2020 13:49:14 -0400 Subject: [PATCH] bcachefs: Account for ioclock slop when throttling rebalance thread This should fix an issue where the rebalance thread was spinning Signed-off-by: Kent Overstreet Signed-off-by: Kent Overstreet --- fs/bcachefs/rebalance.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/fs/bcachefs/rebalance.c b/fs/bcachefs/rebalance.c index a0a75cfa41cbe..eb3f7d02c791c 100644 --- a/fs/bcachefs/rebalance.c +++ b/fs/bcachefs/rebalance.c @@ -204,17 +204,21 @@ static int bch2_rebalance_thread(void *arg) prev_run_time; if (w.dev_most_full_percent < 20 && throttle > 0) { - r->state = REBALANCE_THROTTLED; r->throttled_until_iotime = io_start + div_u64(w.dev_most_full_capacity * (20 - w.dev_most_full_percent), 50); - r->throttled_until_cputime = start + throttle; - bch2_kthread_io_clock_wait(clock, - r->throttled_until_iotime, - throttle); - continue; + if (atomic_long_read(&clock->now) + clock->max_slop < + r->throttled_until_iotime) { + r->throttled_until_cputime = start + throttle; + r->state = REBALANCE_THROTTLED; + + bch2_kthread_io_clock_wait(clock, + r->throttled_until_iotime, + throttle); + continue; + } } /* minimum 1 mb/sec: */ -- 2.30.2