Skip to content

Commit 7b6759b

Browse files
author
Kent Overstreet
committed
bcachefs: Fix livelock in journal_entry_open()
When the journal is low on space, we might do discards from journal_res_get() -> journal_entry_open(). Make sure we set j->can_discard correctly, so that if we're low on space but not because discards aren't keeping up we don't livelock. Fixes: 8e4d280 ("bcachefs: Don't aggressively discard the journal") Signed-off-by: Kent Overstreet <[email protected]>
1 parent b1c71cb commit 7b6759b

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

fs/bcachefs/journal_reclaim.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#include <linux/kthread.h>
1818
#include <linux/sched/mm.h>
1919

20+
static bool __should_discard_bucket(struct journal *, struct journal_device *);
21+
2022
/* Free space calculations: */
2123

2224
static unsigned journal_space_from(struct journal_device *ja,
@@ -203,8 +205,7 @@ void bch2_journal_space_available(struct journal *j)
203205
ja->bucket_seq[ja->dirty_idx_ondisk] < j->last_seq_ondisk)
204206
ja->dirty_idx_ondisk = (ja->dirty_idx_ondisk + 1) % ja->nr;
205207

206-
if (ja->discard_idx != ja->dirty_idx_ondisk)
207-
can_discard = true;
208+
can_discard |= __should_discard_bucket(j, ja);
208209

209210
max_entry_size = min_t(unsigned, max_entry_size, ca->mi.bucket_size);
210211
nr_online++;
@@ -264,13 +265,19 @@ void bch2_journal_space_available(struct journal *j)
264265

265266
/* Discards - last part of journal reclaim: */
266267

267-
static bool should_discard_bucket(struct journal *j, struct journal_device *ja)
268+
static bool __should_discard_bucket(struct journal *j, struct journal_device *ja)
268269
{
269-
spin_lock(&j->lock);
270270
unsigned min_free = max(4, ja->nr / 8);
271271

272-
bool ret = bch2_journal_dev_buckets_available(j, ja, journal_space_discarded) < min_free &&
272+
return bch2_journal_dev_buckets_available(j, ja, journal_space_discarded) <
273+
min_free &&
273274
ja->discard_idx != ja->dirty_idx_ondisk;
275+
}
276+
277+
static bool should_discard_bucket(struct journal *j, struct journal_device *ja)
278+
{
279+
spin_lock(&j->lock);
280+
bool ret = __should_discard_bucket(j, ja);
274281
spin_unlock(&j->lock);
275282

276283
return ret;

0 commit comments

Comments
 (0)