runc icon indicating copy to clipboard operation
runc copied to clipboard

cgroups: Add support for `cgroup.kill` added in Linux Kernel 5.14

Open flouthoc opened this issue 3 years ago • 18 comments

Following PR adds support for cgroup.kill to kill all the processes in a cgroup instead of iterating over each process to save cost if possible.

Linux kernel 5.14 adds support for cgroup.kill.

Ref

  • https://lwn.net/Articles/855049/
  • https://lwn.net/Articles/855924/

flouthoc avatar Sep 05 '21 08:09 flouthoc

@giuseppe @AkihiroSuda @kolyshkin PTAL

flouthoc avatar Sep 05 '21 08:09 flouthoc

PS: this is already added in crun by @giuseppe via https://github.com/containers/crun/pull/724

flouthoc avatar Sep 05 '21 08:09 flouthoc

This would fix https://github.com/opencontainers/runc/issues/3135

kolyshkin avatar Sep 06 '21 19:09 kolyshkin

@cyphar @AkihiroSuda @kolyshkin Addressed all the feedback points in latest commit. Could you please take a look again.

flouthoc avatar Sep 07 '21 09:09 flouthoc

@flouthoc on what distro are you testing this? Problem is, we don't have 5.14+ kernel in CI yet.

kolyshkin avatar Sep 08 '21 03:09 kolyshkin

@kolyshkin I am using ubuntu 21.04 but 5.14 is not shipped by default but its available on kernel.ubuntu.com mainline.

flouthoc avatar Sep 08 '21 05:09 flouthoc

I have booted 5.14 myself and, as I was suspecting, the feature is only available for cgroup v2 (or when using v1 + hybrid hierarchy).

So, it does not make sense to add to v1 managers (unless they gain hybrid support), and the code you're using to get paths to cgroup.kill in v1 managers is probably not working.

Given the fact that this is not ready, and we don't have kernel 5.14 in CI, I think we have to postpone it to 1.2.0.

kolyshkin avatar Sep 09 '21 00:09 kolyshkin

@kolyshkin fair points i think we can hold on to this till kernel 5.14 and I'll confirm if this works for v1 at all , if not i will remove the case for v1. Will add a .bats test for v2 does that sounds good ?

flouthoc avatar Sep 09 '21 04:09 flouthoc

and I'll confirm if this works for v1 at all , if not i will remove the case for v1.

There's no cgroup.kill for v1, but it is there in case hybrid hierarchy is used. Support for hybrid hierarchy is added by various PRs. In this particular case, we need https://github.com/opencontainers/runc/pull/2087, and once it's in, we can use Path("") to get path to the hybrid hierarchy, if available.

kolyshkin avatar Sep 13 '21 20:09 kolyshkin

@kolyshkin Sure makes sense lets wait for hybrid hierarchy.

flouthoc avatar Sep 14 '21 04:09 flouthoc

Marked as draft as we need

  • #2087 (or #3059 which carries it) for v1 + hybrid unified path support;
  • kernel 5.14 in CI;

Problem is, #3059 needs criu 3.16 which is not yet released.

kolyshkin avatar Sep 15 '21 22:09 kolyshkin

@kolyshkin @cyphar Just curious how would m.paths[""] would look like for hybrid+v1 could you please state with an example. I'll try setting up a hybrid+v1 in spare time for myself to work on this till other PR gets merged.

flouthoc avatar Sep 21 '21 16:09 flouthoc

Just want to do this testing myself here cause i think it will take some time to get new kernel in CI meanwhile i can just do testing on my own and we can keep PR on hold.

flouthoc avatar Sep 21 '21 16:09 flouthoc

Nvm i'll wait for dependent PRs then will pick this up again. I think would be hard to plumb things temporarily into code.

flouthoc avatar Sep 21 '21 17:09 flouthoc

Just putting mock code so its easier to revisit, please don't review yet.

flouthoc avatar Sep 21 '21 17:09 flouthoc

@flouthoc can you revisit this? I almost ended up rewriting this from scratch (which would be a colossal waste of time).

kolyshkin avatar May 31 '22 23:05 kolyshkin

@kolyshkin Sure I'll revisit this. Thanks for the reminder.

flouthoc avatar Jun 01 '22 03:06 flouthoc

I completely forgot about this patch. Ping me to review it when you're done rebasing. :D

cyphar avatar Jun 01 '22 03:06 cyphar

@flouthoc can you take a look and refresh this PR? This would be nice to have in 1.2.0

kolyshkin avatar Dec 01 '22 18:12 kolyshkin

I am working on an alternative, implemented without adding a new public method to cgroup managers, and modelled after cgroup.kill kernel tests. Still a WIP.

kolyshkin avatar Apr 13 '23 01:04 kolyshkin

@kolyshkin Thanks a lot for taking this over, i am closing this one.

flouthoc avatar Apr 13 '23 03:04 flouthoc