Commit Graph

4399 Commits

Author SHA1 Message Date
Katarzyna Kujawa 71e63de4a3 Fix #2469 omit memory.numa_stat when not available
Signed-off-by: Katarzyna Kujawa <katarzyna.kujawa@intel.com>
2020-06-15 11:39:34 +02:00
Akihiro Suda fdc48376d1
Merge pull request #2458 from kolyshkin/cpu-quota-II
Cpu quota fixes, try II
2020-06-12 07:46:56 +09:00
Kir Kolyshkin 3ddb913a8b
Merge pull request #2467 from mrunalp/save_state_atomic
Write state.json atomically
2020-06-11 15:07:40 -07:00
Mrunal Patel ed9d93e290
Merge pull request #2455 from AkihiroSuda/docs-cgroup2
add cgroup v2 documentation
2020-06-11 12:32:20 -07:00
Mrunal Patel a4a306d2a2 Write state.json atomically
We want to make sure that the state file is syned and cannot be
read partially or truncated.

Signed-off-by: Mrunal Patel <mrunalp@gmail.com>
2020-06-10 20:21:04 -07:00
Mrunal Patel b2163040db
Merge pull request #2454 from AkihiroSuda/ci-fix-rt
test "update rt period and runtime": fix up runtime and period
2020-06-09 21:17:37 -07:00
Kir Kolyshkin 1b03e72554 tests/int/update: more cpu period/quota cases
Add four "corner case" tests that check that the CPU period/quota
can be set/updated even in case neither CPU quota nor CPU period
(were previously) set.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-06-09 17:38:24 -07:00
Kir Kolyshkin a92b0327ce cgroups/systemd: fix set CPU quota if period is unset
systemd drivers ignore --cpu-quota during update if the CPU
period was not set earlier.

Fixed by adding the default for the period.

The test will be added by the following commit.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-06-09 17:32:17 -07:00
Kir Kolyshkin 1832bf0b88 tests/int/update: add cpu-quota -1 tests
Check that resetting cpu quota works.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-06-09 17:17:13 -07:00
Kir Kolyshkin 7c2b23497e tests/integration/update: enable cpu quota for v2
Also, enable tests of setting quota and period separately in case
systemd cgroup driver is used, as commit 32746fb334
("update: do not overwrite old cpu quota/period") made it possible
to do so.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-06-09 17:16:47 -07:00
Kir Kolyshkin 32746fb334 update: do not overwrite old cpu quota/period
Seting CPU quota and period independently does not make much sense,
but historically runc allowed it and this needs to be supported
to not break compatibility.

For systemd cgroup drivers to set CPU quota/period correctly,
it needs to know both values. For fs2 cgroup driver to be compatible
with the fs driver, it also needs to know both values.

Here in update, previously set values are available from config.
If only one of {quota,period} is set and the other is not, leave
the unset parameter at the old value (don't overwrite config).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2020-06-09 17:15:56 -07:00
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
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
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 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