linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: "T.J. Mercier" <tjmercier@google.com>
To: Yosry Ahmed <yosryahmed@google.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>,
	Andrew Morton <akpm@linux-foundation.org>,
	 Johannes Weiner <hannes@cmpxchg.org>,
	Michal Hocko <mhocko@kernel.org>,
	 Roman Gushchin <roman.gushchin@linux.dev>,
	Muchun Song <muchun.song@linux.dev>,
	 Greg Thelen <gthelen@google.com>,
	Facebook Kernel Team <kernel-team@meta.com>,
	linux-mm@kvack.org,  linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] memcg: expose children memory usage for root
Date: Fri, 26 Jul 2024 09:50:49 -0700	[thread overview]
Message-ID: <CABdmKX0XtaBCF-Dwv2rJBUTjj1NXOus9CL9k2ubaJRSGM35vTg@mail.gmail.com> (raw)
In-Reply-To: <CAJD7tkaW8bkwpUChJPc-Bw1epfrLySVhgr8528yZg5eCg3d=JA@mail.gmail.com>

On Fri, Jul 26, 2024 at 9:26 AM Yosry Ahmed <yosryahmed@google.com> wrote:
>
> On Fri, Jul 26, 2024 at 8:48 AM Shakeel Butt <shakeel.butt@linux.dev> wrote:
> >
> > On Thu, Jul 25, 2024 at 04:20:45PM GMT, Yosry Ahmed wrote:
> > > On Mon, Jul 22, 2024 at 3:53 PM Shakeel Butt <shakeel.butt@linux.dev> wrote:
> > > >
> > > > Linux kernel does not expose memory.current on the root memcg and there
> > > > are applications which have to traverse all the top level memcgs to
> > > > calculate the total memory charged in the system. This is more expensive
> > > > (directory traversal and multiple open and reads) and is racy on a busy
> > > > machine. As the kernel already have the needed information i.e. root's
> > > > memory.current, why not expose that?
> > > >
> > > > However root's memory.current will have a different semantics than the
> > > > non-root's memory.current as the kernel skips the charging for root, so
> > > > maybe it is better to have a different named interface for the root.
> > > > Something like memory.children_usage only for root memcg.
> > > >
> > > > Now there is still a question that why the kernel does not expose
> > > > memory.current for the root. The historical reason was that the memcg
> > > > charging was expensice and to provide the users to bypass the memcg
> > > > charging by letting them run in the root. However do we still want to
> > > > have this exception today? What is stopping us to start charging the
> > > > root memcg as well. Of course the root will not have limits but the
> > > > allocations will go through memcg charging and then the memory.current
> > > > of root and non-root will have the same semantics.
> > > >
> > > > This is an RFC to start a discussion on memcg charging for root.
> > >
> > > I vaguely remember when running some netperf tests (tcp_rr?) in a
> > > cgroup that the performance decreases considerably with every level
> > > down the hierarchy. I am assuming that charging was a part of the
> > > reason. If that's the case, charging the root will be similar to
> > > moving all workloads one level down the hierarchy in terms of charging
> > > overhead.
> >
> > No, the workloads running in non-root memcgs will not see any
> > difference. Only the workloads running in root will see charging
> > overhead.
>
> Oh yeah we already charge the root's page counters hierarchically in
> the upstream kernel, we just do not charge them if the origin of the
> charge is the root itself.
>
> We also have workloads that iterate top-level memcgs to calculate the
> total charged memory, so memory.children_usage for the root memcg
> would help.
>
> As for memory.current, do you have any data about how much memory is
> charged to the root itself?

Yeah I wonder if we'd be able to see any significant regressions for
stuff that lives there today if we were to start charging it. I can
try running a test with Android next week. I guess try_charge() is the
main thing that would need to change to allow root charges?

> We think of the memory charged to the root
> as system overhead, while the memory charged to top-level memcgs
> isn't.
>
> So basically total_memory - root::memory.children_usage would be a
> fast way to get a rough estimation of system overhead. The same would
> not apply for total_memory - root::memory.current if I understand
> correctly.
>

