From: Ivan Babrou <ivan@cloudflare.com>
To: Shakeel Butt <shakeelb@google.com>
Cc: cgroups@vger.kernel.org, Linux MM <linux-mm@kvack.org>,
kernel-team <kernel-team@cloudflare.com>,
Johannes Weiner <hannes@cmpxchg.org>,
Michal Hocko <mhocko@kernel.org>,
Roman Gushchin <roman.gushchin@linux.dev>,
Muchun Song <muchun.song@linux.dev>,
Andrew Morton <akpm@linux-foundation.org>,
linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: Expensive memory.stat + cpu.stat reads
Date: Mon, 10 Jul 2023 16:21:51 -0700 [thread overview]
Message-ID: <CABWYdi2pBaCrdKcM37oBomc+5W8MdRp1HwPpOExBGYfZitxyWA@mail.gmail.com> (raw)
In-Reply-To: <20230706062045.xwmwns7cm4fxd7iu@google.com>
On Wed, Jul 5, 2023 at 11:20 PM Shakeel Butt <shakeelb@google.com> wrote:
>
> On Fri, Jun 30, 2023 at 04:22:28PM -0700, Ivan Babrou wrote:
> > Hello,
> >
> > We're seeing CPU load issues with cgroup stats retrieval. I made a
> > public gist with all the details, including the repro code (which
> > unfortunately requires heavily loaded hardware) and some flamegraphs:
> >
> > * https://gist.github.com/bobrik/5ba58fb75a48620a1965026ad30a0a13
> >
> > I'll repeat the gist of that gist here. Our repro has the following
> > output after a warm-up run:
> >
> > completed: 5.17s [manual / mem-stat + cpu-stat]
> > completed: 5.59s [manual / cpu-stat + mem-stat]
> > completed: 0.52s [manual / mem-stat]
> > completed: 0.04s [manual / cpu-stat]
> >
> > The first two lines do effectively the following:
> >
> > for _ in $(seq 1 1000); do cat /sys/fs/cgroup/system.slice/memory.stat
> > /sys/fs/cgroup/system.slice/cpu.stat > /dev/null
> >
> > The latter two are the same thing, but via two loops:
> >
> > for _ in $(seq 1 1000); do cat /sys/fs/cgroup/system.slice/cpu.stat >
> > /dev/null; done
> > for _ in $(seq 1 1000); do cat /sys/fs/cgroup/system.slice/memory.stat
> > > /dev/null; done
> >
> > As you might've noticed from the output, splitting the loop into two
> > makes the code run 10x faster. This isn't great, because most
> > monitoring software likes to get all stats for one service before
> > reading the stats for the next one, which maps to the slow and
> > expensive way of doing this.
> >
> > We're running Linux v6.1 (the output is from v6.1.25) with no patches
> > that touch the cgroup or mm subsystems, so you can assume vanilla
> > kernel.
> >
> > From the flamegraph it just looks like rstat flushing takes longer. I
> > used the following flags on an AMD EPYC 7642 system (our usual pick
> > cpu-clock was blaming spinlock irqrestore, which was questionable):
> >
> > perf -e cycles -g --call-graph fp -F 999 -- /tmp/repro
> >
> > Naturally, there are two questions that arise:
> >
> > * Is this expected (I guess not, but good to be sure)?
> > * What can we do to make this better?
> >
> > I am happy to try out patches or to do some tracing to help understand
> > this better.
>
> Hi Ivan,
>
> Thanks a lot, as always, for reporting this. This is not expected and
> should be fixed. Is the issue easy to repro or some specific workload or
> high load/traffic is required? Can you repro this with the latest linus
> tree? Also do you see any difference of root's cgroup.stat where this
> issue happens vs good state?
I'm afraid there's no easy way to reproduce. We see it from time to
time in different locations. The one that I was looking at for the
initial email does not reproduce it anymore:
completed: 0.75s [manual / cpu-stat + mem-stat]
completed: 0.72s [manual / mem-stat]
completed: 0.05s [manual / cpu-stat]
I took the top 20 servers by metrics scrape duration for cadvisor and
it it does happen on the slowest ones:
completed: 22.32s [manual / cpu-stat + mem-stat]
completed: 0.34s [manual / mem-stat]
completed: 1.68s [manual / cpu-stat]
Is cadvisor or a similar metrics agent used by Google? Any chance you
could see if your own fleet exhibits this behavior?
Given that this behavior requires full production setup with customer
traffic and long qualification times we have for kernels, I'm not sure
if I can try the linus tree here.
I uploaded the contents of /sys/fs/cgroup/memory.stat here:
* https://gist.github.com/bobrik/9255b5e8ed0a83afb73ebf06b79f07c4
The fast one is v6.1.37 and the slow one is v6.1.25. I'm not sure if
the kernel version makes a difference or if it's a matter of uptime /
traffic profile. The data is from two different locations. The fast
location has gone through an expansion, which meant a full reboot with
a kernel upgrade, so maybe that affected things:
* https://i.imgur.com/x8uyMaF.png
Let me try to reboot the slow location and see if there's any lasting
improvement.
next prev parent reply other threads:[~2023-07-10 23:22 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-30 23:22 Ivan Babrou
2023-07-06 6:20 ` Shakeel Butt
2023-07-10 23:21 ` Ivan Babrou [this message]
2023-07-11 0:44 ` Waiman Long
2023-07-13 23:25 ` Ivan Babrou
2023-07-14 17:23 ` Waiman Long
2023-07-15 0:00 ` Ivan Babrou
2023-07-15 0:30 ` Ivan Babrou
2023-08-11 22:03 ` Ivan Babrou
2023-08-11 22:27 ` Waiman Long
2023-08-11 22:35 ` Ivan Babrou
2023-08-12 2:33 ` Shakeel Butt
2023-08-14 17:56 ` Ivan Babrou
2023-08-11 23:43 ` Yosry Ahmed
2023-08-12 0:01 ` Yosry Ahmed
2023-08-15 0:18 ` Tejun Heo
2023-08-15 0:30 ` Ivan Babrou
2023-08-15 0:31 ` Yosry Ahmed
2023-07-15 0:14 ` Ivan Babrou
2023-07-10 14:44 ` Michal Koutný
2023-07-10 23:23 ` Ivan Babrou
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=CABWYdi2pBaCrdKcM37oBomc+5W8MdRp1HwPpOExBGYfZitxyWA@mail.gmail.com \
--to=ivan@cloudflare.com \
--cc=akpm@linux-foundation.org \
--cc=cgroups@vger.kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kernel-team@cloudflare.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mhocko@kernel.org \
--cc=muchun.song@linux.dev \
--cc=roman.gushchin@linux.dev \
--cc=shakeelb@google.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