]> git.baikalelectronics.ru Git - kernel.git/commit
bcache: improve multithreaded bch_sectors_dirty_init()
authorColy Li <colyli@suse.de>
Tue, 24 May 2022 10:23:34 +0000 (18:23 +0800)
committerJens Axboe <axboe@kernel.dk>
Tue, 24 May 2022 12:19:33 +0000 (06:19 -0600)
commitc4f0da6f4a1ecee9209aa4d1f1708e9134a60c17
treee78ae185437cbfc5f80c365156860462df11d8ee
parent35b04bfdac3b6e8c851493fbe2d4b62847088f83
bcache: improve multithreaded bch_sectors_dirty_init()

Commit 88d2b0d3be5c ("bcache: make bch_sectors_dirty_init() to be
multithreaded") makes bch_sectors_dirty_init() to be much faster
when counting dirty sectors by iterating all dirty keys in the btree.
But it isn't in ideal shape yet, still can be improved.

This patch does the following changes to improve current parallel dirty
keys iteration on the btree,
- Add read lock to root node when multiple threads iterating the btree,
  to prevent the root node gets split by I/Os from other registered
  bcache devices.
- Remove local variable "char name[32]" and generate kernel thread name
  string directly when calling kthread_run().
- Allocate "struct bch_dirty_init_state state" directly on stack and
  avoid the unnecessary dynamic memory allocation for it.
- Decrease BCH_DIRTY_INIT_THRD_MAX from 64 to 12 which is enough indeed.
- Increase &state->started to count created kernel thread after it
  succeeds to create.
- When wait for all dirty key counting threads to finish, use
  wait_event() to replace wait_event_interruptible().

With the above changes, the code is more clear, and some potential error
conditions are avoided.

Fixes: 88d2b0d3be5c ("bcache: make bch_sectors_dirty_init() to be multithreaded")
Signed-off-by: Coly Li <colyli@suse.de>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/20220524102336.10684-3-colyli@suse.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/bcache/writeback.c
drivers/md/bcache/writeback.h