Linux bcache driver list
 help / color / mirror / Atom feed
From: mingzhe <mingzhe.zou@easystack.cn>
To: Coly Li <colyli@suse.de>
Cc: linux-bcache@vger.kernel.org, zoumingzhe@qq.com
Subject: Re: [PATCH v2] bcache: fix set_at_max_writeback_rate() for multiple attached devices
Date: Mon, 19 Sep 2022 14:24:40 +0800	[thread overview]
Message-ID: <7239cacc-9bad-389b-2838-36d38a147c4f@easystack.cn> (raw)
In-Reply-To: <EABD6CA2-9BC2-4243-B3DE-3B0FA6F43583@suse.de>



在 2022/9/19 12:38, Coly Li 写道:
> 
> 
>> 2022年9月19日 11:29,mingzhe <mingzhe.zou@easystack.cn> 写道:
>>
>>
>>
>> 在 2022/9/18 20:16, Coly Li 写道:
>>> 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>
>>> ---
>>> Changelog:
>>> v2: Add the missing "!atomic_read(&c->at_max_writeback_rate)" part
>>>      back.
>>> v1: Original verison.
>>>   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;
>> Hi, Coly

> 
> BTW, if the patch looks fine to you, could you please to response a Reviewed-by or Acked-by for it?
> 
> Thanks.
> 
> Coly Li
> 
Acked-by: Mingzhe Zou <mingzhe.zou@easystack.cn>

Thanks

mingzhe
> 

      reply	other threads:[~2022-09-19  6:24 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-18 12:16 [PATCH v2] bcache: fix set_at_max_writeback_rate() for multiple attached devices Coly Li
2022-09-19  3:29 ` mingzhe
2022-09-19  4:38   ` Coly Li
2022-09-19  6:24     ` mingzhe [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7239cacc-9bad-389b-2838-36d38a147c4f@easystack.cn \
    --to=mingzhe.zou@easystack.cn \
    --cc=colyli@suse.de \
    --cc=linux-bcache@vger.kernel.org \
    --cc=zoumingzhe@qq.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox