加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
core-cgroup-support-cpuset.patch 50.04 KB
一键复制 编辑 原始数据 按行查看 历史
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990
From 2ea8175b3d8ec118fa0f42392485ce0f4308456a Mon Sep 17 00:00:00 2001
From: licunlong <licunlong1@huawei.com>
Date: Thu, 6 May 2021 09:38:54 +0800
Subject: [PATCH] core-cgroup: support cpuset
This patch add support for cpuset subsystem.
---
meson.build | 2 +
meson_options.txt | 3 +
src/basic/cgroup-util.c | 3 +-
src/basic/cgroup-util.h | 14 ++-
src/basic/string-util.c | 42 +++++++
src/basic/string-util.h | 1 +
src/core/cgroup.c | 112 ++++++++++++++----
src/core/cgroup.h | 14 ++-
src/core/dbus-cgroup.c | 60 ++++++++--
src/core/dbus-manager.c | 1 +
src/core/execute-serialize.c | 44 +++----
src/core/load-fragment-gperf.gperf.in | 13 +-
src/core/load-fragment.c | 69 +++++++++++
src/core/load-fragment.h | 1 +
src/core/main.c | 1 +
src/core/manager.c | 2 +
src/core/manager.h | 1 +
src/core/system.conf.in | 1 +
src/core/unit.c | 1 +
src/shared/bus-unit-util.c | 15 ++-
src/shared/cpu-set-util.c | 1 +
src/test/test-cgroup-mask.c | 5 +-
.../fuzz-unit-file/directives-all.service | 5 +
23 files changed, 338 insertions(+), 73 deletions(-)
diff --git a/meson.build b/meson.build
index 7419e2b..614013b 100644
--- a/meson.build
+++ b/meson.build
@@ -1578,6 +1578,7 @@ foreach term : ['analyze',
'binfmt',
'compat-mutable-uid-boundaries',
'coredump',
+ 'cpuset-cgv1',
'efi',
'environment-d',
'firstboot',
@@ -2853,6 +2854,7 @@ foreach tuple : [
['fexecve'],
['standalone-binaries', get_option('standalone-binaries')],
['coverage', get_option('b_coverage')],
+ ['cpuset-cgv1'],
]
if tuple.length() >= 2
diff --git a/meson_options.txt b/meson_options.txt
index e708745..5fda5d9 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -514,3 +514,6 @@ option('bpf-compiler', type : 'combo', choices : ['clang', 'gcc'],
description: 'compiler used to build BPF programs')
option('bpf-framework', type : 'feature', deprecated : { 'true' : 'enabled', 'false' : 'disabled' },
description: 'build BPF programs from source code in restricted C')
+
+option('cpuset-cgv1', type : 'boolean', value : 'true',
+ description : 'enable cgroup v1 cpuset support')
diff --git a/src/basic/cgroup-util.c b/src/basic/cgroup-util.c
index 18b16ec..abd1f91 100644
--- a/src/basic/cgroup-util.c
+++ b/src/basic/cgroup-util.c
@@ -2352,12 +2352,13 @@ bool fd_is_cgroup_fs(int fd) {
static const char *const cgroup_controller_table[_CGROUP_CONTROLLER_MAX] = {
[CGROUP_CONTROLLER_CPU] = "cpu",
[CGROUP_CONTROLLER_CPUACCT] = "cpuacct",
- [CGROUP_CONTROLLER_CPUSET] = "cpuset",
+ [CGROUP_CONTROLLER_CPUSET2] = "cpuset2",
[CGROUP_CONTROLLER_IO] = "io",
[CGROUP_CONTROLLER_BLKIO] = "blkio",
[CGROUP_CONTROLLER_MEMORY] = "memory",
[CGROUP_CONTROLLER_DEVICES] = "devices",
[CGROUP_CONTROLLER_PIDS] = "pids",
+ [CGROUP_CONTROLLER_CPUSET] = "cpuset",
[CGROUP_CONTROLLER_BPF_FIREWALL] = "bpf-firewall",
[CGROUP_CONTROLLER_BPF_DEVICES] = "bpf-devices",
[CGROUP_CONTROLLER_BPF_FOREIGN] = "bpf-foreign",
diff --git a/src/basic/cgroup-util.h b/src/basic/cgroup-util.h
index 6ab14c7..dd3df28 100644
--- a/src/basic/cgroup-util.h
+++ b/src/basic/cgroup-util.h
@@ -22,12 +22,13 @@ typedef enum CGroupController {
/* Original cgroup controllers */
CGROUP_CONTROLLER_CPU,
CGROUP_CONTROLLER_CPUACCT, /* v1 only */
- CGROUP_CONTROLLER_CPUSET, /* v2 only */
+ CGROUP_CONTROLLER_CPUSET2, /* v2 only */
CGROUP_CONTROLLER_IO, /* v2 only */
CGROUP_CONTROLLER_BLKIO, /* v1 only */
CGROUP_CONTROLLER_MEMORY,
CGROUP_CONTROLLER_DEVICES, /* v1 only */
CGROUP_CONTROLLER_PIDS,
+ CGROUP_CONTROLLER_CPUSET,
/* BPF-based pseudo-controllers, v2 only */
CGROUP_CONTROLLER_BPF_FIREWALL,
@@ -49,12 +50,13 @@ typedef enum CGroupController {
typedef enum CGroupMask {
CGROUP_MASK_CPU = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_CPU),
CGROUP_MASK_CPUACCT = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_CPUACCT),
- CGROUP_MASK_CPUSET = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_CPUSET),
+ CGROUP_MASK_CPUSET2 = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_CPUSET2),
CGROUP_MASK_IO = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_IO),
CGROUP_MASK_BLKIO = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_BLKIO),
CGROUP_MASK_MEMORY = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_MEMORY),
CGROUP_MASK_DEVICES = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_DEVICES),
CGROUP_MASK_PIDS = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_PIDS),
+ CGROUP_MASK_CPUSET = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_CPUSET),
CGROUP_MASK_BPF_FIREWALL = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_BPF_FIREWALL),
CGROUP_MASK_BPF_DEVICES = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_BPF_DEVICES),
CGROUP_MASK_BPF_FOREIGN = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_BPF_FOREIGN),
@@ -62,10 +64,14 @@ typedef enum CGroupMask {
CGROUP_MASK_BPF_RESTRICT_NETWORK_INTERFACES = CGROUP_CONTROLLER_TO_MASK(CGROUP_CONTROLLER_BPF_RESTRICT_NETWORK_INTERFACES),
/* All real cgroup v1 controllers */
- CGROUP_MASK_V1 = CGROUP_MASK_CPU|CGROUP_MASK_CPUACCT|CGROUP_MASK_BLKIO|CGROUP_MASK_MEMORY|CGROUP_MASK_DEVICES|CGROUP_MASK_PIDS,
+ CGROUP_MASK_V1 = CGROUP_MASK_CPU|CGROUP_MASK_CPUACCT|CGROUP_MASK_BLKIO|CGROUP_MASK_MEMORY|CGROUP_MASK_DEVICES|CGROUP_MASK_PIDS
+#if ENABLE_CPUSET_CGV1
+ | CGROUP_MASK_CPUSET
+#endif
+ ,
/* All real cgroup v2 controllers */
- CGROUP_MASK_V2 = CGROUP_MASK_CPU|CGROUP_MASK_CPUSET|CGROUP_MASK_IO|CGROUP_MASK_MEMORY|CGROUP_MASK_PIDS,
+ CGROUP_MASK_V2 = CGROUP_MASK_CPU|CGROUP_MASK_CPUSET2|CGROUP_MASK_IO|CGROUP_MASK_MEMORY|CGROUP_MASK_PIDS,
/* All cgroup v2 BPF pseudo-controllers */
CGROUP_MASK_BPF = CGROUP_MASK_BPF_FIREWALL|CGROUP_MASK_BPF_DEVICES|CGROUP_MASK_BPF_FOREIGN|CGROUP_MASK_BPF_SOCKET_BIND|CGROUP_MASK_BPF_RESTRICT_NETWORK_INTERFACES,
diff --git a/src/basic/string-util.c b/src/basic/string-util.c
index 7329bfa..0fecb40 100644
--- a/src/basic/string-util.c
+++ b/src/basic/string-util.c
@@ -1295,6 +1295,48 @@ int string_contains_word_strv(const char *string, const char *separators, char *
return !!found;
}
+int string_isvalid_interval(const char *instr)
+{
+ const char *pstr = instr; /* tmp */
+ const char *pstr_front = instr; /* front char */
+ const char *pstr_behind = instr; /* behind char */
+
+ if (isempty(instr))
+ {
+ return 1;
+ }
+
+ while (*pstr != '\0')
+ {
+ /* behind */
+ pstr_behind = pstr + 1;
+
+ /* 0-3,4,6,7-10 */
+ if (((*pstr < '0') || (*pstr > '9')) &&
+ (*pstr != '-') &&
+ (*pstr != ','))
+ {
+ return 2;
+ }
+
+ /* - , must is a num */
+ if (('-' == *pstr) || (',' == *pstr))
+ {
+ if ((*pstr_front < '0') || (*pstr_front > '9') ||
+ (*pstr_behind < '0') || (*pstr_behind > '9'))
+ {
+ return 3;
+ }
+ }
+
+ /* front */
+ pstr_front = pstr;
+ pstr++;
+ }
+
+ return 0;
+}
+
bool streq_skip_trailing_chars(const char *s1, const char *s2, const char *ok) {
if (!s1 && !s2)
return true;
diff --git a/src/basic/string-util.h b/src/basic/string-util.h
index b6d8be3..c6773d3 100644
--- a/src/basic/string-util.h
+++ b/src/basic/string-util.h
@@ -270,6 +270,7 @@ static inline int string_contains_word(const char *string, const char *separator
return string_contains_word_strv(string, separators, STRV_MAKE(word), NULL);
}
+int string_isvalid_interval(const char *instr);
bool streq_skip_trailing_chars(const char *s1, const char *s2, const char *ok);
char *string_replace_char(char *str, char old_char, char new_char);
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index 78bc551..cd1e97d 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -91,8 +91,8 @@ bool unit_has_startup_cgroup_constraints(Unit *u) {
return c->startup_cpu_shares != CGROUP_CPU_SHARES_INVALID ||
c->startup_io_weight != CGROUP_WEIGHT_INVALID ||
c->startup_blockio_weight != CGROUP_BLKIO_WEIGHT_INVALID ||
- c->startup_cpuset_cpus.set ||
- c->startup_cpuset_mems.set ||
+ c->startup_cpuset_cpus2.set ||
+ c->startup_cpuset_mems2.set ||
c->startup_memory_high_set ||
c->startup_memory_max_set ||
c->startup_memory_swap_max_set||
@@ -293,10 +293,16 @@ void cgroup_context_done(CGroupContext *c) {
c->restrict_network_interfaces = set_free_free(c->restrict_network_interfaces);
- cpu_set_reset(&c->cpuset_cpus);
- cpu_set_reset(&c->startup_cpuset_cpus);
- cpu_set_reset(&c->cpuset_mems);
- cpu_set_reset(&c->startup_cpuset_mems);
+ if (c->cpuset_cpus)
+ c->cpuset_cpus = mfree(c->cpuset_cpus);
+
+ if (c->cpuset_mems)
+ c->cpuset_mems = mfree(c->cpuset_mems);
+
+ cpu_set_reset(&c->cpuset_cpus2);
+ cpu_set_reset(&c->startup_cpuset_cpus2);
+ cpu_set_reset(&c->cpuset_mems2);
+ cpu_set_reset(&c->startup_cpuset_mems2);
c->delegate_subgroup = mfree(c->delegate_subgroup);
@@ -496,7 +502,7 @@ CGroupDevicePermissions cgroup_device_permissions_from_string(const char *s) {
}
void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
- _cleanup_free_ char *disable_controllers_str = NULL, *delegate_controllers_str = NULL, *cpuset_cpus = NULL, *cpuset_mems = NULL, *startup_cpuset_cpus = NULL, *startup_cpuset_mems = NULL;
+ _cleanup_free_ char *disable_controllers_str = NULL, *delegate_controllers_str = NULL, *cpuset_cpus2 = NULL, *cpuset_mems2 = NULL, *startup_cpuset_cpus2 = NULL, *startup_cpuset_mems2 = NULL;
CGroupContext *c;
struct in_addr_prefix *iaai;
@@ -525,16 +531,17 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
/* "Delegate=" means "yes, but no controllers". Show this as "(none)". */
const char *delegate_str = delegate_controllers_str ?: c->delegate ? "(none)" : "no";
- cpuset_cpus = cpu_set_to_range_string(&c->cpuset_cpus);
- startup_cpuset_cpus = cpu_set_to_range_string(&c->startup_cpuset_cpus);
- cpuset_mems = cpu_set_to_range_string(&c->cpuset_mems);
- startup_cpuset_mems = cpu_set_to_range_string(&c->startup_cpuset_mems);
+ cpuset_cpus2 = cpu_set_to_range_string(&c->cpuset_cpus2);
+ startup_cpuset_cpus2 = cpu_set_to_range_string(&c->startup_cpuset_cpus2);
+ cpuset_mems2 = cpu_set_to_range_string(&c->cpuset_mems2);
+ startup_cpuset_mems2 = cpu_set_to_range_string(&c->startup_cpuset_mems2);
fprintf(f,
"%sCPUAccounting: %s\n"
"%sIOAccounting: %s\n"
"%sBlockIOAccounting: %s\n"
"%sMemoryAccounting: %s\n"
+ "%sCPUSetAccounting: %s\n"
"%sTasksAccounting: %s\n"
"%sIPAccounting: %s\n"
"%sCPUWeight: %" PRIu64 "\n"
@@ -565,6 +572,10 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
"%sMemoryZSwapMax: %" PRIu64 "%s\n"
"%sStartupMemoryZSwapMax: %" PRIu64 "%s\n"
"%sMemoryLimit: %" PRIu64 "\n"
+ "%sCPUSetCpus=%s\n"
+ "%sCPUSetMems=%s\n"
+ "%sCPUSetCloneChildren=%s\n"
+ "%sCPUSetMemMigrate=%s\n"
"%sTasksMax: %" PRIu64 "\n"
"%sDevicePolicy: %s\n"
"%sDisableControllers: %s\n"
@@ -579,6 +590,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
prefix, yes_no(c->io_accounting),
prefix, yes_no(c->blockio_accounting),
prefix, yes_no(c->memory_accounting),
+ prefix, yes_no(c->cpuset_accounting),
prefix, yes_no(c->tasks_accounting),
prefix, yes_no(c->ip_accounting),
prefix, c->cpu_weight,
@@ -587,10 +599,10 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
prefix, c->startup_cpu_shares,
prefix, FORMAT_TIMESPAN(c->cpu_quota_per_sec_usec, 1),
prefix, FORMAT_TIMESPAN(c->cpu_quota_period_usec, 1),
- prefix, strempty(cpuset_cpus),
- prefix, strempty(startup_cpuset_cpus),
- prefix, strempty(cpuset_mems),
- prefix, strempty(startup_cpuset_mems),
+ prefix, strempty(cpuset_cpus2),
+ prefix, strempty(startup_cpuset_cpus2),
+ prefix, strempty(cpuset_mems2),
+ prefix, strempty(startup_cpuset_mems2),
prefix, c->io_weight,
prefix, c->startup_io_weight,
prefix, c->blockio_weight,
@@ -609,6 +621,10 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
prefix, c->memory_zswap_max, format_cgroup_memory_limit_comparison(cdj, sizeof(cdj), u, "MemoryZSwapMax"),
prefix, c->startup_memory_zswap_max, format_cgroup_memory_limit_comparison(cdk, sizeof(cdk), u, "StartupMemoryZSwapMax"),
prefix, c->memory_limit,
+ prefix, c->cpuset_cpus,
+ prefix, c->cpuset_mems,
+ prefix, yes_no(c->cpuset_clone_children),
+ prefix, yes_no(c->cpuset_memory_migrate),
prefix, cgroup_tasks_max_resolve(&c->tasks_max),
prefix, cgroup_device_policy_to_string(c->device_policy),
prefix, strempty(disable_controllers_str),
@@ -1113,11 +1129,11 @@ static bool cgroup_context_has_cpu_shares(CGroupContext *c) {
}
static bool cgroup_context_has_allowed_cpus(CGroupContext *c) {
- return c->cpuset_cpus.set || c->startup_cpuset_cpus.set;
+ return c->cpuset_cpus2.set || c->startup_cpuset_cpus2.set;
}
static bool cgroup_context_has_allowed_mems(CGroupContext *c) {
- return c->cpuset_mems.set || c->startup_cpuset_mems.set;
+ return c->cpuset_mems2.set || c->startup_cpuset_mems2.set;
}
uint64_t cgroup_context_cpu_weight(CGroupContext *c, ManagerState state) {
@@ -1144,18 +1160,18 @@ static uint64_t cgroup_context_cpu_shares(CGroupContext *c, ManagerState state)
static CPUSet *cgroup_context_allowed_cpus(CGroupContext *c, ManagerState state) {
if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING) &&
- c->startup_cpuset_cpus.set)
- return &c->startup_cpuset_cpus;
+ c->startup_cpuset_cpus2.set)
+ return &c->startup_cpuset_cpus2;
else
- return &c->cpuset_cpus;
+ return &c->cpuset_cpus2;
}
static CPUSet *cgroup_context_allowed_mems(CGroupContext *c, ManagerState state) {
if (IN_SET(state, MANAGER_STARTING, MANAGER_INITIALIZING, MANAGER_STOPPING) &&
- c->startup_cpuset_mems.set)
- return &c->startup_cpuset_mems;
+ c->startup_cpuset_mems2.set)
+ return &c->startup_cpuset_mems2;
else
- return &c->cpuset_mems;
+ return &c->cpuset_mems2;
}
usec_t cgroup_cpu_adjust_period(usec_t period, usec_t quota, usec_t resolution, usec_t max_period) {
@@ -1727,7 +1743,7 @@ static void cgroup_context_apply(
}
}
- if ((apply_mask & CGROUP_MASK_CPUSET) && !is_local_root) {
+ if ((apply_mask & CGROUP_MASK_CPUSET2) && !is_local_root) {
cgroup_apply_unified_cpuset(u, cgroup_context_allowed_cpus(c, state), "cpuset.cpus");
cgroup_apply_unified_cpuset(u, cgroup_context_allowed_mems(c, state), "cpuset.mems");
}
@@ -1902,6 +1918,45 @@ static void cgroup_context_apply(
}
}
+ if ((apply_mask & CGROUP_MASK_CPUSET) && !is_local_root) {
+ (void) set_attribute_and_warn(u, "cpuset", "cgroup.clone_children", one_zero(c->cpuset_clone_children));
+ (void) set_attribute_and_warn(u, "cpuset", "cpuset.memory_migrate", one_zero(c->cpuset_memory_migrate));
+ if (c->cpuset_cpus) {
+ if (streq(c->cpuset_cpus, "all")) {
+ _cleanup_free_ char *str_cpuset_cpus = NULL;
+ _cleanup_free_ char *cg_root_path_cpus = NULL;
+ r = cg_get_root_path(&cg_root_path_cpus);
+ if (r < 0)
+ log_info_errno(r, "Failed to determine root cgroup, ignoring cgroup cpuset cpus: %m");
+ if (cg_root_path_cpus) {
+ r = cg_get_attribute("cpuset", cg_root_path_cpus, "cpuset.cpus", &str_cpuset_cpus);
+ if (r < 0)
+ log_error("cgroup context apply: cg get attribute is error(%d), path=%s.", r, cg_root_path_cpus);
+ if (str_cpuset_cpus)
+ (void) set_attribute_and_warn(u, "cpuset", "cpuset.cpus", str_cpuset_cpus);
+ }
+ } else
+ (void) set_attribute_and_warn(u, "cpuset", "cpuset.cpus", c->cpuset_cpus);
+ }
+ if (c->cpuset_mems) {
+ if (streq(c->cpuset_mems, "all")) {
+ _cleanup_free_ char *str_cpuset_mems = NULL;
+ _cleanup_free_ char *cg_root_path_mems = NULL;
+ r = cg_get_root_path(&cg_root_path_mems);
+ if (r < 0)
+ log_info_errno(r, "Failed to determine root cgroup, ignoring cgroup cpuset mems: %m");
+ if (cg_root_path_mems) {
+ r = cg_get_attribute("cpuset", cg_root_path_mems, "cpuset.mems", &str_cpuset_mems);
+ if (r < 0)
+ log_error("cgroup context apply: cg get attribute is error(%d), path=%s.", r, cg_root_path_mems);
+ if (str_cpuset_mems)
+ (void) set_attribute_and_warn(u, "cpuset", "cpuset.mems", str_cpuset_mems);
+ }
+ } else
+ (void) set_attribute_and_warn(u, "cpuset", "cpuset.mems", c->cpuset_mems);
+ }
+ }
+
/* On cgroup v2 we can apply BPF everywhere. On cgroup v1 we apply it everywhere except for the root of
* containers, where we leave this to the manager */
if ((apply_mask & (CGROUP_MASK_DEVICES | CGROUP_MASK_BPF_DEVICES)) &&
@@ -2045,7 +2100,7 @@ static CGroupMask unit_get_cgroup_mask(Unit *u) {
mask |= CGROUP_MASK_CPU;
if (cgroup_context_has_allowed_cpus(c) || cgroup_context_has_allowed_mems(c))
- mask |= CGROUP_MASK_CPUSET;
+ mask |= CGROUP_MASK_CPUSET2;
if (cgroup_context_has_io_config(c) || cgroup_context_has_blockio_config(c))
mask |= CGROUP_MASK_IO | CGROUP_MASK_BLKIO;
@@ -2055,6 +2110,11 @@ static CGroupMask unit_get_cgroup_mask(Unit *u) {
unit_has_unified_memory_config(u))
mask |= CGROUP_MASK_MEMORY;
+ if (c->cpuset_accounting ||
+ c->cpuset_cpus ||
+ c->cpuset_mems)
+ mask |= CGROUP_MASK_CPUSET;
+
if (c->device_allow ||
c->device_policy != CGROUP_DEVICE_POLICY_AUTO)
mask |= CGROUP_MASK_DEVICES | CGROUP_MASK_BPF_DEVICES;
@@ -4597,7 +4657,7 @@ int unit_get_cpuset(Unit *u, CPUSet *cpus, const char *name) {
if (!u->cgroup_path)
return -ENODATA;
- if ((u->cgroup_realized_mask & CGROUP_MASK_CPUSET) == 0)
+ if ((u->cgroup_realized_mask & CGROUP_MASK_CPUSET2) == 0)
return -ENODATA;
r = cg_all_unified();
diff --git a/src/core/cgroup.h b/src/core/cgroup.h
index f1b674b..04a7f25 100644
--- a/src/core/cgroup.h
+++ b/src/core/cgroup.h
@@ -134,6 +134,7 @@ struct CGroupContext {
bool io_accounting;
bool blockio_accounting;
bool memory_accounting;
+ bool cpuset_accounting;
bool tasks_accounting;
bool ip_accounting;
@@ -151,10 +152,10 @@ struct CGroupContext {
usec_t cpu_quota_per_sec_usec;
usec_t cpu_quota_period_usec;
- CPUSet cpuset_cpus;
- CPUSet startup_cpuset_cpus;
- CPUSet cpuset_mems;
- CPUSet startup_cpuset_mems;
+ CPUSet cpuset_cpus2;
+ CPUSet startup_cpuset_cpus2;
+ CPUSet cpuset_mems2;
+ CPUSet startup_cpuset_mems2;
uint64_t io_weight;
uint64_t startup_io_weight;
@@ -177,6 +178,11 @@ struct CGroupContext {
uint64_t memory_zswap_max;
uint64_t startup_memory_zswap_max;
+ char *cpuset_cpus;
+ char *cpuset_mems;
+ bool cpuset_clone_children;
+ bool cpuset_memory_migrate;
+
bool default_memory_min_set:1;
bool default_memory_low_set:1;
bool default_startup_memory_low_set:1;
diff --git a/src/core/dbus-cgroup.c b/src/core/dbus-cgroup.c
index 4237e69..05fd445 100644
--- a/src/core/dbus-cgroup.c
+++ b/src/core/dbus-cgroup.c
@@ -453,10 +453,10 @@ const sd_bus_vtable bus_cgroup_vtable[] = {
SD_BUS_PROPERTY("StartupCPUShares", "t", NULL, offsetof(CGroupContext, startup_cpu_shares), 0),
SD_BUS_PROPERTY("CPUQuotaPerSecUSec", "t", bus_property_get_usec, offsetof(CGroupContext, cpu_quota_per_sec_usec), 0),
SD_BUS_PROPERTY("CPUQuotaPeriodUSec", "t", bus_property_get_usec, offsetof(CGroupContext, cpu_quota_period_usec), 0),
- SD_BUS_PROPERTY("AllowedCPUs", "ay", property_get_cpuset, offsetof(CGroupContext, cpuset_cpus), 0),
- SD_BUS_PROPERTY("StartupAllowedCPUs", "ay", property_get_cpuset, offsetof(CGroupContext, startup_cpuset_cpus), 0),
- SD_BUS_PROPERTY("AllowedMemoryNodes", "ay", property_get_cpuset, offsetof(CGroupContext, cpuset_mems), 0),
- SD_BUS_PROPERTY("StartupAllowedMemoryNodes", "ay", property_get_cpuset, offsetof(CGroupContext, startup_cpuset_mems), 0),
+ SD_BUS_PROPERTY("AllowedCPUs", "ay", property_get_cpuset, offsetof(CGroupContext, cpuset_cpus2), 0),
+ SD_BUS_PROPERTY("StartupAllowedCPUs", "ay", property_get_cpuset, offsetof(CGroupContext, startup_cpuset_cpus2), 0),
+ SD_BUS_PROPERTY("AllowedMemoryNodes", "ay", property_get_cpuset, offsetof(CGroupContext, cpuset_mems2), 0),
+ SD_BUS_PROPERTY("StartupAllowedMemoryNodes", "ay", property_get_cpuset, offsetof(CGroupContext, startup_cpuset_mems2), 0),
SD_BUS_PROPERTY("IOAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, io_accounting), 0),
SD_BUS_PROPERTY("IOWeight", "t", NULL, offsetof(CGroupContext, io_weight), 0),
SD_BUS_PROPERTY("StartupIOWeight", "t", NULL, offsetof(CGroupContext, startup_io_weight), 0),
@@ -488,6 +488,11 @@ const sd_bus_vtable bus_cgroup_vtable[] = {
SD_BUS_PROPERTY("MemoryZSwapMax", "t", NULL, offsetof(CGroupContext, memory_zswap_max), 0),
SD_BUS_PROPERTY("StartupMemoryZSwapMax", "t", NULL, offsetof(CGroupContext, startup_memory_zswap_max), 0),
SD_BUS_PROPERTY("MemoryLimit", "t", NULL, offsetof(CGroupContext, memory_limit), 0),
+ SD_BUS_PROPERTY("CPUSetAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, cpuset_accounting), 0),
+ SD_BUS_PROPERTY("CPUSetCpus", "s", NULL, offsetof(CGroupContext, cpuset_cpus), 0),
+ SD_BUS_PROPERTY("CPUSetMems", "s", NULL, offsetof(CGroupContext, cpuset_mems), 0),
+ SD_BUS_PROPERTY("CPUSetCloneChildren", "b", bus_property_get_bool, offsetof(CGroupContext, cpuset_clone_children), 0),
+ SD_BUS_PROPERTY("CPUSetMemMigrate", "b", bus_property_get_bool, offsetof(CGroupContext, cpuset_memory_migrate), 0),
SD_BUS_PROPERTY("DevicePolicy", "s", property_get_cgroup_device_policy, offsetof(CGroupContext, device_policy), 0),
SD_BUS_PROPERTY("DeviceAllow", "a(ss)", property_get_device_allow, 0, 0),
SD_BUS_PROPERTY("TasksAccounting", "b", bus_property_get_bool, offsetof(CGroupContext, tasks_accounting), 0),
@@ -1279,6 +1284,43 @@ int bus_cgroup_set_property(
if (streq(name, "MemoryLimitScale"))
return bus_cgroup_set_memory_scale(u, name, &c->memory_limit, message, flags, error);
+ if (streq(name, "CPUSetAccounting"))
+ return bus_cgroup_set_boolean(u, name, &c->cpuset_accounting, CGROUP_MASK_CPUSET, message, flags, error);
+
+ if (STR_IN_SET(name, "CPUSetCpus", "CPUSetMems")) {
+ const char *cpuset_str = NULL;
+
+ r = sd_bus_message_read(message, "s", &cpuset_str);
+ if (r < 0)
+ return r;
+
+ if (!UNIT_WRITE_FLAGS_NOOP(flags)) {
+ unit_invalidate_cgroup(u, CGROUP_MASK_CPUSET);
+ if (streq(name, "CPUSetCpus")) {
+ if (c->cpuset_cpus)
+ c->cpuset_cpus = mfree(c->cpuset_cpus);
+ c->cpuset_cpus = strdup(cpuset_str);
+ if (!c->cpuset_cpus)
+ return -ENOMEM;
+ unit_write_settingf(u, flags, name, "CPUSetCpus=%s", cpuset_str);
+ } else {
+ if (c->cpuset_mems)
+ c->cpuset_mems = mfree(c->cpuset_mems);
+ c->cpuset_mems = strdup(cpuset_str);
+ if (!c->cpuset_mems)
+ return -ENOMEM;
+ unit_write_settingf(u, flags, name, "CPUSetMems=%s", cpuset_str);
+ }
+ }
+ return 1;
+ }
+
+ if (streq(name, "CPUSetCloneChildren"))
+ return bus_cgroup_set_boolean(u, name, &c->cpuset_clone_children, CGROUP_MASK_CPUSET, message, flags, error);
+
+ if (streq(name, "CPUSetMemMigrate"))
+ return bus_cgroup_set_boolean(u, name, &c->cpuset_memory_migrate, CGROUP_MASK_CPUSET, message, flags, error);
+
if (streq(name, "TasksAccounting"))
return bus_cgroup_set_boolean(u, name, &c->tasks_accounting, CGROUP_MASK_PIDS, message, flags, error);
@@ -1358,13 +1400,13 @@ int bus_cgroup_set_property(
return -ENOMEM;
if (streq(name, "AllowedCPUs"))
- set = &c->cpuset_cpus;
+ set = &c->cpuset_cpus2;
else if (streq(name, "StartupAllowedCPUs"))
- set = &c->startup_cpuset_cpus;
+ set = &c->startup_cpuset_cpus2;
else if (streq(name, "AllowedMemoryNodes"))
- set = &c->cpuset_mems;
+ set = &c->cpuset_mems2;
else if (streq(name, "StartupAllowedMemoryNodes"))
- set = &c->startup_cpuset_mems;
+ set = &c->startup_cpuset_mems2;
assert(set);
@@ -1372,7 +1414,7 @@ int bus_cgroup_set_property(
*set = new_set;
new_set = (CPUSet) {};
- unit_invalidate_cgroup(u, CGROUP_MASK_CPUSET);
+ unit_invalidate_cgroup(u, CGROUP_MASK_CPUSET2);
unit_write_settingf(u, flags, name, "%s=\n%s=%s", name, name, setstr);
}
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
index 745f5cc..fc49e7d 100644
--- a/src/core/dbus-manager.c
+++ b/src/core/dbus-manager.c
@@ -3005,6 +3005,7 @@ const sd_bus_vtable bus_manager_vtable[] = {
SD_BUS_PROPERTY("DefaultIOAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.io_accounting), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("DefaultIPAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.ip_accounting), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("DefaultMemoryAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.memory_accounting), SD_BUS_VTABLE_PROPERTY_CONST),
+ SD_BUS_PROPERTY("DefaultCpusetAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.cpuset_accounting), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("DefaultTasksAccounting", "b", bus_property_get_bool, offsetof(Manager, defaults.tasks_accounting), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("DefaultLimitCPU", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("DefaultLimitCPUSoft", "t", bus_property_get_rlimit, offsetof(Manager, defaults.rlimit[RLIMIT_CPU]), SD_BUS_VTABLE_PROPERTY_CONST),
diff --git a/src/core/execute-serialize.c b/src/core/execute-serialize.c
index 6c19cd4..e585188 100644
--- a/src/core/execute-serialize.c
+++ b/src/core/execute-serialize.c
@@ -21,8 +21,8 @@
static int exec_cgroup_context_serialize(const CGroupContext *c, FILE *f) {
_cleanup_free_ char *disable_controllers_str = NULL, *delegate_controllers_str = NULL,
- *cpuset_cpus = NULL, *cpuset_mems = NULL, *startup_cpuset_cpus = NULL,
- *startup_cpuset_mems = NULL;
+ *cpuset_cpus2 = NULL, *cpuset_mems2 = NULL, *startup_cpuset_cpus2 = NULL,
+ *startup_cpuset_mems2 = NULL;
char *iface;
struct in_addr_prefix *iaai;
int r;
@@ -96,35 +96,35 @@ static int exec_cgroup_context_serialize(const CGroupContext *c, FILE *f) {
return r;
}
- cpuset_cpus = cpu_set_to_range_string(&c->cpuset_cpus);
- if (!cpuset_cpus)
+ cpuset_cpus2 = cpu_set_to_range_string(&c->cpuset_cpus2);
+ if (!cpuset_cpus2)
return log_oom_debug();
- r = serialize_item(f, "exec-cgroup-context-allowed-cpus", cpuset_cpus);
+ r = serialize_item(f, "exec-cgroup-context-allowed-cpus", cpuset_cpus2);
if (r < 0)
return r;
- startup_cpuset_cpus = cpu_set_to_range_string(&c->startup_cpuset_cpus);
- if (!startup_cpuset_cpus)
+ startup_cpuset_cpus2 = cpu_set_to_range_string(&c->startup_cpuset_cpus2);
+ if (!startup_cpuset_cpus2)
return log_oom_debug();
- r = serialize_item(f, "exec-cgroup-context-startup-allowed-cpus", startup_cpuset_cpus);
+ r = serialize_item(f, "exec-cgroup-context-startup-allowed-cpus", startup_cpuset_cpus2);
if (r < 0)
return r;
- cpuset_mems = cpu_set_to_range_string(&c->cpuset_mems);
- if (!cpuset_mems)
+ cpuset_mems2 = cpu_set_to_range_string(&c->cpuset_mems2);
+ if (!cpuset_mems2)
return log_oom_debug();
- r = serialize_item(f, "exec-cgroup-context-allowed-memory-nodes", cpuset_mems);
+ r = serialize_item(f, "exec-cgroup-context-allowed-memory-nodes", cpuset_mems2);
if (r < 0)
return r;
- startup_cpuset_mems = cpu_set_to_range_string(&c->startup_cpuset_mems);
- if (!startup_cpuset_mems)
+ startup_cpuset_mems2 = cpu_set_to_range_string(&c->startup_cpuset_mems2);
+ if (!startup_cpuset_mems2)
return log_oom_debug();
- r = serialize_item(f, "exec-cgroup-context-startup-allowed-memory-nodes", startup_cpuset_mems);
+ r = serialize_item(f, "exec-cgroup-context-startup-allowed-memory-nodes", startup_cpuset_mems2);
if (r < 0)
return r;
@@ -555,12 +555,12 @@ static int exec_cgroup_context_deserialize(CGroupContext *c, FILE *f) {
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-cgroup-context-allowed-cpus="))) {
- if (c->cpuset_cpus.set)
+ if (c->cpuset_cpus2.set)
return -EINVAL; /* duplicated */
r = parse_cpu_set_full(
val,
- &c->cpuset_cpus,
+ &c->cpuset_cpus2,
/* warn= */ false,
/* unit= */ NULL,
/* filename= */ NULL,
@@ -569,12 +569,12 @@ static int exec_cgroup_context_deserialize(CGroupContext *c, FILE *f) {
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-cgroup-context-startup-allowed-cpus="))) {
- if (c->startup_cpuset_cpus.set)
+ if (c->startup_cpuset_cpus2.set)
return -EINVAL; /* duplicated */
r = parse_cpu_set_full(
val,
- &c->startup_cpuset_cpus,
+ &c->startup_cpuset_cpus2,
/* warn= */ false,
/* unit= */ NULL,
/* filename= */ NULL,
@@ -583,12 +583,12 @@ static int exec_cgroup_context_deserialize(CGroupContext *c, FILE *f) {
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-cgroup-context-allowed-memory-nodes="))) {
- if (c->cpuset_mems.set)
+ if (c->cpuset_mems2.set)
return -EINVAL; /* duplicated */
r = parse_cpu_set_full(
val,
- &c->cpuset_mems,
+ &c->cpuset_mems2,
/* warn= */ false,
/* unit= */ NULL,
/* filename= */ NULL,
@@ -597,12 +597,12 @@ static int exec_cgroup_context_deserialize(CGroupContext *c, FILE *f) {
if (r < 0)
return r;
} else if ((val = startswith(l, "exec-cgroup-context-startup-allowed-memory-nodes="))) {
- if (c->startup_cpuset_mems.set)
+ if (c->startup_cpuset_mems2.set)
return -EINVAL; /* duplicated */
r = parse_cpu_set_full(
val,
- &c->startup_cpuset_mems,
+ &c->startup_cpuset_mems2,
/* warn= */ false,
/* unit= */ NULL,
/* filename= */ NULL,
diff --git a/src/core/load-fragment-gperf.gperf.in b/src/core/load-fragment-gperf.gperf.in
index 45f9ab0..1e46af4 100644
--- a/src/core/load-fragment-gperf.gperf.in
+++ b/src/core/load-fragment-gperf.gperf.in
@@ -194,10 +194,10 @@
{%- macro CGROUP_CONTEXT_CONFIG_ITEMS(type) -%}
{{type}}.Slice, config_parse_unit_slice, 0, 0
-{{type}}.AllowedCPUs, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.cpuset_cpus)
-{{type}}.StartupAllowedCPUs, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.startup_cpuset_cpus)
-{{type}}.AllowedMemoryNodes, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.cpuset_mems)
-{{type}}.StartupAllowedMemoryNodes, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.startup_cpuset_mems)
+{{type}}.AllowedCPUs, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.cpuset_cpus2)
+{{type}}.StartupAllowedCPUs, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.startup_cpuset_cpus2)
+{{type}}.AllowedMemoryNodes, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.cpuset_mems2)
+{{type}}.StartupAllowedMemoryNodes, config_parse_allowed_cpuset, 0, offsetof({{type}}, cgroup_context.startup_cpuset_mems2)
{{type}}.CPUAccounting, config_parse_bool, 0, offsetof({{type}}, cgroup_context.cpu_accounting)
{{type}}.CPUWeight, config_parse_cg_cpu_weight, 0, offsetof({{type}}, cgroup_context.cpu_weight)
{{type}}.StartupCPUWeight, config_parse_cg_cpu_weight, 0, offsetof({{type}}, cgroup_context.startup_cpu_weight)
@@ -221,6 +221,11 @@
{{type}}.MemoryZSwapMax, config_parse_memory_limit, 0, offsetof({{type}}, cgroup_context)
{{type}}.StartupMemoryZSwapMax, config_parse_memory_limit, 0, offsetof({{type}}, cgroup_context)
{{type}}.MemoryLimit, config_parse_memory_limit, 0, offsetof({{type}}, cgroup_context)
+{{type}}.CPUSetAccounting, config_parse_bool, 0, offsetof({{type}}, cgroup_context.cpuset_accounting)
+{{type}}.CPUSetCpus, config_parse_cpuset_cpumems, 0, offsetof({{type}}, cgroup_context.cpuset_cpus)
+{{type}}.CPUSetMems, config_parse_cpuset_cpumems, 0, offsetof({{type}}, cgroup_context.cpuset_mems)
+{{type}}.CPUSetCloneChildren, config_parse_bool, 0, offsetof({{type}}, cgroup_context.cpuset_clone_children)
+{{type}}.CPUSetMemMigrate, config_parse_bool, 0, offsetof({{type}}, cgroup_context.cpuset_memory_migrate)
{{type}}.DeviceAllow, config_parse_device_allow, 0, offsetof({{type}}, cgroup_context)
{{type}}.DevicePolicy, config_parse_device_policy, 0, offsetof({{type}}, cgroup_context.device_policy)
{{type}}.IOAccounting, config_parse_bool, 0, offsetof({{type}}, cgroup_context.io_accounting)
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 6e3a22b..cbc75e1 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -3904,6 +3904,75 @@ int config_parse_memory_limit(
return 0;
}
+int config_parse_cpuset_cpumems(
+ const char *unit,
+ const char *filename,
+ unsigned line,
+ const char *section,
+ unsigned section_line,
+ const char *lvalue,
+ int ltype,
+ const char *rvalue,
+ void *data,
+ void *userdata)
+{
+ char **pcpumems = data;
+ char *pinstr = NULL;
+ int iret = 0;
+
+ assert(filename);
+ assert(lvalue);
+ assert(rvalue);
+ assert(data);
+ (void)section;
+ (void)section_line;
+ (void)ltype;
+ (void)userdata;
+
+ if (!utf8_is_valid(rvalue))
+ {
+ log_syntax_invalid_utf8(unit, LOG_ERR, filename, line, rvalue);
+ return 0;
+ }
+
+ if (0 == strcmp(rvalue, "all"))
+ {
+ pinstr = strdup(rvalue);
+ if (!pinstr)
+ {
+ return log_oom();
+ }
+
+ free(*pcpumems);
+ *pcpumems = pinstr;
+
+ return 0;
+ }
+
+ /* 0-2,4 */
+ iret = string_isvalid_interval(rvalue);
+ if (0 != iret)
+ {
+ pinstr = NULL;
+ log_syntax(unit, LOG_ERR, filename, line, EINVAL,
+ "cpuset cpumems '%s' is invalid, Ignoring(%d).",
+ rvalue, iret);
+ }
+ else
+ {
+ pinstr = strdup(rvalue);
+ if (!pinstr)
+ {
+ return log_oom();
+ }
+ }
+
+ free(*pcpumems);
+ *pcpumems = pinstr;
+
+ return 0;
+}
+
int config_parse_tasks_max(
const char *unit,
const char *filename,
diff --git a/src/core/load-fragment.h b/src/core/load-fragment.h
index 6919805..0b77c8b 100644
--- a/src/core/load-fragment.h
+++ b/src/core/load-fragment.h
@@ -84,6 +84,7 @@ CONFIG_PARSER_PROTOTYPE(config_parse_cg_weight);
CONFIG_PARSER_PROTOTYPE(config_parse_cg_cpu_weight);
CONFIG_PARSER_PROTOTYPE(config_parse_cpu_shares);
CONFIG_PARSER_PROTOTYPE(config_parse_memory_limit);
+CONFIG_PARSER_PROTOTYPE(config_parse_cpuset_cpumems);
CONFIG_PARSER_PROTOTYPE(config_parse_tasks_max);
CONFIG_PARSER_PROTOTYPE(config_parse_delegate);
CONFIG_PARSER_PROTOTYPE(config_parse_delegate_subgroup);
diff --git a/src/core/main.c b/src/core/main.c
index 62112dc..de3f536 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -678,6 +678,7 @@ static int parse_config_file(void) {
{ "Manager", "DefaultIPAccounting", config_parse_bool, 0, &arg_defaults.ip_accounting },
{ "Manager", "DefaultBlockIOAccounting", config_parse_bool, 0, &arg_defaults.blockio_accounting },
{ "Manager", "DefaultMemoryAccounting", config_parse_bool, 0, &arg_defaults.memory_accounting },
+ { "Manager", "DefaultCpusetAccounting", config_parse_bool, 0, &arg_defaults.cpuset_accounting },
{ "Manager", "DefaultTasksAccounting", config_parse_bool, 0, &arg_defaults.tasks_accounting },
{ "Manager", "DefaultTasksMax", config_parse_tasks_max, 0, &arg_defaults.tasks_max },
{ "Manager", "DefaultMemoryPressureThresholdSec", config_parse_sec, 0, &arg_defaults.memory_pressure_threshold_usec },
diff --git a/src/core/manager.c b/src/core/manager.c
index ce20d6b..ef22fed 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -4192,6 +4192,7 @@ int manager_set_unit_defaults(Manager *m, const UnitDefaults *defaults) {
m->defaults.cpu_accounting = defaults->cpu_accounting;
m->defaults.memory_accounting = defaults->memory_accounting;
+ m->defaults.cpuset_accounting = defaults->cpuset_accounting;
m->defaults.io_accounting = defaults->io_accounting;
m->defaults.blockio_accounting = defaults->blockio_accounting;
m->defaults.tasks_accounting = defaults->tasks_accounting;
@@ -4961,6 +4962,7 @@ void unit_defaults_init(UnitDefaults *defaults, RuntimeScope scope) {
* controller to be enabled, so the default is to enable it unless we got told otherwise. */
.cpu_accounting = cpu_accounting_is_cheap(),
.memory_accounting = MEMORY_ACCOUNTING_DEFAULT,
+ .cpuset_accounting = false,
.io_accounting = false,
.blockio_accounting = false,
.tasks_accounting = true,
diff --git a/src/core/manager.h b/src/core/manager.h
index d96eb7b..e560811 100644
--- a/src/core/manager.h
+++ b/src/core/manager.h
@@ -165,6 +165,7 @@ typedef struct UnitDefaults {
bool memory_accounting;
bool io_accounting;
bool blockio_accounting;
+ bool cpuset_accounting;
bool tasks_accounting;
bool ip_accounting;
diff --git a/src/core/system.conf.in b/src/core/system.conf.in
index 90109ad..69ea5d6 100644
--- a/src/core/system.conf.in
+++ b/src/core/system.conf.in
@@ -57,6 +57,7 @@
#DefaultIOAccounting=no
#DefaultIPAccounting=no
#DefaultMemoryAccounting={{ 'yes' if MEMORY_ACCOUNTING_DEFAULT else 'no' }}
+#DefaultCpusetAccounting=
#DefaultTasksAccounting=yes
#DefaultTasksMax=80%
#DefaultLimitCPU=
diff --git a/src/core/unit.c b/src/core/unit.c
index 69fc998..38017d0 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -188,6 +188,7 @@ static void unit_init(Unit *u) {
cc->io_accounting = u->manager->defaults.io_accounting;
cc->blockio_accounting = u->manager->defaults.blockio_accounting;
cc->memory_accounting = u->manager->defaults.memory_accounting;
+ cc->cpuset_accounting = u->manager->defaults.cpuset_accounting;
cc->tasks_accounting = u->manager->defaults.tasks_accounting;
cc->ip_accounting = u->manager->defaults.ip_accounting;
diff --git a/src/shared/bus-unit-util.c b/src/shared/bus-unit-util.c
index 4ee9706..a8f493e 100644
--- a/src/shared/bus-unit-util.c
+++ b/src/shared/bus-unit-util.c
@@ -566,7 +566,10 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
"BlockIOAccounting",
"TasksAccounting",
"IPAccounting",
- "CoredumpReceive"))
+ "CoredumpReceive",
+ "CPUSetAccounting",
+ "CPUSetCloneChildren",
+ "CPUSetMemMigrate"))
return bus_append_parse_boolean(m, field, eq);
if (STR_IN_SET(field, "CPUWeight",
@@ -672,6 +675,16 @@ static int bus_append_cgroup_property(sd_bus_message *m, const char *field, cons
return bus_append_parse_size(m, field, eq, 1024);
}
+ if (STR_IN_SET(field, "CPUSetCpus", "CPUSetMems")) {
+ if (string_isvalid_interval(eq) == 0 || streq(eq, "all"))
+ r = sd_bus_message_append(m, "(sv)", field, "s", eq);
+ else
+ r = -EINVAL;
+ if (r < 0)
+ return bus_log_create_error(r);
+ return 1;
+ }
+
if (streq(field, "CPUQuota")) {
if (isempty(eq))
r = sd_bus_message_append(m, "(sv)", "CPUQuotaPerSecUSec", "t", USEC_INFINITY);
diff --git a/src/shared/cpu-set-util.c b/src/shared/cpu-set-util.c
index d096576..356a46a 100644
--- a/src/shared/cpu-set-util.c
+++ b/src/shared/cpu-set-util.c
@@ -7,6 +7,7 @@
#include "alloc-util.h"
#include "cpu-set-util.h"
+#include "cgroup-util.h"
#include "dirent-util.h"
#include "errno-util.h"
#include "extract-word.h"
diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c
index bfc8fac..37ec6d6 100644
--- a/src/test/test-cgroup-mask.c
+++ b/src/test/test-cgroup-mask.c
@@ -55,6 +55,7 @@ TEST_RET(cgroup_mask, .sd_booted = true) {
* else. */
m->defaults.cpu_accounting =
m->defaults.memory_accounting =
+ m->defaults.cpuset_accounting =
m->defaults.blockio_accounting =
m->defaults.io_accounting =
m->defaults.tasks_accounting = false;
@@ -140,10 +141,10 @@ static void test_cg_mask_to_string_one(CGroupMask mask, const char *t) {
TEST(cg_mask_to_string) {
test_cg_mask_to_string_one(0, NULL);
- test_cg_mask_to_string_one(_CGROUP_MASK_ALL, "cpu cpuacct cpuset io blkio memory devices pids bpf-firewall bpf-devices bpf-foreign bpf-socket-bind bpf-restrict-network-interfaces");
+ test_cg_mask_to_string_one(_CGROUP_MASK_ALL, "cpu cpuacct cpuset2 io blkio memory devices pids cpuset bpf-firewall bpf-devices bpf-foreign bpf-socket-bind bpf-restrict-network-interfaces");
test_cg_mask_to_string_one(CGROUP_MASK_CPU, "cpu");
test_cg_mask_to_string_one(CGROUP_MASK_CPUACCT, "cpuacct");
- test_cg_mask_to_string_one(CGROUP_MASK_CPUSET, "cpuset");
+ test_cg_mask_to_string_one(CGROUP_MASK_CPUSET2, "cpuset2");
test_cg_mask_to_string_one(CGROUP_MASK_IO, "io");
test_cg_mask_to_string_one(CGROUP_MASK_BLKIO, "blkio");
test_cg_mask_to_string_one(CGROUP_MASK_MEMORY, "memory");
diff --git a/test/fuzz/fuzz-unit-file/directives-all.service b/test/fuzz/fuzz-unit-file/directives-all.service
index 4bdc48a..0e953f2 100644
--- a/test/fuzz/fuzz-unit-file/directives-all.service
+++ b/test/fuzz/fuzz-unit-file/directives-all.service
@@ -52,6 +52,11 @@ BusName=
CoredumpFilter=
CPUAccounting=
CPUQuota=
+CPUSetAccounting=
+CPUSetCloneChildren=
+CPUSetCpus=
+CPUSetMemMigrate=
+CPUSetMems=
CPUShares=
CPUWeight=
CapabilityBoundingSet=
--
2.41.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化