Skip to content

Conversation

@cdown
Copy link
Member

@cdown cdown commented Oct 24, 2018

systemd only uses functions that are as of Linux 4.15+ provided
externally to the CPU controller (currently usage_usec), so if we have a
new enough kernel, we don't need to set CGROUP_MASK_CPU for
CPUAccounting=true as the CPU controller does not need to necessarily be
enabled in this case.

@cdown
Copy link
Member Author

cdown commented Oct 24, 2018

(This is partially based on #9665, but the author has gone AWOL.)

@poettering
Copy link
Member

looks pretty ok.

One thing is missing though: in bus_cgroup_set_property() we should probably only request CGROUP_MASK_CPUACCT to be invalidated when bus_cgroup_set_boolean() is called when the CPUAccounting property is changed dynamically.

I'd also like to see a second commit in this PR which turns on global CPU accounting whenever need_cpu_controller_for_accounting() is false. i.e. in that case it's free, hence we should use it. THis would mean setting arg_default_cpu_accounting early on in main() somewhere. Would also need an update to the systemd-system.conf man page.

@poettering
Copy link
Member

Also, the commit msg should somehow attribute the original author of PR #9665, i.e. @ghost for this.

@poettering
Copy link
Member

The commit author of #9665 was "Ryutaroh Matsumoto".

@poettering poettering added cgroups pid1 reviewed/needs-rework 🔨 PR has been reviewed and needs another round of reworks labels Oct 24, 2018
@cdown
Copy link
Member Author

cdown commented Oct 24, 2018

The commit author of #9665 was "Ryutaroh Matsumoto".

Thanks, that helps. I'll make sure it's in the commit/PR message and look at the rest tomorrow.

@cdown
Copy link
Member Author

cdown commented Oct 25, 2018

Updated.

@cdown
Copy link
Member Author

cdown commented Oct 25, 2018

Tested live on my laptop in four configurations:

  • 4.14 LTS, hybrid
  • 4.18, hybrid
  • 4.14 LTS, all_unified
  • 4.18, all_unified

DefaultCPUAccounting value when looking at systemctl show looks correct on each

return bus_cgroup_set_boolean(u, name, &c->cpu_accounting, CGROUP_MASK_CPUACCT|CGROUP_MASK_CPU, message, flags, error);
if (streq(name, "CPUAccounting")) {
CGroupMask mask = CGROUP_MASK_CPUACCT;
if (need_cpu_controller_for_accounting())
Copy link
Member Author

@cdown cdown Oct 25, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is correct, since this might not be local, right? If this isn't correct for that reason I'll just remove it and only set CGROUP_MASK_CPUACCT I suppose, unless you have any better ideas

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use the cached version here?

Copy link
Member

@poettering poettering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some issues

return bus_cgroup_set_boolean(u, name, &c->cpu_accounting, CGROUP_MASK_CPUACCT|CGROUP_MASK_CPU, message, flags, error);
if (streq(name, "CPUAccounting")) {
CGroupMask mask = CGROUP_MASK_CPUACCT;
if (need_cpu_controller_for_accounting())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not use the cached version here?

@poettering
Copy link
Member

(and sorry for not realizing the above earlier)

@cdown
Copy link
Member Author

cdown commented Oct 26, 2018

Updated and tested the tristate does the right thing when manually set. Thanks for the suggestions! :-)

@cdown cdown force-pushed the cpu_acct branch 2 times, most recently from 7097b64 to 6ab76ab Compare October 26, 2018 15:26
}

bool cpu_accounting_is_cheap(void) {
return !(get_cpu_accounting_mask() & CGROUP_MASK_CPU);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return get_cpu_accounting_mask() == 0;

It's cheap precisely when we need no controller for it at all...

if (cgroup_context_has_cpu_weight(c) ||
cgroup_context_has_cpu_shares(c) ||
c->cpu_quota_per_sec_usec != USEC_INFINITY)
mask |= CGROUP_MASK_CPUACCT | CGROUP_MASK_CPU;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually, we might as well start being accurate here, and only set 'CGROUP_MASK_CPU` in this case...


if ((u->cgroup_realized_mask & CGROUP_MASK_CPU) == 0)
if (!cpu_accounting_is_cheap() && (u->cgroup_realized_mask & CGROUP_MASK_CPU) == 0)
return -ENODATA;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's move this check before the cg_all_unified() check above, in a generic fashion:

if (get_cpu_accounting_mask() & ~u->cgroup_realized_mask != 0) 
        return -ENODATA;

The above checks whether any of the controllers we need are among the unrealized controllers. This kind of check is pretty nice as it works for all three cases the same way.

@poettering
Copy link
Member

added some comments on the first patch. the second commit looks perfect!

@cdown
Copy link
Member Author

cdown commented Oct 26, 2018

Updated. As always, thanks for the tips :)

Copy link
Member

@poettering poettering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, the lack of emojis in that comment means it's not perfect, but I'll let it pass ;-)

