linux/drivers/md/bcache
Mingzhe Zou 7b1002f7cf bcache: fixup bcache_dev_sectors_dirty_add() multithreaded CPU false sharing
When attaching a cached device (a.k.a backing device) to a cache
device, bch_sectors_dirty_init() is called to count dirty sectors
and stripes (see what bcache_dev_sectors_dirty_add() does) on the
cache device.

When bcache_dev_sectors_dirty_add() is called, set_bit(stripe,
d->full_dirty_stripes) or clear_bit(stripe, d->full_dirty_stripes)
operation will always be performed. In full_dirty_stripes, each 1bit
represents stripe_size (8192) sectors (512B), so 1bit=4MB (8192*512),
and each CPU cache line=64B=512bit=2048MB. When 20 threads process
a cached disk with 100G dirty data, a single thread processes about
23M at a time, and 20 threads total 460M. These full_dirty_stripes
bits corresponding to the 460M data is likely to fall in the same CPU
cache line. When one of these threads performs a set_bit or clear_bit
operation, the same CPU cache line of other threads will become invalid
and must read the full_dirty_stripes from the main memory again. Compared
with single thread, the time of a bcache_dev_sectors_dirty_add()
call is increased by about 50 times in our test (100G dirty data,
20 threads, bcache_dev_sectors_dirty_add() is called more than
20 million times).

This patch tries to test_bit before set_bit or clear_bit operation.
Therefore, a lot of force set and clear operations will be avoided,
and most of bcache_dev_sectors_dirty_add() calls will only read CPU
cache line.

Signed-off-by: Mingzhe Zou <mingzhe.zou@easystack.cn>
Signed-off-by: Coly Li <colyli@suse.de>
2022-03-06 22:33:37 +08:00
..
alloc.c bcache: remove PTR_CACHE 2021-04-11 08:37:55 -06:00
bcache.h bcache: move uapi header bcache.h to bcache code directory 2021-10-29 06:43:21 -06:00
bcache_ondisk.h bcache: move uapi header bcache.h to bcache code directory 2021-10-29 06:43:21 -06:00
bset.c bcache: Avoid comma separated statements 2021-02-10 08:06:00 -07:00
bset.h bcache: move uapi header bcache.h to bcache code directory 2021-10-29 06:43:21 -06:00
btree.c bcache: Revert "bcache: use bvec_virt" 2021-11-08 06:23:17 -07:00
btree.h bcache: remove embedded struct cache_sb from struct cache_set 2020-10-02 14:25:30 -06:00
closure.c bcache: Convert to DEFINE_SHOW_ATTRIBUTE 2020-10-02 14:25:29 -06:00
closure.h bcache: fix typo in code comments of closure_return_with_destructor() 2018-10-08 08:19:43 -06:00
debug.c bcache: use bvec_kmap_local in bch_data_verify 2021-10-20 08:40:54 -06:00
debug.h bcache: add identifier names to arguments of function definitions 2018-08-11 15:46:41 -06:00
extents.c bcache: remove PTR_CACHE 2021-04-11 08:37:55 -06:00
extents.h bcache: add identifier names to arguments of function definitions 2018-08-11 15:46:41 -06:00
features.c bcache: move uapi header bcache.h to bcache code directory 2021-10-29 06:43:21 -06:00
features.h bcache: move uapi header bcache.h to bcache code directory 2021-10-29 06:43:21 -06:00
io.c block: pass a block_device and opf to bio_init 2022-02-02 07:49:59 -07:00
journal.c block: pass a block_device and opf to bio_reset 2022-02-02 07:50:00 -07:00
journal.h Revert "bcache: fix fifo index swapping condition in journal_pin_cmp()" 2019-11-18 08:35:47 -07:00
Kconfig block: make the block holder code optional 2021-08-09 11:50:42 -06:00
Makefile bcache: add sysfs file to display feature sets information of cache set 2020-07-25 07:38:21 -06:00
movinggc.c block: pass a block_device and opf to bio_init 2022-02-02 07:49:59 -07:00
request.c bcache: use bvec_kmap_local in bio_csum 2022-03-04 12:29:21 -07:00
request.h block: switch polling to be bio based 2021-10-18 06:17:36 -06:00
stats.c bcache: remove bcache device self-defined readahead 2021-06-08 15:06:03 -06:00
stats.h bcache: remove bcache device self-defined readahead 2021-06-08 15:06:03 -06:00
super.c block: pass a block_device and opf to bio_init 2022-02-02 07:49:59 -07:00
sysfs.c bcache: remove the backing_dev_name field from struct cached_dev 2021-10-20 08:40:54 -06:00
sysfs.h bcache: replace snprintf in show functions with sysfs_emit 2021-10-29 06:43:21 -06:00
trace.c License cleanup: add SPDX GPL-2.0 license identifier to files with no license 2017-11-02 11:10:55 +01:00
util.c treewide: Use fallthrough pseudo-keyword 2020-08-23 17:36:59 -05:00
util.h for-5.16/bdev-size-2021-10-29 2021-11-01 09:50:37 -07:00
writeback.c bcache: fixup bcache_dev_sectors_dirty_add() multithreaded CPU false sharing 2022-03-06 22:33:37 +08:00
writeback.h bcache: consider the fragmentation when update the writeback rate 2021-02-10 08:05:59 -07:00