diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-02-24 23:50:10 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-02-24 23:50:10 +0100 |
commit | 085afe36cb823e7d5b8c5f3ef21ebb9639bac78b (patch) | |
tree | 25b26a8b92d8562983b22098d0dfe5777efc8927 /src | |
parent | 4e72e29a390e0bd9226eb802d80b9a9c259565cd (diff) |
core: add global settings for enabling CPUAccounting=, MemoryAccounting=, BlockIOAccounting= for all units at once
Diffstat (limited to 'src')
-rw-r--r-- | src/core/main.c | 9 | ||||
-rw-r--r-- | src/core/manager.h | 7 | ||||
-rw-r--r-- | src/core/mount.c | 4 | ||||
-rw-r--r-- | src/core/scope.c | 2 | ||||
-rw-r--r-- | src/core/service.c | 8 | ||||
-rw-r--r-- | src/core/slice.c | 1 | ||||
-rw-r--r-- | src/core/socket.c | 4 | ||||
-rw-r--r-- | src/core/swap.c | 4 | ||||
-rw-r--r-- | src/core/system.conf | 3 | ||||
-rw-r--r-- | src/core/unit.c | 19 | ||||
-rw-r--r-- | src/core/unit.h | 3 |
11 files changed, 53 insertions, 11 deletions
diff --git a/src/core/main.c b/src/core/main.c index 4e24f851e2..d3581fcde9 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 948ea98a45..9dee48ddde 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 a0cea1e7d4..814674a02d 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 16758fed0a..be2a637023 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 ca71788d22..6977774257 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 1e42df2b8b..ae9a54ba69 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 0ccda2fe3c..8e39032db6 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 24c4611cbe..96cf38aae2 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 7a2d7b4d09..5be158d9f5 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 1bbcb39d32..9d54147adb 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 808929e64a..34afe93e65 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_; |