excellent work, thanks!

* ║ Unified │ nothing │ CGROUP_MASK_CPU ║
* ╟───────────────┼─────────────────────┼─────────────────────╢
* ║ Hybrid/Legacy │ CGROUP_MASK_CPUACCT │ CGROUP_MASK_CPUACCT ║
* ╚═══════════════╧═════════════════════╧═════════════════════╝
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

beautiful! but why no emojis? ;-)

@poettering poettering added the good-to-merge/waiting-for-ci 👍 PR is good to merge, but CI hasn't passed at time of review. Please merge if you see CI has passed label Oct 26, 2018
@cdown cdown force-pushed the cpu_acct branch 2 times, most recently from 7f90bd4 to 729f8e2 Compare October 30, 2018 19:54
@evverx
Copy link
Contributor

evverx commented Oct 30, 2018

This pull request introduces 2 alerts when merging 729f8e2 into fee04d7 - view on LGTM.com

new alerts:

  • 2 for FIXME comment

Comment posted by LGTM.com

@martinpitt
Copy link
Contributor

@cdown: It sounds like your earlier test patch is obsolete with this?

@cdown
Copy link
Member Author

cdown commented Oct 31, 2018

This is ready for final review now. Two FIXMEs are added pending #10580 being cleaned up, but it doesn't make it worse than it is without this PR, since before we unconditionally used both cpuacct and cpu together anyway :-)

@cdown: It sounds like your earlier test patch is obsolete with this?

Yeah, no need for changes in debian downstream. We'll follow up on the JoinControllers shenanigans in #10580.

@cdown
Copy link
Member Author

cdown commented Oct 31, 2018

Just a friendly poke, this is ready for review :-)

Nothing has changed since you accepted it other than the FIXMEs being added for the JoinController bug (and thus always using both cpu and cpuacct controllers on legacy hierarchy together). CI passes.

@evverx
Copy link
Contributor

evverx commented Nov 2, 2018

This pull request introduces 2 alerts when merging b38ee91 into 3da1da8 - view on LGTM.com

new alerts:

  • 2 for FIXME comment

Comment posted by LGTM.com

@poettering
Copy link
Member

Heya, sorry for not reporting back quickly on this. We did some internal surveying inside of RH to figure out if any customers actually used the joincontroller config thingy. Turns out they do not. So I'll prepare a patch now removing the ability to configure which controllers are mounted together, and we simply hardcode that cpu + cpuacct are mounted together.

@cdown
Copy link
Member Author

cdown commented Nov 10, 2018

Thanks! Once you've done that, I'll rebase on top of it and go back to the FIXMEless version.

poettering added a commit to poettering/systemd that referenced this pull request Nov 15, 2018
This removes the ability to configure which cgroup controllers to mount
together. Instead, we'll now hardcode that "cpu" and "cpuacct" are
mounted together as well as "net_cls" and "net_prio".

