From ecee72e1b6c3476b674b58472c483fc4aef7ceed Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 13 Nov 2015 15:24:21 +0100 Subject: core: make sure DefaultLimitCPU= and DefaultLimitRTTIME= understand time units, too We added this for the per-unit setting, hence let's enable this for the global default settings too. --- src/core/main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/core/main.c') diff --git a/src/core/main.c b/src/core/main.c index 33529c3e76..0924b51a7d 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -657,7 +657,7 @@ static int parse_config_file(void) { { "Manager", "DefaultStartLimitInterval", config_parse_sec, 0, &arg_default_start_limit_interval }, { "Manager", "DefaultStartLimitBurst", config_parse_unsigned, 0, &arg_default_start_limit_burst }, { "Manager", "DefaultEnvironment", config_parse_environ, 0, &arg_default_environment }, - { "Manager", "DefaultLimitCPU", config_parse_limit, 0, &arg_default_rlimit[RLIMIT_CPU] }, + { "Manager", "DefaultLimitCPU", config_parse_sec_limit, 0, &arg_default_rlimit[RLIMIT_CPU] }, { "Manager", "DefaultLimitFSIZE", config_parse_bytes_limit, 0, &arg_default_rlimit[RLIMIT_FSIZE] }, { "Manager", "DefaultLimitDATA", config_parse_bytes_limit, 0, &arg_default_rlimit[RLIMIT_DATA] }, { "Manager", "DefaultLimitSTACK", config_parse_bytes_limit, 0, &arg_default_rlimit[RLIMIT_STACK] }, @@ -672,7 +672,7 @@ static int parse_config_file(void) { { "Manager", "DefaultLimitMSGQUEUE", config_parse_bytes_limit, 0, &arg_default_rlimit[RLIMIT_MSGQUEUE] }, { "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", "DefaultLimitRTTIME", config_parse_usec_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 }, -- cgit v1.2.3-54-g00ecf From 0af20ea2ee2af2bcf2258e7a8e1a13181a6a75d6 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 13 Nov 2015 17:13:55 +0100 Subject: core: add new DefaultTasksMax= setting for system.conf This allows initializing the TasksMax= setting of all units by default to some fixed value, instead of leaving it at infinity as before. --- man/systemd-system.conf.xml | 13 ++++++++++++- man/systemd.resource-control.xml | 5 ++++- src/core/dbus-manager.c | 1 + src/core/load-fragment-gperf.gperf.m4 | 2 +- src/core/load-fragment.c | 7 +++---- src/core/main.c | 3 +++ src/core/manager.c | 1 + src/core/manager.h | 1 + src/core/system.conf | 1 + src/core/unit.c | 3 +++ 10 files changed, 30 insertions(+), 7 deletions(-) (limited to 'src/core/main.c') diff --git a/man/systemd-system.conf.xml b/man/systemd-system.conf.xml index 54ce992b85..0050f24f8e 100644 --- a/man/systemd-system.conf.xml +++ b/man/systemd-system.conf.xml @@ -1,4 +1,4 @@ - + @@ -320,6 +320,17 @@ for details on the per-unit settings. + + DefaultTasksMax= + + Configure the default value for the per-unit + TasksMax= setting. See + systemd.resource-control5 + for details. This setting applies to all unit types that + support resource control settings, with the exception of slice + units. + + DefaultLimitCPU= DefaultLimitFSIZE= diff --git a/man/systemd.resource-control.xml b/man/systemd.resource-control.xml index 0497f60546..b1106c759d 100644 --- a/man/systemd.resource-control.xml +++ b/man/systemd.resource-control.xml @@ -241,7 +241,10 @@ see pids.txt. - Implies TasksAccounting=true. + Implies TasksAccounting=true. The + system default for this setting may be controlled with + DefaultTasksMax= in + systemd-system.conf5. diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c index d3bcc795ae..72ad6121e0 100644 --- a/src/core/dbus-manager.c +++ b/src/core/dbus-manager.c @@ -1960,6 +1960,7 @@ const sd_bus_vtable bus_manager_vtable[] = { SD_BUS_PROPERTY("DefaultLimitNICE", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_NICE]), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("DefaultLimitRTPRIO", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTPRIO]), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("DefaultLimitRTTIME", "t", bus_property_get_rlimit, offsetof(Manager, rlimit[RLIMIT_RTTIME]), SD_BUS_VTABLE_PROPERTY_CONST), + SD_BUS_PROPERTY("DefaultTasksMax", "t", NULL, offsetof(Manager, default_tasks_max), SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_PROPERTY("TimerSlackNSec", "t", property_get_timer_slack_nsec, 0, SD_BUS_VTABLE_PROPERTY_CONST), SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit, SD_BUS_VTABLE_UNPRIVILEGED), diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4 index 4c5376d601..799418033d 100644 --- a/src/core/load-fragment-gperf.gperf.m4 +++ b/src/core/load-fragment-gperf.gperf.m4 @@ -126,7 +126,7 @@ $1.BlockIODeviceWeight, config_parse_blockio_device_weight, 0, $1.BlockIOReadBandwidth, config_parse_blockio_bandwidth, 0, offsetof($1, cgroup_context) $1.BlockIOWriteBandwidth, config_parse_blockio_bandwidth, 0, offsetof($1, cgroup_context) $1.TasksAccounting, config_parse_bool, 0, offsetof($1, cgroup_context.tasks_accounting) -$1.TasksMax, config_parse_tasks_max, 0, offsetof($1, cgroup_context) +$1.TasksMax, config_parse_tasks_max, 0, offsetof($1, cgroup_context.tasks_max) $1.Delegate, config_parse_bool, 0, offsetof($1, cgroup_context.delegate) $1.NetClass, config_parse_netclass, 0, offsetof($1, cgroup_context)' )m4_dnl diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c index 62cad0a0c0..5d013de2e8 100644 --- a/src/core/load-fragment.c +++ b/src/core/load-fragment.c @@ -2991,12 +2991,11 @@ int config_parse_tasks_max( void *data, void *userdata) { - CGroupContext *c = data; - uint64_t u; + uint64_t *tasks_max = data, u; int r; if (isempty(rvalue) || streq(rvalue, "infinity")) { - c->tasks_max = (uint64_t) -1; + *tasks_max = (uint64_t) -1; return 0; } @@ -3006,7 +3005,7 @@ int config_parse_tasks_max( return 0; } - c->tasks_max = u; + *tasks_max = u; return 0; } diff --git a/src/core/main.c b/src/core/main.c index 0924b51a7d..f8e1d88335 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -126,6 +126,7 @@ static bool arg_default_cpu_accounting = false; static bool arg_default_blockio_accounting = false; static bool arg_default_memory_accounting = false; static bool arg_default_tasks_accounting = false; +static uint64_t arg_default_tasks_max = (uint64_t) -1; static void pager_open_if_enabled(void) { @@ -677,6 +678,7 @@ static int parse_config_file(void) { { "Manager", "DefaultBlockIOAccounting", config_parse_bool, 0, &arg_default_blockio_accounting }, { "Manager", "DefaultMemoryAccounting", config_parse_bool, 0, &arg_default_memory_accounting }, { "Manager", "DefaultTasksAccounting", config_parse_bool, 0, &arg_default_tasks_accounting }, + { "Manager", "DefaultTasksMax", config_parse_tasks_max, 0, &arg_default_tasks_max }, {} }; @@ -712,6 +714,7 @@ static void manager_set_defaults(Manager *m) { m->default_blockio_accounting = arg_default_blockio_accounting; m->default_memory_accounting = arg_default_memory_accounting; m->default_tasks_accounting = arg_default_tasks_accounting; + m->default_tasks_max = arg_default_tasks_max; manager_set_default_rlimits(m, arg_default_rlimit); manager_environment_add(m, NULL, arg_default_environment); diff --git a/src/core/manager.c b/src/core/manager.c index f695b8a66c..fd915d748c 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -577,6 +577,7 @@ int manager_new(ManagerRunningAs running_as, bool test_run, Manager **_m) { m->running_as = running_as; m->exit_code = _MANAGER_EXIT_CODE_INVALID; m->default_timer_accuracy_usec = USEC_PER_MINUTE; + m->default_tasks_max = (uint64_t) -1; /* Prepare log fields we can use for structured logging */ m->unit_log_field = unit_log_fields[running_as]; diff --git a/src/core/manager.h b/src/core/manager.h index bc3f02f872..b5b258f909 100644 --- a/src/core/manager.h +++ b/src/core/manager.h @@ -260,6 +260,7 @@ struct Manager { bool default_blockio_accounting; bool default_tasks_accounting; + uint64_t default_tasks_max; usec_t default_timer_accuracy_usec; struct rlimit *rlimit[_RLIMIT_MAX]; diff --git a/src/core/system.conf b/src/core/system.conf index 50668e12c4..63bff085eb 100644 --- a/src/core/system.conf +++ b/src/core/system.conf @@ -41,6 +41,7 @@ #DefaultBlockIOAccounting=no #DefaultMemoryAccounting=no #DefaultTasksAccounting=no +#DefaultTasksMax= #DefaultLimitCPU= #DefaultLimitFSIZE= #DefaultLimitDATA= diff --git a/src/core/unit.c b/src/core/unit.c index f553f24829..a5872ef30a 100644 --- a/src/core/unit.c +++ b/src/core/unit.c @@ -132,6 +132,9 @@ static void unit_init(Unit *u) { cc->blockio_accounting = u->manager->default_blockio_accounting; cc->memory_accounting = u->manager->default_memory_accounting; cc->tasks_accounting = u->manager->default_tasks_accounting; + + if (u->type != UNIT_SLICE) + cc->tasks_max = u->manager->default_tasks_max; } ec = unit_get_exec_context(u); -- cgit v1.2.3-54-g00ecf From 9ded9cd14cc03c67291b10a5c42ce5094ba0912f Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 13 Nov 2015 19:28:32 +0100 Subject: core: enable TasksMax= for all services by default, and set it to 512 Also, enable TasksAccounting= for all services by default, too. See: http://lists.freedesktop.org/archives/systemd-devel/2015-November/035006.html --- man/systemd-system.conf.xml | 6 ++++-- src/core/main.c | 4 ++-- src/core/manager.c | 3 ++- src/core/system.conf | 4 ++-- src/test/test-cgroup-mask.c | 10 ++++++++++ 5 files changed, 20 insertions(+), 7 deletions(-) (limited to 'src/core/main.c') diff --git a/man/systemd-system.conf.xml b/man/systemd-system.conf.xml index 0050f24f8e..ead52951da 100644 --- a/man/systemd-system.conf.xml +++ b/man/systemd-system.conf.xml @@ -317,7 +317,9 @@ MemoryAccounting= and TasksAccounting=. See systemd.resource-control5 - for details on the per-unit settings. + for details on the per-unit + settings. DefaulTasksAccounting= defaults + to on, the other three settings to off. @@ -328,7 +330,7 @@ systemd.resource-control5 for details. This setting applies to all unit types that support resource control settings, with the exception of slice - units. + units. Defaults to 512. diff --git a/src/core/main.c b/src/core/main.c index f8e1d88335..a09ce0f083 100644 --- a/src/core/main.c +++ b/src/core/main.c @@ -125,8 +125,8 @@ 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 bool arg_default_tasks_accounting = false; -static uint64_t arg_default_tasks_max = (uint64_t) -1; +static bool arg_default_tasks_accounting = true; +static uint64_t arg_default_tasks_max = UINT64_C(512); static void pager_open_if_enabled(void) { diff --git a/src/core/manager.c b/src/core/manager.c index fd915d748c..edff6758c5 100644 --- a/src/core/manager.c +++ b/src/core/manager.c @@ -577,7 +577,8 @@ int manager_new(ManagerRunningAs running_as, bool test_run, Manager **_m) { m->running_as = running_as; m->exit_code = _MANAGER_EXIT_CODE_INVALID; m->default_timer_accuracy_usec = USEC_PER_MINUTE; - m->default_tasks_max = (uint64_t) -1; + m->default_tasks_accounting = true; + m->default_tasks_max = UINT64_C(512); /* Prepare log fields we can use for structured logging */ m->unit_log_field = unit_log_fields[running_as]; diff --git a/src/core/system.conf b/src/core/system.conf index 63bff085eb..e2ded27333 100644 --- a/src/core/system.conf +++ b/src/core/system.conf @@ -40,8 +40,8 @@ #DefaultCPUAccounting=no #DefaultBlockIOAccounting=no #DefaultMemoryAccounting=no -#DefaultTasksAccounting=no -#DefaultTasksMax= +#DefaultTasksAccounting=yes +#DefaultTasksMax=512 #DefaultLimitCPU= #DefaultLimitFSIZE= #DefaultLimitDATA= diff --git a/src/test/test-cgroup-mask.c b/src/test/test-cgroup-mask.c index de6c421b82..85b0d607d6 100644 --- a/src/test/test-cgroup-mask.c +++ b/src/test/test-cgroup-mask.c @@ -40,6 +40,16 @@ static int test_cgroup_mask(void) { puts("manager_new: Permission denied. Skipping test."); return EXIT_TEST_SKIP; } + + /* Turn off all kinds of default accouning, so that we can + * verify the masks resulting of our configuration and nothing + * else. */ + m->default_cpu_accounting = + m->default_memory_accounting = + m->default_blockio_accounting = + m->default_tasks_accounting = false; + m->default_tasks_max = (uint64_t) -1; + assert_se(r >= 0); assert_se(manager_startup(m, serial, fdset) >= 0); -- cgit v1.2.3-54-g00ecf