linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Waiman Long <longman@redhat.com>
To: Tejun Heo <tj@kernel.org>
Cc: Jens Axboe <axboe@kernel.dk>,
	cgroups@vger.kernel.org, linux-block@vger.kernel.org,
	linux-kernel@vger.kernel.org, Ming Lei <ming.lei@redhat.com>
Subject: Re: [PATCH] blk-cgroup: Optimize blkcg_rstat_flush()
Date: Tue, 31 May 2022 15:22:02 -0400	[thread overview]
Message-ID: <341bbbed-23cc-12f4-d68c-a4e839a97a9f@redhat.com> (raw)
In-Reply-To: <70a2763a-f7c4-e161-23e4-33815e76380c@redhat.com>

On 5/31/22 15:03, Waiman Long wrote:
> On 5/31/22 14:24, Tejun Heo wrote:
>> Hello, Waiman.
>>
>> On Tue, May 31, 2022 at 02:18:21PM -0400, Waiman Long wrote:
>>> For a system with many CPUs and block devices, the time to do
>>> blkcg_rstat_flush() from cgroup_rstat_flush() can be rather long. It
>>> can be especially problematic as interrupt is disabled during the 
>>> flush.
>>> It was reported that it might take seconds in some extreme cases 
>>> leading
>>> to hard lockup messages.
>>>
>>> As it is likely that not all the percpu blkg_iostat_set's has been
>>> updated since the last flush, those stale blkg_iostat_set's don't need
>>> to be flushed in this case. This patch optimizes blkcg_rstat_flush()
>>> by checking the current sequence number against the one recorded since
>>> the last flush and skip the blkg_iostat_set if the sequence number
>>> hasn't changed. There is a slight chance that it may miss an update
>>> that is being done in parallel, the new update will just have to wait
>>> until the next flush.
>>>
>>> Signed-off-by: Waiman Long <longman@redhat.com>
>>> ---
>>>   block/blk-cgroup.c | 18 +++++++++++++++---
>>>   block/blk-cgroup.h |  1 +
>>>   2 files changed, 16 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
>>> index 40161a3f68d0..79b89af61ef2 100644
>>> --- a/block/blk-cgroup.c
>>> +++ b/block/blk-cgroup.c
>>> @@ -864,11 +864,23 @@ static void blkcg_rstat_flush(struct 
>>> cgroup_subsys_state *css, int cpu)
>>>           unsigned long flags;
>>>           unsigned int seq;
>>>   +        seq = u64_stats_fetch_begin(&bisc->sync);
>>> +        /*
>>> +         * If the sequence number hasn't been updated since the last
>>> +         * flush, we can skip this blkg_iostat_set though we may miss
>>> +         * an update that is happening in parallel.
>>> +         */
>>> +        if (seq == bisc->last_seq)
>>> +            continue;
>> Is this a sufficient solution? The code assumes that there aren't too 
>> many
>> blkgs for the cgroup, which can be wrong in some cases. Wouldn't it be
>> better to create a list of updated blkg's per blkcg so that we don't 
>> walk
>> all the dormant ones?
>
> It is probably not a sufficient solution, but it is simple. The 
> problem with keeping a list of recently updated blkg's is that 
> sequence lock does not provide enough synchronization on the read side 
> to guarantee a race free reset of the list. It may be doable, but I 
> need to think harder on the best way to do it without too much overhead.
>
> Thanks,
> Longman
>
I think we can use a lockless list to keep a list of recently updated 
blkg for each blkcg. There is an atomic operation overhead when an entry 
is added to the list though. I will send an updated patch later today or 
tomorrow.

Thanks,
Longman


      reply	other threads:[~2022-05-31 19:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-31 18:18 [PATCH] blk-cgroup: Optimize blkcg_rstat_flush() Waiman Long
2022-05-31 18:24 ` Tejun Heo
2022-05-31 19:03   ` Waiman Long
2022-05-31 19:22     ` Waiman Long [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=341bbbed-23cc-12f4-d68c-a4e839a97a9f@redhat.com \
    --to=longman@redhat.com \
    --cc=axboe@kernel.dk \
    --cc=cgroups@vger.kernel.org \
    --cc=linux-block@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@redhat.com \
    --cc=tj@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).