The concept of mounting controllers together has no future as it does
not exist to cgroupsv2. Moreover, the current logic is systematically
broken, as revealed by the discussions in systemd#10507. Also, we surveyed Red
Hat customers and couldn't find a single user of the concept (which
isn't particularly surprising, as it is broken...)

This reduced the (already way too complex) cgroup handling for us, since
we now know whenever we make a change to a cgroup for one controller to
which other controllers it applies.
poettering added a commit to poettering/systemd that referenced this pull request Nov 15, 2018
… mask according to cpu/cpuacct joint mounting

Note that for cgroup_context_get_mask() this doesn't actually change
much, but it does prepare the ground for systemd#10507 later on.
@poettering
Copy link
Member

Heya, sorry for the delay. I have now prepared #10785 which removes the JoinControllers= setting. Would be thankful for a review, and then eventuall a rebase of your work on top of it.

@poettering
Copy link
Member

Oh, and I noticed that cgtop should probably be updated by your patch too

poettering added a commit to poettering/systemd that referenced this pull request Nov 16, 2018
This removes the ability to configure which cgroup controllers to mount
together. Instead, we'll now hardcode that "cpu" and "cpuacct" are
mounted together as well as "net_cls" and "net_prio".

The concept of mounting controllers together has no future as it does
not exist to cgroupsv2. Moreover, the current logic is systematically
broken, as revealed by the discussions in systemd#10507. Also, we surveyed Red
Hat customers and couldn't find a single user of the concept (which
isn't particularly surprising, as it is broken...)

This reduced the (already way too complex) cgroup handling for us, since
we now know whenever we make a change to a cgroup for one controller to
which other controllers it applies.
poettering added a commit to poettering/systemd that referenced this pull request Nov 16, 2018
… mask according to cpu/cpuacct joint mounting

Note that for cgroup_context_get_mask() this doesn't actually change
much, but it does prepare the ground for systemd#10507 later on.
@cdown cdown force-pushed the cpu_acct branch 2 times, most recently from 477e903 to 2c6c5a7 Compare November 17, 2018 12:13
systemd only uses functions that are as of Linux 4.15+ provided
externally to the CPU controller (currently usage_usec), so if we have a
new enough kernel, we don't need to set CGROUP_MASK_CPU for
CPUAccounting=true as the CPU controller does not need to necessarily be
enabled in this case.

Part of this patch is modelled on an earlier patch by Ryutaroh Matsumoto
(see PR systemd#9665).
If CPU accounting is cheap, no controller necessarily needs to be
enabled here for us to be able to read statistics.
We now don't enable the CPU controller just for CPU accounting if we are
on 4.15+ and using pure unified hierarchy, as this is provided
externally to the CPU controller. This makes CPUAccounting=yes
essentially free, so enabling it by default when it's cheap seems like a
good idea.
@cdown
Copy link
Member Author

cdown commented Nov 18, 2018

@poettering arm64 failure is unrelated, this is good to go.

@poettering poettering merged commit 2b38a8e into systemd:master Nov 19, 2018
@poettering
Copy link
Member

Looks excellent! Thanks!

facebook-github-bot pushed a commit to facebookarchive/rpm-backports that referenced this pull request Dec 11, 2018
Summary:
Rebase two fixes onto the version merged upstream:
systemd/systemd#10507
systemd/systemd#10567
and backport a few more:
systemd/systemd#10411
systemd/systemd#10493
systemd/systemd#10757
systemd/systemd#10876

These are almost all cgroup2 related.

Reviewed By: cdown

Differential Revision: D13351498

fbshipit-source-id: 87c8428d48dbb0eb2ae7d34f7381fff88f83872f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cgroups ci-fails/needs-rework 🔥 Please rework this, the CI noticed an issue with the PR pid1

Development

Successfully merging this pull request may close these issues.

5 participants