Re: Showing /sys/fs/cgroup/memory/memory.stat very slow on some machines

From: Shakeel Butt
Date: Wed Jul 18 2018 - 11:33:48 EST


On Wed, Jul 18, 2018 at 8:27 AM Bruce Merry <bmerry@xxxxxxxxx> wrote:
>
> On 18 July 2018 at 16:47, Michal Hocko <mhocko@xxxxxxxxxx> wrote:
> >> Thanks for looking into this. I'm not familiar with ftrace. Can you
> >> give me a specific command line to run? Based on "perf record cat
> >> /sys/fs/cgroup/memory/memory.stat"/"perf report", I see the following:
> >>
> >> 42.09% cat [kernel.kallsyms] [k] memcg_stat_show
> >> 29.19% cat [kernel.kallsyms] [k] memcg_sum_events.isra.22
> >> 12.41% cat [kernel.kallsyms] [k] mem_cgroup_iter
> >> 5.42% cat [kernel.kallsyms] [k] _find_next_bit
> >> 4.14% cat [kernel.kallsyms] [k] css_next_descendant_pre
> >> 3.44% cat [kernel.kallsyms] [k] find_next_bit
> >> 2.84% cat [kernel.kallsyms] [k] mem_cgroup_node_nr_lru_pages
> >
> > I would just use perf record as you did. How long did the call take?
> > Also is the excessive time an outlier or a more consistent thing? If the
> > former does perf record show any difference?
>
> I didn't note the exact time for that particular run, but it's pretty
> consistently 372-377ms on the machine that has that perf report. The
> times differ between machines showing the symptom (anywhere from
> 200-500ms), but are consistent (within a few ms) in back-to-back runs
> on each machine.
>
> >> Ubuntu 16.04 with kernel 4.13.0-41-generic (so presumably includes
> >> some Ubuntu special sauce).
> >
> > Do you see the same whe running with the vanilla kernel?
>
> We don't currently have any boxes running vanilla kernels. While I
> could install a test box with a vanilla kernel, I don't know how to
> reproduce the problem, what piece of our production environment is
> triggering it, or even why some machines are unaffected, so if the
> problem didn't re-occur on the test box I wouldn't be able to conclude
> anything useful.
>
> Do you have suggestions on things I could try that might trigger this?
> e.g. are there cases where a cgroup no longer shows up in the
> filesystem but is still lingering while waiting for its refcount to
> hit zero? Does every child cgroup contribute to the stat_show cost of
> its parent or does it have to have some non-trivial variation from its
> parent?
>

The memcg tree does include all zombie memcgs and these zombies does
contribute to the memcg_stat_show cost.

Shakeel