Skip to content

Commit f54b2a8

Browse files
author
Kent Overstreet
committed
bcachefs: Fix misaligned bucket check in journal space calculations
Fix an assertion pop in the tiering_misaligned test: rounding down to bucket size at the end of the journal space calculations leaves cur_entry_sectors == 0, which is incorrect with !cur_entry_err. Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
1 parent 813825d commit f54b2a8

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

fs/bcachefs/journal_reclaim.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,20 @@ static struct journal_space
8383
journal_dev_space_available(struct journal *j, struct bch_dev *ca,
8484
enum journal_space_from from)
8585
{
86+
struct bch_fs *c = container_of(j, struct bch_fs, journal);
8687
struct journal_device *ja = &ca->journal;
8788
unsigned sectors, buckets, unwritten;
89+
unsigned bucket_size_aligned = round_down(ca->mi.bucket_size, block_sectors(c));
8890
u64 seq;
8991

9092
if (from == journal_space_total)
9193
return (struct journal_space) {
92-
.next_entry = ca->mi.bucket_size,
93-
.total = ca->mi.bucket_size * ja->nr,
94+
.next_entry = bucket_size_aligned,
95+
.total = bucket_size_aligned * ja->nr,
9496
};
9597

9698
buckets = bch2_journal_dev_buckets_available(j, ja, from);
97-
sectors = ja->sectors_free;
99+
sectors = round_down(ja->sectors_free, block_sectors(c));
98100

99101
/*
100102
* We that we don't allocate the space for a journal entry
@@ -109,7 +111,7 @@ journal_dev_space_available(struct journal *j, struct bch_dev *ca,
109111
continue;
110112

111113
/* entry won't fit on this device, skip: */
112-
if (unwritten > ca->mi.bucket_size)
114+
if (unwritten > bucket_size_aligned)
113115
continue;
114116

115117
if (unwritten >= sectors) {
@@ -119,20 +121,20 @@ journal_dev_space_available(struct journal *j, struct bch_dev *ca,
119121
}
120122

121123
buckets--;
122-
sectors = ca->mi.bucket_size;
124+
sectors = bucket_size_aligned;
123125
}
124126

125127
sectors -= unwritten;
126128
}
127129

128130
if (sectors < ca->mi.bucket_size && buckets) {
129131
buckets--;
130-
sectors = ca->mi.bucket_size;
132+
sectors = bucket_size_aligned;
131133
}
132134

133135
return (struct journal_space) {
134136
.next_entry = sectors,
135-
.total = sectors + buckets * ca->mi.bucket_size,
137+
.total = sectors + buckets * bucket_size_aligned,
136138
};
137139
}
138140

@@ -256,8 +258,7 @@ void bch2_journal_space_available(struct journal *j)
256258
bch2_journal_set_watermark(j);
257259
out:
258260
j->cur_entry_sectors = !ret
259-
? round_down(j->space[journal_space_discarded].next_entry,
260-
block_sectors(c))
261+
? j->space[journal_space_discarded].next_entry
261262
: 0;
262263
j->cur_entry_error = ret;
263264

0 commit comments

Comments
 (0)