linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: Tejun Heo <tj@kernel.org>
To: Benjamin Berg <benjamin@sipsolutions.net>
Cc: cgroups@vger.kernel.org, linux-mm@kvack.org,
	Johannes Weiner <hannes@cmpxchg.org>
Subject: Re: Memory reclaim protection and cgroup nesting (desktop use)
Date: Wed, 4 Mar 2020 11:30:44 -0500	[thread overview]
Message-ID: <20200304163044.GF189690@mtj.thefacebook.com> (raw)
In-Reply-To: <d4826b9e568f1ab7df19f94c409df11956a8e262.camel@sipsolutions.net>

Hello,

(cc'ing Johannes and quoting whole msg)

On Wed, Mar 04, 2020 at 10:44:44AM +0100, Benjamin Berg wrote:
> Hi,
> 
> TL;DR: I seem to need memory.min/memory.max to be set on each child
> cgroup and not just the parents. Is this expected?

Yes, currently. However, v5.7+ will have a cgroup2 mount option to
propagate protection automatically.

  https://lore.kernel.org/linux-mm/20191219200718.15696-4-hannes@cmpxchg.org/

> I have been experimenting with using cgroups to protect a GNOME
> session. The intention is that the GNOME Shell itself and important
> other services remain responsive, even if the application workload is
> thrashing. The long term goal here is to bridge the time until an OOM
> killer like oomd would get the system back into normal conditions using
> memory pressure information.
> 
> Note that I have done these tests without any swap and with huge
> memory.min/memory.low values. I consider this scenario pathological,
> however, it seems like a reasonable way to really exercise the cgroup
> reclaim protection logic.

It's incomplete and more brittle in that the kernel has to treat a
large portion of memory usage as essentially memlocked.

> The resulting cgroup hierarchy looked something like:
> 
> -.slice
> ├─user.slice
> │ └─user-1000.slice
> │   ├─user@1000.service
> │   │ ├─session.slice
> │   │ │ ├─gsd-*.service
> │   │ │ │ └─208803 /usr/libexec/gsd-rfkill
> │   │ │ ├─gnome-shell-wayland.service
> │   │ │ │ ├─208493 /usr/bin/gnome-shell
> │   │ │ │ ├─208549 /usr/bin/Xwayland :0 -rootless -noreset -accessx -core -auth /run/user/1000/.mutter-Xwayla>
> │   │ │ │ └─ …
> │   │ └─apps.slice
> │   │   ├─gnome-launched-tracker-miner-fs.desktop-208880.scope
> │   │   │ └─208880 /usr/libexec/tracker-miner-fs
> │   │   ├─dbus-:1.2-org.gnome.OnlineAccounts@0.service
> │   │   │ └─208668 /usr/libexec/goa-daemon
> │   │   ├─flatpak-org.gnome.Fractal-210350.scope
> │   │   ├─gnome-terminal-server.service
> │   │   │ ├─209261 /usr/libexec/gnome-terminal-server
> │   │   │ ├─209434 bash
> │   │   │ └─ … including the test load i.e. "make -j32" of a C++ code
> 
> 
> I also enabled the CPU and IO controllers in my tests, but I don't
> think that is as relevant. The main thing is that I set

CPU control isn't but IO is. Without working IO isolation, it's
relatively easy to drive the system into the ground given enough
stress ouside the protected area.

>   memory.min: 2GiB
>   memory.low: 4GiB
> 
> using systemd on all of
> 
>  * user.slice,
>  * user-1000.slice,
>  * user@1000.slice,
>  * session.slice and
>  * everything inside session.slice
>    (i.e. gnome-shell-wayland.service, gsd-*.service, …)
> 
> excluding apps.slice from protection.
> 
> (In a realistic scenario I expect to have swap and then reserving maybe
> a few hundred MiB; DAMON might help with finding good values.)

What's DAMON?

> At that point, the protection started working pretty much flawlessly.
> i.e. my gnome-shell would continue to run without major page faulting
> even though everything in apps.slice was thrashing heavily. The
> mouse/keyboard remained completely responsive, and interacting with
> applications ended up working much better thanks to knowing where input
> was going. Even if the applications themselves took seconds to react.
> 
> So far, so good. What surprises me is that I needed to set the
> protection on the child cgroups (i.e. gnome-shell-wayland.service).
> Without this, it would not work (reliably) and my gnome-shell would
> still have a lot of re-faults to load libraries and other mmap'ed data
> back into memory (I used "perf --no-syscalls -F" to trace this and
> observed these to be repeatedly for the same pages loading e.g.
> functions for execution).
> 
> Due to accounting effects, I would expect re-faults to happen up to one
> time in this scenario. At that point the page in question will be
> accounted against the shell's cgroup and reclaim protection could kick
> in. Unfortunately, that did not seem to happen unless the shell's
> cgroup itself had protections and not just all of its parents.
> 
> Is it expected that I need to set limits on each child?

Yes, right now, memory.low needs to be configured all the way down to
the leaf to be effective, which can be rather cumbersome. As written
above, future kernels will be easier to work with in this respect.

Thanks.

-- 
tejun


  reply	other threads:[~2020-03-04 16:30 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-04  9:44 Benjamin Berg
2020-03-04 16:30 ` Tejun Heo [this message]
2020-03-04 17:02   ` Jonathan Corbet
2020-03-04 17:10     ` Tejun Heo
2020-03-05  1:29       ` Daniel Xu
2020-03-05 13:13   ` Benjamin Berg
2020-03-05 14:55     ` Tejun Heo
2020-03-05 15:12       ` Tejun Heo
2020-03-05 15:27       ` Benjamin Berg
2020-03-05 15:39         ` Tejun Heo

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=20200304163044.GF189690@mtj.thefacebook.com \
    --to=tj@kernel.org \
    --cc=benjamin@sipsolutions.net \
    --cc=cgroups@vger.kernel.org \
    --cc=hannes@cmpxchg.org \
    --cc=linux-mm@kvack.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