1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
|
From 8fc496f1e5b6d71d29eb446e02f6317bdc45c7c2 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.h | 8 ++-
src/basic/string-util.c | 42 +++++++++++
src/basic/string-util.h | 1 +
src/core/cgroup.c | 62 ++++++++++++++++-
src/core/cgroup.h | 6 ++
src/core/dbus-cgroup.c | 42 +++++++++++
src/core/dbus-manager.c | 1 +
src/core/load-fragment-gperf.gperf.in | 5 ++
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 | 1 +
.../fuzz-unit-file/directives-all.service | 5 ++
21 files changed, 264 insertions(+), 6 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.h b/src/basic/cgroup-util.h
index 6ab14c7..831f8ce 100644
--- a/src/basic/cgroup-util.h
+++ b/src/basic/cgroup-util.h
@@ -22,7 +22,7 @@ typedef enum CGroupController {
/* Original cgroup controllers */
CGROUP_CONTROLLER_CPU,
CGROUP_CONTROLLER_CPUACCT, /* v1 only */
- CGROUP_CONTROLLER_CPUSET, /* v2 only */
+ CGROUP_CONTROLLER_CPUSET,
CGROUP_CONTROLLER_IO, /* v2 only */
CGROUP_CONTROLLER_BLKIO, /* v1 only */
CGROUP_CONTROLLER_MEMORY,
@@ -62,7 +62,11 @@ 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,
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..3154fd3 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -293,6 +293,12 @@ void cgroup_context_done(CGroupContext *c) {
c->restrict_network_interfaces = set_free_free(c->restrict_network_interfaces);
+ if (c->cpuset_cpus_v1)
+ c->cpuset_cpus_v1 = mfree(c->cpuset_cpus_v1);
+
+ if (c->cpuset_mems_v1)
+ c->cpuset_mems_v1 = mfree(c->cpuset_mems_v1);
+
cpu_set_reset(&c->cpuset_cpus);
cpu_set_reset(&c->startup_cpuset_cpus);
cpu_set_reset(&c->cpuset_mems);
@@ -535,6 +541,7 @@ void cgroup_context_dump(Unit *u, FILE* f, const char *prefix) {
"%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,
@@ -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_v1,
+ prefix, c->cpuset_mems_v1,
+ 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),
@@ -1728,8 +1744,47 @@ static void cgroup_context_apply(
}
if ((apply_mask & CGROUP_MASK_CPUSET) && !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");
+ if (cg_all_unified() == 0) {
+ (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_v1) {
+ if (streq(c->cpuset_cpus_v1, "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_v1);
+ }
+ if (c->cpuset_mems_v1) {
+ if (streq(c->cpuset_mems_v1, "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_v1);
+ }
+ } else {
+ 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");
+ }
}
/* The 'io' controller attributes are not exported on the host's root cgroup (being a pure cgroup v2
@@ -2044,7 +2099,8 @@ static CGroupMask unit_get_cgroup_mask(Unit *u) {
c->cpu_quota_per_sec_usec != USEC_INFINITY)
mask |= CGROUP_MASK_CPU;
- if (cgroup_context_has_allowed_cpus(c) || cgroup_context_has_allowed_mems(c))
+ if (cgroup_context_has_allowed_cpus(c) || cgroup_context_has_allowed_mems(c) ||
+ c->cpuset_accounting || c->cpuset_cpus_v1 || c->cpuset_mems_v1)
mask |= CGROUP_MASK_CPUSET;
if (cgroup_context_has_io_config(c) || cgroup_context_has_blockio_config(c))
diff --git a/src/core/cgroup.h b/src/core/cgroup.h
index f1b674b..a4bd959 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;
@@ -177,6 +178,11 @@ struct CGroupContext {
uint64_t memory_zswap_max;
uint64_t startup_memory_zswap_max;
+ char *cpuset_cpus_v1;
+ char *cpuset_mems_v1;
+ 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..e82d56e 100644
--- a/src/core/dbus-cgroup.c
+++ b/src/core/dbus-cgroup.c
@@ -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_v1), 0),
+ SD_BUS_PROPERTY("CPUSetMems", "s", NULL, offsetof(CGroupContext, cpuset_mems_v1), 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_v1)
+ c->cpuset_cpus_v1 = mfree(c->cpuset_cpus_v1);
+ c->cpuset_cpus_v1 = strdup(cpuset_str);
+ if (!c->cpuset_cpus_v1)
+ return -ENOMEM;
+ unit_write_settingf(u, flags, name, "CPUSetCpus=%s", cpuset_str);
+ } else {
+ if (c->cpuset_mems_v1)
+ c->cpuset_mems_v1 = mfree(c->cpuset_mems_v1);
+ c->cpuset_mems_v1 = strdup(cpuset_str);
+ if (!c->cpuset_mems_v1)
+ 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);
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/load-fragment-gperf.gperf.in b/src/core/load-fragment-gperf.gperf.in
index 45f9ab0..62c4027 100644
--- a/src/core/load-fragment-gperf.gperf.in
+++ b/src/core/load-fragment-gperf.gperf.in
@@ -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_v1)
+{{type}}.CPUSetMems, config_parse_cpuset_cpumems, 0, offsetof({{type}}, cgroup_context.cpuset_mems_v1)
+{{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 bfdcc13..724593a 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 3d60904..e38a535 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..5dd569f 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;
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.23.0
|