Commit b4a620ff authored by Coly Li's avatar Coly Li Committed by Yang Yingliang
Browse files

make bch_btree_check() to be multiple threads

mainline inclusion
from mainline-v5.7-rc1
commit 8e710227
category: performance
bugzilla: https://bugzilla.openeuler.org/show_bug.cgi?id=327


CVE: NA

When registering a cache device, bch_btree_check() is called to check
all btree nodes, to make sure the btree is consistent and not
corrupted.

bch_btree_check() is recursively executed in a single thread, when there
are a lot of data cached and the btree is huge, it may take very long
time to check all the btree nodes. In my testing, I observed it took
around 50 minutes to finish bch_btree_check().

When checking the bcache btree nodes, the cache set is not running yet,
and indeed the whole tree is in read-only state, it is safe to create
multiple threads to check the btree in parallel.

This patch tries to create multiple threads, and each thread tries to
one-by-one check the sub-tree indexed by a key from the btree root node.
The parallel thread number depends on how many keys in the btree root
node. At most BCH_BTR_CHKTHREAD_MAX (64) threads can be created, but in
practice is should be min(cpu-number/2, root-node-keys-number).

Signed-off-by: default avatarColy Li <colyli@suse.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarqinghaixiang <xuweiqhx@163.com>
Signed-off-by: default avatarXu Wei <xuwei56@huawei.com>
Acked-by: default avatarXie XiuQi <xiexiuqi@huawei.com>
Reviewed-by: default avatarLi Ruilin <liruilin4@huawei.com>
Signed-off-by: default avatarYang Yingliang <yangyingliang@huawei.com>
parent b278db77
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment