* [PATCH 1/5] bcache: remove unnecessary flush_workqueue
2022-09-19 16:16 [PATCH 0/5] bcache patches for Linux v6.1 Coly Li
@ 2022-09-19 16:16 ` Coly Li
2022-09-19 16:16 ` [PATCH 2/5] bcache: remove unused bch_mark_cache_readahead function def in stats.h Coly Li
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Coly Li @ 2022-09-19 16:16 UTC (permalink / raw)
To: axboe; +Cc: linux-bcache, linux-block, Li Lei, Coly Li
From: Li Lei <lilei@szsandstone.com>
All pending works will be drained by destroy_workqueue(), no need to call
flush_workqueue() explicitly.
Signed-off-by: Li Lei <lilei@szsandstone.com>
Signed-off-by: Coly Li <colyli@suse.de>
---
drivers/md/bcache/writeback.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
index 3f0ff3aab6f2..647661005176 100644
--- a/drivers/md/bcache/writeback.c
+++ b/drivers/md/bcache/writeback.c
@@ -801,10 +801,9 @@ static int bch_writeback_thread(void *arg)
}
}
- if (dc->writeback_write_wq) {
- flush_workqueue(dc->writeback_write_wq);
+ if (dc->writeback_write_wq)
destroy_workqueue(dc->writeback_write_wq);
- }
+
cached_dev_put(dc);
wait_for_kthread_stop();
--
2.35.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/5] bcache: remove unused bch_mark_cache_readahead function def in stats.h
2022-09-19 16:16 [PATCH 0/5] bcache patches for Linux v6.1 Coly Li
2022-09-19 16:16 ` [PATCH 1/5] bcache: remove unnecessary flush_workqueue Coly Li
@ 2022-09-19 16:16 ` Coly Li
2022-09-19 16:16 ` [PATCH 3/5] bcache: bset: Fix comment typos Coly Li
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Coly Li @ 2022-09-19 16:16 UTC (permalink / raw)
To: axboe; +Cc: linux-bcache, linux-block, Lin Feng, Coly Li
From: Lin Feng <linf@wangsu.com>
This is a cleanup for commit 1616a4c2ab1a ("bcache: remove bcache device
self-defined readahead")', currently no user for
bch_mark_cache_readahead() since that commit.
Signed-off-by: Lin Feng <linf@wangsu.com>
Signed-off-by: Coly Li <colyli@suse.de>
---
drivers/md/bcache/stats.h | 1 -
1 file changed, 1 deletion(-)
diff --git a/drivers/md/bcache/stats.h b/drivers/md/bcache/stats.h
index ca4f435f7216..bd3afc856d53 100644
--- a/drivers/md/bcache/stats.h
+++ b/drivers/md/bcache/stats.h
@@ -54,7 +54,6 @@ void bch_cache_accounting_destroy(struct cache_accounting *acc);
void bch_mark_cache_accounting(struct cache_set *c, struct bcache_device *d,
bool hit, bool bypass);
-void bch_mark_cache_readahead(struct cache_set *c, struct bcache_device *d);
void bch_mark_cache_miss_collision(struct cache_set *c,
struct bcache_device *d);
void bch_mark_sectors_bypassed(struct cache_set *c,
--
2.35.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/5] bcache: bset: Fix comment typos
2022-09-19 16:16 [PATCH 0/5] bcache patches for Linux v6.1 Coly Li
2022-09-19 16:16 ` [PATCH 1/5] bcache: remove unnecessary flush_workqueue Coly Li
2022-09-19 16:16 ` [PATCH 2/5] bcache: remove unused bch_mark_cache_readahead function def in stats.h Coly Li
@ 2022-09-19 16:16 ` Coly Li
2022-09-19 16:16 ` [PATCH 4/5] bcache:: fix repeated words in comments Coly Li
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: Coly Li @ 2022-09-19 16:16 UTC (permalink / raw)
To: axboe; +Cc: linux-bcache, linux-block, Jules Maselbas, Kent Overstreet, Coly Li
From: Jules Maselbas <jmaselbas@kalray.eu>
Remove the redundant word `by`, correct the typo `creaated`.
CC: Kent Overstreet <kent.overstreet@gmail.com>
CC: linux-bcache@vger.kernel.org
Signed-off-by: Jules Maselbas <jmaselbas@kalray.eu>
Signed-off-by: Coly Li <colyli@suse.de>
---
drivers/md/bcache/bset.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/md/bcache/bset.c b/drivers/md/bcache/bset.c
index 94d38e8a59b3..2bba4d6aaaa2 100644
--- a/drivers/md/bcache/bset.c
+++ b/drivers/md/bcache/bset.c
@@ -1264,7 +1264,7 @@ static void __btree_sort(struct btree_keys *b, struct btree_iter *iter,
*
* Don't worry event 'out' is allocated from mempool, it can
* still be swapped here. Because state->pool is a page mempool
- * creaated by by mempool_init_page_pool(), which allocates
+ * created by mempool_init_page_pool(), which allocates
* pages by alloc_pages() indeed.
*/
--
2.35.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/5] bcache:: fix repeated words in comments
2022-09-19 16:16 [PATCH 0/5] bcache patches for Linux v6.1 Coly Li
` (2 preceding siblings ...)
2022-09-19 16:16 ` [PATCH 3/5] bcache: bset: Fix comment typos Coly Li
@ 2022-09-19 16:16 ` Coly Li
2022-09-19 16:16 ` [PATCH 5/5] bcache: fix set_at_max_writeback_rate() for multiple attached devices Coly Li
2022-09-19 17:12 ` [PATCH 0/5] bcache patches for Linux v6.1 Jens Axboe
5 siblings, 0 replies; 7+ messages in thread
From: Coly Li @ 2022-09-19 16:16 UTC (permalink / raw)
To: axboe; +Cc: linux-bcache, linux-block, Jilin Yuan, Coly Li
From: Jilin Yuan <yuanjilin@cdjrlc.com>
Delete the redundant word 'we'.
Signed-off-by: Jilin Yuan <yuanjilin@cdjrlc.com>
Signed-off-by: Coly Li <colyli@suse.de>
---
drivers/md/bcache/bcache.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/md/bcache/bcache.h b/drivers/md/bcache/bcache.h
index 2acda9cea0f9..aebb7ef10e63 100644
--- a/drivers/md/bcache/bcache.h
+++ b/drivers/md/bcache/bcache.h
@@ -107,7 +107,7 @@
*
* BTREE NODES:
*
- * Our unit of allocation is a bucket, and we we can't arbitrarily allocate and
+ * Our unit of allocation is a bucket, and we can't arbitrarily allocate and
* free smaller than a bucket - so, that's how big our btree nodes are.
*
* (If buckets are really big we'll only use part of the bucket for a btree node
--
2.35.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/5] bcache: fix set_at_max_writeback_rate() for multiple attached devices
2022-09-19 16:16 [PATCH 0/5] bcache patches for Linux v6.1 Coly Li
` (3 preceding siblings ...)
2022-09-19 16:16 ` [PATCH 4/5] bcache:: fix repeated words in comments Coly Li
@ 2022-09-19 16:16 ` Coly Li
2022-09-19 17:12 ` [PATCH 0/5] bcache patches for Linux v6.1 Jens Axboe
5 siblings, 0 replies; 7+ messages in thread
From: Coly Li @ 2022-09-19 16:16 UTC (permalink / raw)
To: axboe; +Cc: linux-bcache, linux-block, Coly Li, Mingzhe Zou
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>
---
drivers/md/bcache/writeback.c | 73 +++++++++++++++++++++++++----------
1 file changed, 52 insertions(+), 21 deletions(-)
diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
index 647661005176..c186bf55fe61 100644
--- a/drivers/md/bcache/writeback.c
+++ b/drivers/md/bcache/writeback.c
@@ -157,6 +157,53 @@ static void __update_writeback_rate(struct cached_dev *dc)
dc->writeback_rate_target = target;
}
+static bool idle_counter_exceeded(struct cache_set *c)
+{
+ int counter, dev_nr;
+
+ /*
+ * If c->idle_counter is overflow (idel for really long time),
+ * reset as 0 and not set maximum rate this time for code
+ * simplicity.
+ */
+ counter = atomic_inc_return(&c->idle_counter);
+ if (counter <= 0) {
+ atomic_set(&c->idle_counter, 0);
+ return false;
+ }
+
+ dev_nr = atomic_read(&c->attached_dev_nr);
+ if (dev_nr == 0)
+ return false;
+
+ /*
+ * c->idle_counter is increased by writeback thread of all
+ * attached backing devices, in order to represent a rough
+ * time period, counter should be divided by dev_nr.
+ * Otherwise the idle time cannot be larger with more backing
+ * device attached.
+ * The following calculation equals to checking
+ * (counter / dev_nr) < (dev_nr * 6)
+ */
+ if (counter < (dev_nr * dev_nr * 6))
+ return false;
+
+ return true;
+}
+
+/*
+ * Idle_counter is increased every time when update_writeback_rate() is
+ * called. If all backing devices attached to the same cache set have
+ * identical dc->writeback_rate_update_seconds values, it is about 6
+ * rounds of update_writeback_rate() on each backing device before
+ * c->at_max_writeback_rate is set to 1, and then max wrteback rate set
+ * to each dc->writeback_rate.rate.
+ * In order to avoid extra locking cost for counting exact dirty cached
+ * devices number, c->attached_dev_nr is used to calculate the idle
+ * throushold. It might be bigger if not all cached device are in write-
+ * back mode, but it still works well with limited extra rounds of
+ * update_writeback_rate().
+ */
static bool set_at_max_writeback_rate(struct cache_set *c,
struct cached_dev *dc)
{
@@ -167,21 +214,8 @@ static bool set_at_max_writeback_rate(struct cache_set *c,
/* Don't set max writeback rate if gc is running */
if (!c->gc_mark_valid)
return false;
- /*
- * Idle_counter is increased everytime when update_writeback_rate() is
- * called. If all backing devices attached to the same cache set have
- * identical dc->writeback_rate_update_seconds values, it is about 6
- * rounds of update_writeback_rate() on each backing device before
- * c->at_max_writeback_rate is set to 1, and then max wrteback rate set
- * to each dc->writeback_rate.rate.
- * In order to avoid extra locking cost for counting exact dirty cached
- * devices number, c->attached_dev_nr is used to calculate the idle
- * throushold. It might be bigger if not all cached device are in write-
- * back mode, but it still works well with limited extra rounds of
- * update_writeback_rate().
- */
- if (atomic_inc_return(&c->idle_counter) <
- atomic_read(&c->attached_dev_nr) * 6)
+
+ if (!idle_counter_exceeded(c))
return false;
if (atomic_read(&c->at_max_writeback_rate) != 1)
@@ -195,13 +229,10 @@ static bool set_at_max_writeback_rate(struct cache_set *c,
dc->writeback_rate_change = 0;
/*
- * Check c->idle_counter and c->at_max_writeback_rate agagain in case
- * new I/O arrives during before set_at_max_writeback_rate() returns.
- * Then the writeback rate is set to 1, and its new value should be
- * decided via __update_writeback_rate().
+ * In case new I/O arrives during before
+ * set_at_max_writeback_rate() returns.
*/
- if ((atomic_read(&c->idle_counter) <
- atomic_read(&c->attached_dev_nr) * 6) ||
+ if (!idle_counter_exceeded(c) ||
!atomic_read(&c->at_max_writeback_rate))
return false;
--
2.35.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 0/5] bcache patches for Linux v6.1
2022-09-19 16:16 [PATCH 0/5] bcache patches for Linux v6.1 Coly Li
` (4 preceding siblings ...)
2022-09-19 16:16 ` [PATCH 5/5] bcache: fix set_at_max_writeback_rate() for multiple attached devices Coly Li
@ 2022-09-19 17:12 ` Jens Axboe
5 siblings, 0 replies; 7+ messages in thread
From: Jens Axboe @ 2022-09-19 17:12 UTC (permalink / raw)
To: Coly Li; +Cc: linux-block, linux-bcache
On Tue, 20 Sep 2022 00:16:42 +0800, Coly Li wrote:
> This is the 1st wave bcache patches for Linux v6.1.
>
> The patch from me fixes a calculation mistake reported by Mingzhe Zou,
> now the idle time to wait before setting maximum writeback rate can be
> increased when more backing devices attached.
>
> And we also have other code cleanup patches from Jilin Yuan,
> Jules Maselbas, Lei Li and Lin Feng.
>
> [...]
Applied, thanks!
[1/5] bcache: remove unnecessary flush_workqueue
commit: 97d26ae764a43bfaf870312761a0a0f9b49b6351
[2/5] bcache: remove unused bch_mark_cache_readahead function def in stats.h
commit: d86b4e6dc88826f2b5cfa90c4ebbccb19a88bc39
[3/5] bcache: bset: Fix comment typos
commit: 11e529ccea33f24af6b54fe10bb3be9c1c48eddb
[4/5] bcache:: fix repeated words in comments
commit: 6dd3be6923eec2c49860e7292e4e2783c74a9dff
[5/5] bcache: fix set_at_max_writeback_rate() for multiple attached devices
commit: d2d05b88035d2d51a5bb6c5afec88a0880c73df4
Best regards,
--
Jens Axboe
^ permalink raw reply [flat|nested] 7+ messages in thread