Score:2

How to configure cgroup resource limits for desktop applications using official systemd features?

cn flag

I've previously used cgmanager to group processes in separate cgroups and adjust memory and CPU limits as needed for each group. However, modern systemd doesn't want that other processes mess with cgroups so I guess I would need to configure systemd to do that instead. (To be exact, Lennart Poettering (the author of systemd) thinks this way.)

I would want to e.g. define following:

  • Specify group desktop and set minimum reserved RAM for that group to 1 GB, and automatically move my window manager (marco) and panel process (mate-panel) to it.
  • Specify group browsers and set maximum RAM for that group to 20 GB, and automatically move all Firefox, Chrome and Opera processes to that group.
  • The limits should be per user: when multiple desktop sessions are running (started via "Switch account" action without logging out previous account), each should have it's own cgroup with the limits above.

The important part is that I want those processes to get into the correct group whenever /usr/bin/marco or /opt/google/chrome/google-chrome is executed. That is, this automatic grouping should work even when wrappers such as systemd-run are not used. In short, no processes should be allowed to escape the cgroup containment.

With cgmanager this was really easy. You just created one config file and everything was set and it worked really well. However, I've been trying to look for documentation and I cannot figure out how to do the same thing with systemd alone.

cn flag
One possible solution is to ignore what Poettering is saying and just install package `cgroup-tools` and use `cgrulesengd` combined with `/etc/cgrules.conf` to accomplish the above. As this goes against the plans of Poettering, the changes are there will be some unknown side-effects in long run but if nothing better is available, I think that's better than having no solution at all.
cn flag
Did using `cgroup-tools` and `cgrulesengd` work? Am I right that `cgroup-tools` under 22.04.2 LTS has Version 1 man pages? The `cgcreate` man page is dated 2009-03-15 and talks about "all mounted controllers" as if there were multiple **cgroup** mounts, which is Version 1 language, not Version 2. Using `cgcreate cpu:foobar` creates `/sys/fs/cgroup/foobar` (under the **cgroup2** mount point) and it puts controller **cpu** in the `cgroup.subtree_control` file, so **cpu** applies to sub-cgroups, not this cgroup. Using `cgcreate '*:foobar'` idoes nothing.
cn flag
I haven't used 22.04 (I'm still running 20.04) and I guess cgroup-tools and cgrulesengd might well NOT work anymore because 22.04 is supposed to have cgroup2 implementation.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.