From: Lennart Poettering Date: Mon, 24 Feb 2014 22:50:10 +0000 (+0100) Subject: core: add global settings for enabling CPUAccounting=, MemoryAccounting=, BlockIOAcco... X-Git-Tag: v211~222 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=commitdiff_plain;h=085afe36cb823e7d5b8c5f3ef21ebb9639bac78b core: add global settings for enabling CPUAccounting=, MemoryAccounting=, BlockIOAccounting= for all units at once --- diff --git a/man/systemd-system.conf.xml b/man/systemd-system.conf.xml index f3a89ad45..a7dfc0329 100644 --- a/man/systemd-system.conf.xml +++ b/man/systemd-system.conf.xml @@ -292,7 +292,7 @@ TimeoutStartSec=, TimeoutStopSec= and RestartSec= (for - service units, see + services, see systemd.service5 for details on the per-unit settings). For non-service units, @@ -301,18 +301,20 @@ TimeoutSec= value. + DefaultStartLimitInterval= DefaultStartLimitBurst= - Configure the default start rate - limiting, as configured per-service by - StartLimitInterval= and + Configure the default + unit start rate limiting, as + configured per-service by + StartLimitInterval= + and StartLimitBurst=. See systemd.service5 for details on the per-service - settings). - + settings. @@ -337,6 +339,23 @@ VAR3. + + DefaultCPUAccounting= + DefaultBlockIOAccounting= + DefaultMemoryAccounting= + + Configure the default + resource accounting settings, as + configured per-unit by + CPUAccounting=, + BlockIOAccounting= + and + MemoryAccounting=. See + systemd.resource-control5 + for details on the per-unit + settings. + + DefaultLimitCPU= DefaultLimitFSIZE= diff --git a/man/systemd.resource-control.xml b/man/systemd.resource-control.xml index e923b6da8..c3fd5fcee 100644 --- a/man/systemd.resource-control.xml +++ b/man/systemd.resource-control.xml @@ -105,8 +105,11 @@ along with systemd; If not, see . Turn on CPU usage accounting for this unit. Takes a boolean argument. Note that turning on CPU accounting for one unit might also implicitly turn it on for all units - contained in the same slice and for all its parent slices and - the units contained therein. + contained in the same slice and for all its parent slices + and the units contained therein. The system default for this + setting maybe controlled with + DefaultCPUAccounting= in + systemd-system.conf5. @@ -132,8 +135,10 @@ along with systemd; If not, see . Turn on process and kernel memory accounting for this unit. Takes a boolean argument. Note that turning on memory accounting for one unit might also implicitly turn it on for - all units contained in the same slice and for all its parent - slices and the units contained therein. + all its parent slices. The system default for this setting + maybe controlled with + DefaultMemoryAccounting= in + systemd-system.conf5. @@ -164,8 +169,11 @@ along with systemd; If not, see . Turn on Block IO accounting for this unit. Takes a boolean argument. Note that turning on block IO accounting for one unit might also implicitly turn it on for all units - contained in the same slice and all for its parent slices and - the units contained therein. + contained in the same slice and all for its parent slices + and the units contained therein. The system default for this + setting maybe controlled with + DefaultBlockIOAccounting= in + systemd-system.conf5. diff --git a/src/core/main.c b/src/core/main.c index 4e24f851e..d3581fcde 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -107,6 +107,9 @@ static uint64_t arg_capability_bounding_set_drop = 0; static nsec_t arg_timer_slack_nsec = (nsec_t) -1; static Set* arg_syscall_archs = NULL; static FILE* arg_serialization = NULL; +static bool arg_default_cpu_accounting = false; +static bool arg_default_blockio_accounting = false; +static bool arg_default_memory_accounting = false; static void nop_handler(int sig) {} @@ -673,6 +676,9 @@ static int parse_config_file(void) { { "Manager", "DefaultLimitNICE", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_NICE] }, { "Manager", "DefaultLimitRTPRIO", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_RTPRIO] }, { "Manager", "DefaultLimitRTTIME", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_RTTIME] }, + { "Manager", "DefaultCPUAccounting", config_parse_bool, 0, &arg_default_cpu_accounting }, + { "Manager", "DefaultBlockIOAccounting", config_parse_bool, 0, &arg_default_blockio_accounting }, + { "Manager", "DefaultMemoryAccounting", config_parse_bool, 0, &arg_default_memory_accounting }, {} }; @@ -1591,6 +1597,9 @@ int main(int argc, char *argv[]) { m->default_timeout_stop_usec = arg_default_timeout_stop_usec; m->default_start_limit_interval = arg_default_start_limit_interval; m->default_start_limit_burst = arg_default_start_limit_burst; + m->default_cpu_accounting = arg_default_cpu_accounting; + m->default_blockio_accounting = arg_default_blockio_accounting; + m->default_memory_accounting = arg_default_memory_accounting; m->runtime_watchdog = arg_runtime_watchdog; m->shutdown_watchdog = arg_shutdown_watchdog; m->userspace_timestamp = userspace_timestamp; diff --git a/src/core/manager.h b/src/core/manager.h index 948ea98a4..9dee48ddd 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -212,12 +212,15 @@ struct Manager { ExecOutput default_std_output, default_std_error; - usec_t default_restart_usec, default_timeout_start_usec, - default_timeout_stop_usec; + usec_t default_restart_usec, default_timeout_start_usec, default_timeout_stop_usec; usec_t default_start_limit_interval; unsigned default_start_limit_burst; + bool default_cpu_accounting; + bool default_memory_accounting; + bool default_blockio_accounting; + struct rlimit *rlimit[RLIMIT_NLIMITS]; /* non-zero if we are reloading or reexecuting, */ diff --git a/src/core/mount.c b/src/core/mount.c index a0cea1e7d..814674a02 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -141,6 +141,8 @@ static void mount_init(Unit *u) { kill_context_init(&m->kill_context); cgroup_context_init(&m->cgroup_context); + unit_cgroup_context_init_defaults(u, &m->cgroup_context); + if (unit_has_name(u, "-.mount")) { /* Don't allow start/stop for root directory */ u->refuse_manual_start = true; @@ -577,7 +579,7 @@ static int mount_add_extras(Mount *m) { if (r < 0) return r; - r = unit_exec_context_defaults(u, &m->exec_context); + r = unit_exec_context_patch_defaults(u, &m->exec_context); if (r < 0) return r; diff --git a/src/core/scope.c b/src/core/scope.c index 16758fed0..be2a63702 100644 --- a/src/core/scope.c +++ b/src/core/scope.c @@ -54,6 +54,8 @@ static void scope_init(Unit *u) { cgroup_context_init(&s->cgroup_context); kill_context_init(&s->kill_context); + unit_cgroup_context_init_defaults(u, &s->cgroup_context); + UNIT(s)->ignore_on_isolate = true; UNIT(s)->ignore_on_snapshot = true; } diff --git a/src/core/service.c b/src/core/service.c index ca71788d2..697777425 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -147,9 +147,9 @@ static void service_init(Unit *u) { kill_context_init(&s->kill_context); cgroup_context_init(&s->cgroup_context); - RATELIMIT_INIT(s->start_limit, - u->manager->default_start_limit_interval, - u->manager->default_start_limit_burst); + unit_cgroup_context_init_defaults(u, &s->cgroup_context); + + RATELIMIT_INIT(s->start_limit, u->manager->default_start_limit_interval, u->manager->default_start_limit_burst); s->control_command_id = _SERVICE_EXEC_COMMAND_INVALID; } @@ -1235,7 +1235,7 @@ static int service_load(Unit *u) { return r; } - r = unit_exec_context_defaults(u, &s->exec_context); + r = unit_exec_context_patch_defaults(u, &s->exec_context); if (r < 0) return r; } diff --git a/src/core/slice.c b/src/core/slice.c index 1e42df2b8..ae9a54ba6 100644 --- a/src/core/slice.c +++ b/src/core/slice.c @@ -43,6 +43,7 @@ static void slice_init(Unit *u) { assert(u->load_state == UNIT_STUB); cgroup_context_init(&s->cgroup_context); + unit_cgroup_context_init_defaults(u, &s->cgroup_context); } static void slice_done(Unit *u) { diff --git a/src/core/socket.c b/src/core/socket.c index 0ccda2fe3..8e39032db 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -96,6 +96,8 @@ static void socket_init(Unit *u) { kill_context_init(&s->kill_context); cgroup_context_init(&s->cgroup_context); + unit_cgroup_context_init_defaults(u, &s->cgroup_context); + s->control_command_id = _SOCKET_EXEC_COMMAND_INVALID; } @@ -338,7 +340,7 @@ static int socket_add_extras(Socket *s) { if (r < 0) return r; - r = unit_exec_context_defaults(u, &s->exec_context); + r = unit_exec_context_patch_defaults(u, &s->exec_context); if (r < 0) return r; diff --git a/src/core/swap.c b/src/core/swap.c index 24c4611cb..96cf38aae 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -124,6 +124,8 @@ static void swap_init(Unit *u) { kill_context_init(&s->kill_context); cgroup_context_init(&s->cgroup_context); + unit_cgroup_context_init_defaults(u, &s->cgroup_context); + s->parameters_proc_swaps.priority = s->parameters_fragment.priority = -1; s->control_command_id = _SWAP_EXEC_COMMAND_INVALID; @@ -352,7 +354,7 @@ static int swap_load(Unit *u) { return r; } - r = unit_exec_context_defaults(u, &s->exec_context); + r = unit_exec_context_patch_defaults(u, &s->exec_context); if (r < 0) return r; } diff --git a/src/core/system.conf b/src/core/system.conf index 7a2d7b4d0..5be158d9f 100644 --- a/src/core/system.conf +++ b/src/core/system.conf @@ -31,6 +31,9 @@ #DefaultStartLimitInterval=10s #DefaultStartLimitBurst=5 #DefaultEnvironment= +#DefaultCPUAccounting=no +#DefaultBlockIOAccounting=no +#DefaultMemoryAccounting=no #DefaultLimitCPU= #DefaultLimitFSIZE= #DefaultLimitDATA= diff --git a/src/core/unit.c b/src/core/unit.c index 1bbcb39d3..9d54147ad 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -2777,13 +2777,30 @@ void unit_ref_unset(UnitRef *ref) { ref->unit = NULL; } -int unit_exec_context_defaults(Unit *u, ExecContext *c) { +int unit_cgroup_context_init_defaults(Unit *u, CGroupContext *c) { + assert(u); + assert(c); + + /* Copy in the manager defaults into the cgroup context, + * _before_ the rest of the settings have been initialized */ + + c->cpu_accounting = u->manager->default_cpu_accounting; + c->blockio_accounting = u->manager->default_blockio_accounting; + c->memory_accounting = u->manager->default_memory_accounting; + + return 0; +} + +int unit_exec_context_patch_defaults(Unit *u, ExecContext *c) { unsigned i; int r; assert(u); assert(c); + /* Patch in the manager defaults into the exec context, + * _after_ the rest of the settings have been initialized */ + /* This only copies in the ones that need memory */ for (i = 0; i < RLIMIT_NLIMITS; i++) if (u->manager->rlimit[i] && !c->rlimit[i]) { diff --git a/src/core/unit.h b/src/core/unit.h index 808929e64..34afe93e6 100644 --- a/src/core/unit.h +++ b/src/core/unit.h @@ -602,7 +602,8 @@ void unit_ref_unset(UnitRef *ref); #define UNIT_DEREF(ref) ((ref).unit) #define UNIT_ISSET(ref) (!!(ref).unit) -int unit_exec_context_defaults(Unit *u, ExecContext *c); +int unit_exec_context_patch_defaults(Unit *u, ExecContext *c); +int unit_cgroup_context_init_defaults(Unit *u, CGroupContext *c); ExecContext *unit_get_exec_context(Unit *u) _pure_; KillContext *unit_get_kill_context(Unit *u) _pure_;