Skip to content

Commit 21e478d

Browse files
Coly Liaxboe
authored andcommitted
bcache: handle c->uuids properly for bucket size > 8MB
Bcache allocates a whole bucket to store c->uuids on cache device, and allocates continuous pages to store it in-memory. When the bucket size exceeds maximum allocable continuous pages, bch_cache_set_alloc() will fail and cache device registration will fail. This patch allocates c->uuids by alloc_meta_bucket_pages(), and uses ilog2(meta_bucket_pages(c)) to indicate order of c->uuids pages when free it. When writing c->uuids to cache device, its size is decided by meta_bucket_pages(c) * PAGE_SECTORS. Now c->uuids is properly handled for bucket size > 8MB. Signed-off-by: Coly Li <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent de1fafa commit 21e478d

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/md/bcache/super.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -466,14 +466,16 @@ static int __uuid_write(struct cache_set *c)
466466
BKEY_PADDED(key) k;
467467
struct closure cl;
468468
struct cache *ca;
469+
unsigned int size;
469470

470471
closure_init_stack(&cl);
471472
lockdep_assert_held(&bch_register_lock);
472473

473474
if (bch_bucket_alloc_set(c, RESERVE_BTREE, &k.key, 1, true))
474475
return 1;
475476

476-
SET_KEY_SIZE(&k.key, c->sb.bucket_size);
477+
size = meta_bucket_pages(&c->sb) * PAGE_SECTORS;
478+
SET_KEY_SIZE(&k.key, size);
477479
uuid_io(c, REQ_OP_WRITE, 0, &k.key, &cl);
478480
closure_sync(&cl);
479481

@@ -1664,7 +1666,7 @@ static void cache_set_free(struct closure *cl)
16641666
}
16651667

16661668
bch_bset_sort_state_free(&c->sort);
1667-
free_pages((unsigned long) c->uuids, ilog2(bucket_pages(c)));
1669+
free_pages((unsigned long) c->uuids, ilog2(meta_bucket_pages(&c->sb)));
16681670

16691671
if (c->moving_gc_wq)
16701672
destroy_workqueue(c->moving_gc_wq);
@@ -1870,7 +1872,7 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb)
18701872

18711873
c->bucket_bits = ilog2(sb->bucket_size);
18721874
c->block_bits = ilog2(sb->block_size);
1873-
c->nr_uuids = bucket_bytes(c) / sizeof(struct uuid_entry);
1875+
c->nr_uuids = meta_bucket_bytes(&c->sb) / sizeof(struct uuid_entry);
18741876
c->devices_max_used = 0;
18751877
atomic_set(&c->attached_dev_nr, 0);
18761878
c->btree_pages = bucket_pages(c);
@@ -1921,7 +1923,7 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb)
19211923
BIOSET_NEED_BVECS|BIOSET_NEED_RESCUER))
19221924
goto err;
19231925

1924-
c->uuids = alloc_bucket_pages(GFP_KERNEL, c);
1926+
c->uuids = alloc_meta_bucket_pages(GFP_KERNEL, &c->sb);
19251927
if (!c->uuids)
19261928
goto err;
19271929

0 commit comments

Comments
 (0)