• C
    bcache: improve multithreaded bch_btree_check() · 75c83226
    Coly Li 提交于
    mainline inclusion
    from v5.19-rc1
    commit 62253644
    category: bugfix
    bugzilla: https://gitee.com/openeuler/kernel/issues/I59A5L?from=project-issue
    CVE: N/A
    
    ----------------------------------------
    
    Commit 8e710227 ("bcache: make bch_btree_check() to be
    multithreaded") makes bch_btree_check() to be much faster when checking
    all btree nodes during cache device registration. But it isn't in ideal
    shap yet, still can be improved.
    
    This patch does the following thing to improve current parallel btree
    nodes check by multiple threads in bch_btree_check(),
    - Add read lock to root node while checking all the btree nodes with
      multiple threads. Although currently it is not mandatory but it is
      good to have a read lock in code logic.
    - Remove local variable 'char name[32]', and generate kernel thread name
      string directly when calling kthread_run().
    - Allocate local variable "struct btree_check_state check_state" on the
      stack and avoid unnecessary dynamic memory allocation for it.
    - Reduce BCH_BTR_CHKTHREAD_MAX from 64 to 12 which is enough indeed.
    - Increase check_state->started to count created kernel thread after it
      succeeds to create.
    - When wait for all checking kernel threads to finish, use wait_event()
      to replace wait_event_interruptible().
    
    With this change, the code is more clear, and some potential error
    conditions are avoided.
    
    Fixes: 8e710227 ("bcache: make bch_btree_check() to be multithreaded")
    Signed-off-by: NColy Li <colyli@suse.de>
    Cc: stable@vger.kernel.org
    Link: https://lore.kernel.org/r/20220524102336.10684-2-colyli@suse.deSigned-off-by: NJens Axboe <axboe@kernel.dk>
    Reviewed-by: NJason Yan <yanaijie@huawei.com>
    Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
    75c83226
btree.h 13.9 KB