Skip to content

Commit f9c32a5

Browse files
Coly Liaxboe
authored andcommitted
bcache: handle btree node memory allocation properly for bucket size > 8MB
Currently the bcache internal btree node occupies a whole bucket. When loading the btree node from cache device into memory, mca_data_alloc() will call bch_btree_keys_alloc() to allocate memory for the whole bucket size, ilog2(b->c->btree_pages) is send to bch_btree_keys_alloc() as the parameter 'page_order'. c->btree_pages is set as bucket_pages() in bch_cache_set_alloc(), for bucket size > 8MB, ilog2(b->c->btree_pages) is 12 for 4KB page size. By default the maximum page order __get_free_pages() accepts is MAX_ORDER (11), in this condition bch_btree_keys_alloc() will always fail. Because of other over-page-order allocation failure fails the cache device registration, such btree node allocation failure wasn't observed during runtime. After other blocking page allocation failures for bucket size > 8MB, this btree node allocation issue may trigger potentical risk e.g. infinite dead-loop to retry btree node allocation after failure. This patch fixes the potential problem by setting c->btree_pages to meta_bucket_pages() in bch_cache_set_alloc(). In the condition that bucket size > 8MB, meta_bucket_pages() will always return a number which won't exceed the maximum page order of the buddy allocator. Signed-off-by: Coly Li <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent bf6af17 commit f9c32a5

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/md/bcache/super.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1875,7 +1875,7 @@ struct cache_set *bch_cache_set_alloc(struct cache_sb *sb)
18751875
c->nr_uuids = meta_bucket_bytes(&c->sb) / sizeof(struct uuid_entry);
18761876
c->devices_max_used = 0;
18771877
atomic_set(&c->attached_dev_nr, 0);
1878-
c->btree_pages = bucket_pages(c);
1878+
c->btree_pages = meta_bucket_pages(&c->sb);
18791879
if (c->btree_pages > BTREE_MAX_PAGES)
18801880
c->btree_pages = max_t(int, c->btree_pages / 4,
18811881
BTREE_MAX_PAGES);

0 commit comments

Comments
 (0)