bcachefs: Fix racy use of jiffies

Calculate the timeout, then check if it's positive before calling
schedule_timeout().

Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
This commit is contained in:
Kent Overstreet
2024-10-09 16:53:59 -04:00
parent 4b8d382b2c
commit 135c0c8524

View File

@@ -758,10 +758,12 @@ static int bch2_journal_reclaim_thread(void *arg)
journal_empty = fifo_empty(&j->pin);
spin_unlock(&j->lock);
long timeout = j->next_reclaim - jiffies;
if (journal_empty)
schedule();
else if (time_after(j->next_reclaim, jiffies))
schedule_timeout(j->next_reclaim - jiffies);
else if (timeout > 0)
schedule_timeout(timeout);
else
break;
}