On Fri, Jul 26, 2024 at 9:26 AM Yosry Ahmed <yosryahmed@google.com> wrote:
>
> On Fri, Jul 26, 2024 at 8:48 AM Shakeel Butt <shakeel.butt@linux.dev> wrote:
> >
> > On Thu, Jul 25, 2024 at 04:20:45PM GMT, Yosry Ahmed wrote:
> > > On Mon, Jul 22, 2024 at 3:53 PM Shakeel Butt <shakeel.butt@linux.dev> wrote:
> > > >
> > > > Linux kernel does not expose memory.current on the root memcg and there
> > > > are applications which have to traverse all the top level memcgs to
> > > > calculate the total memory charged in the system. This is more expensive
> > > > (directory traversal and multiple open and reads) and is racy on a busy
> > > > machine. As the kernel already have the needed information i.e. root's
> > > > memory.current, why not expose that?
> > > >
> > > > However root's memory.current will have a different semantics than the
> > > > non-root's memory.current as the kernel skips the charging for root, so
> > > > maybe it is better to have a different named interface for the root.
> > > > Something like memory.children_usage only for root memcg.
> > > >
> > > > Now there is still a question that why the kernel does not expose
> > > > memory.current for the root. The historical reason was that the memcg
> > > > charging was expensice and to provide the users to bypass the memcg
> > > > charging by letting them run in the root. However do we still want to
> > > > have this exception today? What is stopping us to start charging the
> > > > root memcg as well. Of course the root will not have limits but the
> > > > allocations will go through memcg charging and then the memory.current
> > > > of root and non-root will have the same semantics.
> > > >
> > > > This is an RFC to start a discussion on memcg charging for root.
> > >
> > > I vaguely remember when running some netperf tests (tcp_rr?) in a
> > > cgroup that the performance decreases considerably with every level
> > > down the hierarchy. I am assuming that charging was a part of the
> > > reason. If that's the case, charging the root will be similar to
> > > moving all workloads one level down the hierarchy in terms of charging
> > > overhead.
> >
> > No, the workloads running in non-root memcgs will not see any
> > difference. Only the workloads running in root will see charging
> > overhead.
>
> Oh yeah we already charge the root's page counters hierarchically in
> the upstream kernel, we just do not charge them if the origin of the
> charge is the root itself.
>
> We also have workloads that iterate top-level memcgs to calculate the
> total charged memory, so memory.children_usage for the root memcg
> would help.
>
> As for memory.current, do you have any data about how much memory is
> charged to the root itself? We think of the memory charged to the root
> as system overhead, while the memory charged to top-level memcgs
> isn't.
>
> So basically total_memory - root::memory.children_usage would be a
> fast way to get a rough estimation of system overhead. The same would
> not apply for total_memory - root::memory.current if I understand
> correctly.
>


  reply	other threads:[~2024-07-26 16:51 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-22 22:53 Shakeel Butt
2024-07-25 23:12 ` T.J. Mercier
2024-07-26 15:46   ` Shakeel Butt
2024-07-26 16:46     ` T.J. Mercier
2024-07-25 23:20 ` Yosry Ahmed
2024-07-26 15:48   ` Shakeel Butt
2024-07-26 16:25     ` Yosry Ahmed
2024-07-26 16:50       ` T.J. Mercier [this message]
2024-07-26 17:18         ` Shakeel Butt
2024-07-26 17:30       ` Shakeel Butt
2024-07-26 17:43         ` Yosry Ahmed
2024-07-26 18:16           ` Shakeel Butt

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=CABdmKX0XtaBCF-Dwv2rJBUTjj1NXOus9CL9k2ubaJRSGM35vTg@mail.gmail.com \
    --to=tjmercier@google.com \
    --cc=akpm@linux-foundation.org \
    --cc=gthelen@google.com \
    --cc=hannes@cmpxchg.org \
    --cc=kernel-team@meta.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=shakeel.butt@linux.dev \
    --cc=yosryahmed@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