bcachefs: Account for ioclock slop when throttling rebalance thread
authorKent Overstreet <kent.overstreet@gmail.com>
Tue, 7 Apr 2020 17:49:14 +0000 (13:49 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Sun, 22 Oct 2023 21:08:38 +0000 (17:08 -0400)
This should fix an issue where the rebalance thread was spinning

Signed-off-by: Kent Overstreet <kent.overstreet@gmail.com>
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/rebalance.c

index a0a75cfa41cbeb547a80d97f101bd45c0a20d7e6..eb3f7d02c791cdd55ab1dd7c253b9dad440a99c0 100644 (file)
@@ -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: */