]> git.baikalelectronics.ru Git - kernel.git/commit
bcache: fix set_at_max_writeback_rate() for multiple attached devices
authorColy Li <colyli@suse.de>
Mon, 19 Sep 2022 16:16:47 +0000 (00:16 +0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 26 Oct 2022 11:22:57 +0000 (13:22 +0200)
commit8e1207db64ffd9a9b74c6be5cc8d910dfc893db5
tree6b39773058f3a8c4c9f07585e425cca282d310be
parent76d7de4eb9bb7fae75a22467bfb899162ceb44a3
bcache: fix set_at_max_writeback_rate() for multiple attached devices

[ Upstream commit f04377bdcbe18a2989c825e37aa91887faf8dfe5 ]

Inside set_at_max_writeback_rate() the calculation in following if()
check is wrong,
if (atomic_inc_return(&c->idle_counter) <
    atomic_read(&c->attached_dev_nr) * 6)

Because each attached backing device has its own writeback thread
running and increasing c->idle_counter, the counter increates much
faster than expected. The correct calculation should be,
(counter / dev_nr) < dev_nr * 6
which equals to,
counter < dev_nr * dev_nr * 6

This patch fixes the above mistake with correct calculation, and helper
routine idle_counter_exceeded() is added to make code be more clear.

Reported-by: Mingzhe Zou <mingzhe.zou@easystack.cn>
Signed-off-by: Coly Li <colyli@suse.de>
Acked-by: Mingzhe Zou <mingzhe.zou@easystack.cn>
Link: https://lore.kernel.org/r/20220919161647.81238-6-colyli@suse.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/md/bcache/writeback.c