Skip to content

Commit 2d679fc

Browse files
author
Kent Overstreet
committed
bcache: Stripe size isn't necessarily a power of two
Originally I got this right... except that the divides didn't use do_div(), which broke 32 bit kernels. When I went to fix that, I forgot that the raid stripe size usually isn't a power of two... doh Signed-off-by: Kent Overstreet <kmo@daterainc.com>
1 parent 77c320e commit 2d679fc

5 files changed

Lines changed: 27 additions & 25 deletions

File tree

‎drivers/md/bcache/bcache.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ struct bcache_device {
437437
int flush_done;
438438

439439
uint64_t nr_stripes;
440-
unsigned stripe_size_bits;
440+
unsigned stripe_size;
441441
atomic_t *stripe_sectors_dirty;
442442

443443
unsigned long sectors_dirty_last;

‎drivers/md/bcache/super.c‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -761,11 +761,10 @@ static int bcache_device_init(struct bcache_device *d, unsigned block_size,
761761
struct request_queue *q;
762762
size_t n;
763763

764-
if (!d->stripe_size_bits)
765-
d->stripe_size_bits = 31;
764+
if (!d->stripe_size)
765+
d->stripe_size = 1 << 31;
766766

767-
d->nr_stripes = round_up(sectors, 1 << d->stripe_size_bits) >>
768-
d->stripe_size_bits;
767+
d->nr_stripes = DIV_ROUND_UP_ULL(sectors, d->stripe_size);
769768

770769
if (!d->nr_stripes || d->nr_stripes > SIZE_MAX / sizeof(atomic_t))
771770
return -ENOMEM;

‎drivers/md/bcache/sysfs.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ SHOW(__bch_cached_dev)
157157
sysfs_hprint(dirty_data,
158158
bcache_dev_sectors_dirty(&dc->disk) << 9);
159159

160-
sysfs_hprint(stripe_size, (1 << dc->disk.stripe_size_bits) << 9);
160+
sysfs_hprint(stripe_size, dc->disk.stripe_size << 9);
161161
var_printf(partial_stripes_expensive, "%u");
162162

163163
var_printf(sequential_merge, "%i");

‎drivers/md/bcache/writeback.c‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -114,25 +114,25 @@ static bool dirty_pred(struct keybuf *buf, struct bkey *k)
114114

115115
static bool dirty_full_stripe_pred(struct keybuf *buf, struct bkey *k)
116116
{
117-
uint64_t stripe;
117+
uint64_t stripe = KEY_START(k);
118118
unsigned nr_sectors = KEY_SIZE(k);
119119
struct cached_dev *dc = container_of(buf, struct cached_dev,
120120
writeback_keys);
121-
unsigned stripe_size = 1 << dc->disk.stripe_size_bits;
122121

123122
if (!KEY_DIRTY(k))
124123
return false;
125124

126-
stripe = KEY_START(k) >> dc->disk.stripe_size_bits;
127-
while (1) {
128-
if (atomic_read(dc->disk.stripe_sectors_dirty + stripe) !=
129-
stripe_size)
130-
return false;
125+
do_div(stripe, dc->disk.stripe_size);
131126

132-
if (nr_sectors <= stripe_size)
127+
while (1) {
128+
if (atomic_read(dc->disk.stripe_sectors_dirty + stripe) ==
129+
dc->disk.stripe_size)
133130
return true;
134131

135-
nr_sectors -= stripe_size;
132+
if (nr_sectors <= dc->disk.stripe_size)
133+
return false;
134+
135+
nr_sectors -= dc->disk.stripe_size;
136136
stripe++;
137137
}
138138
}
@@ -186,11 +186,12 @@ static void refill_dirty(struct closure *cl)
186186

187187
for (i = 0; i < dc->disk.nr_stripes; i++)
188188
if (atomic_read(dc->disk.stripe_sectors_dirty + i) ==
189-
1 << dc->disk.stripe_size_bits)
189+
dc->disk.stripe_size)
190190
goto full_stripes;
191191

192192
goto normal_refill;
193193
full_stripes:
194+
searched_from_start = false; /* not searching entire btree */
194195
bch_refill_keybuf(dc->disk.c, buf, &end,
195196
dirty_full_stripe_pred);
196197
} else {
@@ -252,19 +253,19 @@ void bcache_dev_sectors_dirty_add(struct cache_set *c, unsigned inode,
252253
uint64_t offset, int nr_sectors)
253254
{
254255
struct bcache_device *d = c->devices[inode];
255-
unsigned stripe_size, stripe_offset;
256-
uint64_t stripe;
256+
unsigned stripe_offset;
257+
uint64_t stripe = offset;
257258

258259
if (!d)
259260
return;
260261

261-
stripe_size = 1 << d->stripe_size_bits;
262-
stripe = offset >> d->stripe_size_bits;
263-
stripe_offset = offset & (stripe_size - 1);
262+
do_div(stripe, d->stripe_size);
263+
264+
stripe_offset = offset & (d->stripe_size - 1);
264265

265266
while (nr_sectors) {
266267
int s = min_t(unsigned, abs(nr_sectors),
267-
stripe_size - stripe_offset);
268+
d->stripe_size - stripe_offset);
268269

269270
if (nr_sectors < 0)
270271
s = -s;

‎drivers/md/bcache/writeback.h‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,18 @@ static inline bool bcache_dev_stripe_dirty(struct bcache_device *d,
1818
uint64_t offset,
1919
unsigned nr_sectors)
2020
{
21-
uint64_t stripe = offset >> d->stripe_size_bits;
21+
uint64_t stripe = offset;
22+
23+
do_div(stripe, d->stripe_size);
2224

2325
while (1) {
2426
if (atomic_read(d->stripe_sectors_dirty + stripe))
2527
return true;
2628

27-
if (nr_sectors <= 1 << d->stripe_size_bits)
29+
if (nr_sectors <= d->stripe_size)
2830
return false;
2931

30-
nr_sectors -= 1 << d->stripe_size_bits;
32+
nr_sectors -= d->stripe_size;
3133
stripe++;
3234
}
3335
}

0 commit comments

Comments
 (0)