1
0
mirror of https://github.com/systemd/systemd synced 2026-03-27 17:24:51 +01:00

Compare commits

...

7 Commits

Author SHA1 Message Date
Luca Boccassi
54966b7cee
Merge pull request #20705 from yuwata/test-oomd-util
test: skip oomd test on a unified container on a hybrid host
2021-09-12 12:56:46 +01:00
Anita Zhang
7417f06187 test: tweak parameters for TEST-55-OOMD
Pressure remains > 1% after a kill for some time and could cause
testchill to get killed. Bumping the limit from 1% to 20% should help
with this.

Fixes #20118
2021-09-12 19:16:18 +09:00
Yu Watanabe
ca589b1b41 unit: systemd-oomd.service requires cgroup memory controller 2021-09-12 10:29:29 +09:00
Yu Watanabe
8b2e22579a test-oomd-util: skip tests if cgroup memory controller is not available
Fixes #20593 and #20655.
2021-09-12 10:29:25 +09:00
Yu Watanabe
28fb998615 oomd: refuse to start if cgroup memory controller is not available 2021-09-12 10:28:24 +09:00
Yu Watanabe
594c383554 cgroup-util: use string_hash_ops_free 2021-09-11 20:29:34 +09:00
Yu Watanabe
dccdbf9b35 cgroup-util: use _cleanup_free_ attribute 2021-09-11 20:26:58 +09:00
8 changed files with 25 additions and 18 deletions

View File

@ -2001,7 +2001,7 @@ int cg_mask_supported(CGroupMask *ret) {
}
int cg_kernel_controllers(Set **ret) {
_cleanup_set_free_free_ Set *controllers = NULL;
_cleanup_set_free_ Set *controllers = NULL;
_cleanup_fclose_ FILE *f = NULL;
int r;
@ -2011,10 +2011,6 @@ int cg_kernel_controllers(Set **ret) {
* and controllers that aren't currently accessible (because not mounted). This does not include "name="
* pseudo-controllers. */
controllers = set_new(&string_hash_ops);
if (!controllers)
return -ENOMEM;
r = fopen_unlocked("/proc/cgroups", "re", &f);
if (r == -ENOENT) {
*ret = NULL;
@ -2027,7 +2023,7 @@ int cg_kernel_controllers(Set **ret) {
(void) read_line(f, SIZE_MAX, NULL);
for (;;) {
char *controller;
_cleanup_free_ char *controller = NULL;
int enabled = 0;
errno = 0;
@ -2042,17 +2038,13 @@ int cg_kernel_controllers(Set **ret) {
return -EBADMSG;
}
if (!enabled) {
free(controller);
if (!enabled)
continue;
}
if (!cg_controller_is_valid(controller)) {
free(controller);
if (!cg_controller_is_valid(controller))
return -EBADMSG;
}
r = set_consume(controllers, controller);
r = set_ensure_consume(&controllers, &string_hash_ops_free, TAKE_PTR(controller));
if (r < 0)
return r;
}

View File

@ -406,7 +406,7 @@ static int mount_legacy_cgns_unsupported(
uid_t uid_range,
const char *selinux_apifs_context) {
_cleanup_set_free_free_ Set *controllers = NULL;
_cleanup_set_free_ Set *controllers = NULL;
const char *cgroup_root;
int r;

View File

@ -120,6 +120,7 @@ static int run(int argc, char *argv[]) {
_cleanup_(manager_freep) Manager *m = NULL;
_cleanup_free_ char *swap = NULL;
unsigned long long s = 0;
CGroupMask mask;
int r;
log_setup();
@ -153,6 +154,13 @@ static int run(int argc, char *argv[]) {
if (r == 0)
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Requires the unified cgroups hierarchy");
r = cg_mask_supported(&mask);
if (r < 0)
return log_error_errno(r, "Failed to get supported cgroup controllers: %m");
if (!FLAGS_SET(mask, CGROUP_MASK_MEMORY))
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Requires the cgroup memory controller.");
assert_se(sigprocmask_many(SIG_BLOCK, NULL, SIGTERM, SIGINT, -1) >= 0);
if (arg_mem_pressure_usec > 0 && arg_mem_pressure_usec < 1 * USEC_PER_SEC)

View File

@ -90,6 +90,7 @@ static void test_oomd_cgroup_context_acquire_and_insert(void) {
_cleanup_free_ char *cgroup = NULL;
ManagedOOMPreference root_pref;
OomdCGroupContext *c1, *c2;
CGroupMask mask;
bool test_xattrs;
int root_xattrs, r;
@ -102,6 +103,11 @@ static void test_oomd_cgroup_context_acquire_and_insert(void) {
if (cg_all_unified() <= 0)
return (void) log_tests_skipped("cgroups are not running in unified mode");
assert_se(cg_mask_supported(&mask) >= 0);
if (!FLAGS_SET(mask, CGROUP_MASK_MEMORY))
return (void) log_tests_skipped("cgroup memory controller is not available");
assert_se(cg_pid_get_path(NULL, 0, &cgroup) >= 0);
/* If we don't have permissions to set xattrs we're likely in a userns or missing capabilities

View File

@ -292,7 +292,7 @@ static int symlink_controller(const char *target, const char *alias) {
}
int mount_cgroup_controllers(void) {
_cleanup_set_free_free_ Set *controllers = NULL;
_cleanup_set_free_ Set *controllers = NULL;
int r;
if (!cg_is_legacy_wanted())

View File

@ -7,4 +7,4 @@ MemoryAccounting=true
IOAccounting=true
TasksAccounting=true
ManagedOOMMemoryPressure=kill
ManagedOOMMemoryPressureLimit=1%
ManagedOOMMemoryPressureLimit=20%

View File

@ -38,7 +38,7 @@ systemctl start testsuite-55-testbloat.service
# Verify systemd-oomd is monitoring the expected units
oomctl | grep "/testsuite-55-workload.slice"
oomctl | grep "1.00%"
oomctl | grep "20.00%"
oomctl | grep "Default Memory Pressure Duration: 2s"
systemctl status testsuite-55-testchill.service
@ -75,7 +75,7 @@ if setfattr -n user.xattr_test -v 1 /sys/fs/cgroup/; then
if ! systemctl status testsuite-55-testmunch.service; then
break
fi
sleep 5
sleep 2
done
# testmunch should be killed since testbloat had the avoid xattr on it

View File

@ -14,6 +14,7 @@ DefaultDependencies=no
Before=multi-user.target shutdown.target
Conflicts=shutdown.target
ConditionControlGroupController=v2
ConditionControlGroupController=memory
ConditionPathExists=/proc/pressure/cpu
ConditionPathExists=/proc/pressure/io
ConditionPathExists=/proc/pressure/memory