Commit Graph

4443 Commits

Author SHA1 Message Date
Kir Kolyshkin 4189cb65f8 cgroups: remove cgroup.Resources.CpuMax
This (and the converting function) is only used by one of the four
cgroup drivers. The other three do some checking and conversion in
place, so let the fs2 do the same.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-06-09 17:15:38 -07:00
Kir Kolyshkin 8b9646775e cgroups/systemd: unify adding CpuQuota
The code that adds CpuQuotaPerSecUSec is the same in v1 and v2
systemd cgroup driver. Move it to common.

No functional change.

Note that the comment telling that we always set this property
contradicts with the current code, and therefore it is removed.

[v2: drop cgroupv1-specific comment]
[v3: drop returning error as it's not used]
[v4: remove an obsoleted comment]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-06-09 17:14:43 -07:00
Kir Kolyshkin 2ce20ed158 cgroups/systemd: simplify gen*ResourcesProperties
Use r instead of c.Resources for readability. No functional change.

This commit has been brought to you by '<,'>s/c\.Resources\./r./g

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-06-08 13:42:09 -07:00
Ted Yu 9d275d326c Set configs back when intelrdt configs cannot be set
Signed-off-by: Ted Yu <yuzhihong@gmail.com>
2020-06-06 15:10:45 -07:00
lifubang 4be5435569 add integration test for ps/kill after the container stopped
Signed-off-by: lifubang <lifubang@acmcoder.com>
2020-06-06 08:57:10 +08:00
Aleksa Sarai 1b97c04f98
merge branch 'pr-2445'
John Hwang (1):
  Replace sed with jq for more readable json manipulation in tests

LGTMs: @kolyshkin @cyphar
Closes #2445
2020-06-06 06:13:29 +10:00
Aleksa Sarai 2a0466958d
merge branch 'pr-2446'
Kir Kolyshkin (1):
  (*initProcess).start: rm second Apply

LGTMs: @mrunalp @cyphar
Closes #2446
2020-06-05 08:30:51 +10:00
John Hwang 79fe41d3c1 Replace sed with jq for more readable json manipulation in tests
Signed-off-by: John Hwang <John.F.Hwang@gmail.com>
2020-06-03 18:35:47 -07:00
Akihiro Suda 1386570498 add cgroup v2 documentation
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-06-04 00:21:31 +09:00
Akihiro Suda 10d1e1ed06 test "update rt period and runtime": fix up runtime and period
Fix #2046

Previously, the test was failing with EINVAL during writing 500001 to `/sys/fs/cgroup/cpu,cpuacct/runc-cgroups-integration-test/test-cgroup/cpu.rt_runtime_us`, because `/sys/fs/cgroup/cpu,cpuacct/runc-cgroups-integration-test/cpu.rt_runtime_us` was initialized with 0.

The issue had not been caught in Ubuntu 18.04 CI because it doesn't support rt.

Tested on Ubuntu 20.04.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-06-03 16:59:10 +09:00
Mrunal Patel 0853956d23
Merge pull request #2452 from AkihiroSuda/silence-criu-not-found
silence "which: no criu"
2020-06-02 11:48:20 -07:00
Mrunal Patel 1302020239
Merge pull request #2449 from katarzyna-z/kk-fix-2440
Fix #2440 omit cpuacct.usage_all when not available
2020-06-02 11:05:02 -07:00
lifubang 9087f2e827 fix path error in systemd when stopped
When we use cgroup with systemd driver, the cgroup path will be auto removed
by systemd when all processes exited. So we should check cgroup path exists
when we access the cgroup path, for example in `kill/ps`, or else we will
got an error.

Signed-off-by: lifubang <lifubang@acmcoder.com>
2020-06-02 18:17:43 +08:00
Akihiro Suda 4ad326a37d silence "which: no criu"
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-06-02 18:59:19 +09:00
Katarzyna Kujawa 92f831bf0c Fix #2440 omit cpuacct.usage_all when not available
Signed-off-by: Katarzyna Kujawa <katarzyna.kujawa@intel.com>
2020-06-02 09:24:11 +02:00
Kir Kolyshkin d1ba8e39f8 (*initProcess).start: rm second Apply
Apply() determines and creates cgroup path(s), configures parent cgroups
(for some v1 controllers), and creates a systemd unit (in case of a
systemd cgroup manager), then adds a pid specified to the cgroup
for all configured controllers.

This is a relatively heavy procedure (in particular, for cgroups v1 it
involves parsing /proc/self/mountinfo about a dozen times), and it seems
there is no need to do it twice.

More to say, even merely adding the child pid to the same cgroup seems
redundant, as we added the parent pid to the cgroup before sending the
data to the child (runc init process), and it waits for the data before
doing clone(), so its children will be in the same cgroup anyway.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-06-01 19:51:19 -07:00
Mrunal Patel dbe5acade3
Merge pull request #2439 from kolyshkin/int-noswap
integration tests fixes for no swap ctrl case
2020-05-31 10:06:08 -07:00
Mrunal Patel 332a84581e
Merge pull request #2443 from kolyshkin/kmem-fixup
cgroupv1/systemd.Set: don't enable kernel memory acct
2020-05-31 10:04:45 -07:00
Mrunal Patel 0f7ffbebeb
Merge pull request #2416 from AkihiroSuda/exec-join-init-cgroup
cgroup2: exec: join the cgroup of the init process on EBUSY
2020-05-31 08:50:41 -07:00
Aleksa Sarai a30f2556d9
merge branch 'pr-2018'
Lifubang (1):
  add prompt when rootless users have no read access to runc bin

LGTMs: @AkihiroSuda @cyphar
Closes #2018
2020-05-31 18:41:37 +10:00
Akihiro Suda c91fe9aeba cgroup2: exec: join the cgroup of the init process on EBUSY
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
2020-05-31 13:09:43 +09:00
Kir Kolyshkin ed1f14afb5 tests/int/events: skip oom test if no swap
In case swap cgroup control is not available, the "event oom" test gives
the following error:

> # not ok 30 events oom
> # (in test file tests/integration/events.bats, line 134)
> #   `[ "$status" -eq 0 ]' failed
> # <....>
> # runc run -d --console-socket /tmp/console.sock test_busybox (status=1):
> # time="2020-05-29T02:10:20Z" level=warning msg="signal: killed"
> # time="2020-05-29T02:10:20Z" level=error msg="container_linux.go:353: starting container process caused: process_linux.go:437: container init caused: process_linux.go:403: setting cgroup config for procHooks process caused: failed to write \"33554432\" to \"/sys/fs/cgroup/memory/test_busybox/memory.memsw.limit_in_bytes\": open /sys/fs/cgroup/memory/test_busybox/memory.memsw.limit_in_bytes: permission denied"

When I try to run the test without setting the swap limit, the shell
process is still getting killed, but the test hangs. I am not sure what
the reason is, but realistically this test is hard to perform without
the swap limit, so let's require cgroup swap for it.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-05-30 14:48:02 -07:00
Kir Kolyshkin 755b1016ee test/int/update: simplify mem+swap presence check
For v2, mem+swap is always present. For v1, check it once and set a
variable which is used below.

This also removes CGROUP_MEMORY for v2 case since it's no longer used.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-05-30 14:47:28 -07:00
Kir Kolyshkin 8d94363343 test/int/update: simplify mem+swap checks
The "unlimited" value is the same for memory and memory+swap,
so let's use SYSTEM_MEM for both.

In fact, it was already used in one place to check swap, probably due to
a typo.

This also fixes the following failure on a cgroup v1 system without
mem+swap control (Ubuntu 19.04):

> # not ok 78 update cgroup v1/v2 common limits
> # (in test file tests/integration/update.bats, line 72)
> #   `SYSTEM_MEM_SWAP=$(cat "${CGROUP_MEMORY_BASE_PATH}/$MEM_SWAP")' failed

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-05-30 14:42:44 -07:00
Aleksa Sarai e664e732d5
merge branch 'pr-2442'
Kir Kolyshkin (1):
  Remove pullapprove integration

LGTMs: @mrunalp @AkihiroSuda @cyphar
Closes #2442
2020-05-30 21:41:53 +10:00
Mrunal Patel 2679754a5d
Merge pull request #2441 from kolyshkin/check-cpushares
cgroupv1: check cpu shares in place
2020-05-29 21:42:53 -07:00
Kir Kolyshkin 3fe6e04510 cgroupv1/systemd.Set: don't enable kernel memory acct
This is a regression from commit 1d4ccc8e0. We only need to enable
kernel memory accounting once, from the (*legacyManager*).Apply(),
and there is no need to do it in (*legacyManager*).Set().

While at it, rename the method to better reflect what it's doing.

This saves 1 call to mountinfo parser.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-05-29 17:54:50 -07:00
Kir Kolyshkin 3249e2379c cgroupv1: check cpu shares in place
Commit 4e65e0e90a added a check for cpu shares. Apparently, the
kernel allows to set a value higher than max or lower than min without
an error, but the value read back is always within the limits.

The check (which was later moved out to a separate CheckCpushares()
function) is always performed after setting the cpu shares, so let's
move it to the very place where it is set.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-05-29 16:46:28 -07:00
Kir Kolyshkin 774a9e7641
Merge pull request #2420 from tedyu/criu-proc-wait
Wait for criuProcess once

LGTMs: @avagin @mrunalp @kolyshkin
2020-05-29 16:43:14 -07:00
Ted Yu 3ba3d9b1bd Wait for criuProcess once
Signed-off-by: Ted Yu <yuzhihong@gmail.com>
2020-05-29 15:50:37 -07:00
Kir Kolyshkin 0f3d6bec7a Remove pullapprove integration
Fixes #2388

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-05-29 15:09:28 -07:00
Akihiro Suda 64dbdb8645
Merge pull request #2437 from kolyshkin/remove-faster
cgroups/fs2: make removeCgroupPath faster
2020-05-29 14:11:37 +09:00
Kir Kolyshkin a78e21b500 tests/int/delete.bats: fixups
1. __runc does not set $status, so the check is misleading.

2. Add set +eux to the nest.sh script so we can error out early, and see
   what is going on.

3. Doing "echo +io" > cgroup.controllers is giving an error on my
   machine ("sh: write error: Operation not supported"). It is probably
   fine to just enable pids controller.

4. Add status check for runc exec nest.sh

5. Remove the second check for cgroup.threads contents -- it was already
   checked earlier (the output of nest.sh script).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-05-28 11:48:16 -07:00
Kir Kolyshkin 0ac92aab3f cgroups/fs2: make removeCgroupPath faster
1. In cases there are no sub-cgroups, a single rmdir should be faster
than iterating through the list of files.

2. Use unix.Rmdir() to save one more syscall since os.Remove() tries
unlink(2) first which fails on a directory, and only then tries
rmdir(2).

3. Re-use rmdir.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-05-28 11:15:31 -07:00
Mrunal Patel 4f0bdafc8a
Merge pull request #2412 from lifubang/removecgpath
remove cgroup path recursively in cgroup v2
2020-05-27 15:50:14 -07:00
Akihiro Suda a891fee8c6
Merge pull request #2434 from kolyshkin/cpu-quota-fix-minimal
cgroupv1: minimal fix for cpu quota regression
2020-05-27 10:08:17 +09:00
Kir Kolyshkin be5467872d cgroupv1: minimal fix for cpu quota regression
This is a quick-n-dirty fix the regression introduced by commit
06d7c1d, which made it impossible to only set CpuQuota
(without the CpuPeriod). It partially reverts the above commit,
and adds a test case.

The proper fix will follow.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-05-26 11:02:16 -07:00
lifubang 82fa194179 remove cgroup path recursively in cgroup v2
Signed-off-by: lifubang <lifubang@acmcoder.com>
2020-05-26 23:35:20 +08:00
Akihiro Suda 1f737eebaa
Merge pull request #2426 from kolyshkin/mem-swap-unlim
Fix some cases of swap setting
2020-05-26 14:48:59 +09:00
Akihiro Suda 7673bee6bf
Merge pull request #2395 from lifubang/updateCgroupv2
Partially revert "CreateCgroupPath: only enable needed controllers"
2020-05-25 13:56:23 +09:00
Kir Kolyshkin 68391c0e96 use lazy-pages ready notification for criu >= 3.15
This relies on https://github.com/checkpoint-restore/criu/pull/1069
and emulates the previous behavior by writing \0 and closing status
fd (as it was done by criu).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-05-23 11:37:28 -07:00
Kir Kolyshkin 7ab1329835 libct/criuNotifications: simplify switch
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-05-23 11:37:28 -07:00
Kir Kolyshkin 3c6e8ac4d2 cgroupv2: set mem+swap to max if mem set to max
... and mem+swap is not explicitly set otherwise.

This ensures compatibility with cgroupv1 controller which interprets
things this way.

With this fixed, we can finally enable swap tests for cgroupv2.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-05-22 21:32:16 -07:00
lifubang 275157193c add testcase for enable all supported controllers in cgroupv2
Signed-off-by: lifubang <lifubang@acmcoder.com>
2020-05-21 12:17:54 +08:00
lifubang a67dab0ac2 Revert "CreateCgroupPath: only enable needed controllers"
1. Partially revert "CreateCgroupPath: only enable needed controllers"
If we update a resource which did not limited in the beginning,
it will have no effective.
2. Returns err if we use an non enabled controller,
or else the user may feel success, but actually there are no effective.

Signed-off-by: lifubang <lifubang@acmcoder.com>
2020-05-21 12:17:46 +08:00
Mrunal Patel 3c8da9dae0
Merge pull request #2422 from kolyshkin/criu-j
Dockerfile: speed up criu build
2020-05-20 17:43:43 -07:00
Kir Kolyshkin d57f5bb286 cgroupv1: don't ignore MemorySwap if Memory==-1
Commit 18ebc51b3cc3 "Reset Swap when memory is set to unlimited (-1)"
added handling of the case when a user updates the container limits
to set memory to unlimited (-1) but do not set any other limits.
Apparently, in this case, if swap limit was previously set, kernel fails
to set memory.limit_in_bytes to -1 if memory.memsw.limit_in_bytes is
not set to -1.

What the above commit fails to handle correctly is the request when
Memory is set to -1 and MemorySwap is set to some specific limit N
(where N > 0). In this case, the value of N is silently discarded
and MemorySwap is set to -1 instead.

This is wrong thing to do, as the limit set, even if incorrectly,
should not be ignored.

Fix this by only assigning MemorySwap == -1 in case it was not
explicitly set.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-05-20 17:23:40 -07:00
Aleksa Sarai 21cb2360b6
merge branch 'pr-2427'
Akihiro Suda (1):
  README.md: fix a dead link

LGTMs: @kolyshkin @cyphar
Closes #2427
2020-05-21 10:06:32 +10:00
Mrunal Patel 6a6ba0c036
Merge pull request #2423 from kolyshkin/systemd-v2-pids-max
Fix setting some systemd limits, add more tests
2020-05-20 16:33:46 -07:00
Akihiro Suda 8cd84e35f8
Merge pull request #2333 from opencontainers/add-cii-badge
Add CII Badge to README
2020-05-21 07:45:35 +09:00