1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-22 09:57:34 +03:00

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.
This commit is contained in:
Lennart Poettering 2015-11-13 17:13:55 +01:00
parent ecee72e1b6
commit 0af20ea2ee
10 changed files with 30 additions and 7 deletions

View File

@ -1,4 +1,4 @@
<?xml version='1.0'?> <!--*-nxml-*--> <?xml version='1.0'?> <!--*- Mode: nxml; nxml-child-indent: 2; indent-tabs-mode: nil -*-->
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" <!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
"http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd"> "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
@ -320,6 +320,17 @@
for details on the per-unit settings.</para></listitem> for details on the per-unit settings.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><varname>DefaultTasksMax=</varname></term>
<listitem><para>Configure the default value for the per-unit
<varname>TasksMax=</varname> setting. See
<citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
for details. This setting applies to all unit types that
support resource control settings, with the exception of slice
units.</para></listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><varname>DefaultLimitCPU=</varname></term> <term><varname>DefaultLimitCPU=</varname></term>
<term><varname>DefaultLimitFSIZE=</varname></term> <term><varname>DefaultLimitFSIZE=</varname></term>

View File

@ -241,7 +241,10 @@
see <ulink see <ulink
url="https://www.kernel.org/doc/Documentation/cgroups/pids.txt">pids.txt</ulink>.</para> url="https://www.kernel.org/doc/Documentation/cgroups/pids.txt">pids.txt</ulink>.</para>
<para>Implies <literal>TasksAccounting=true</literal>.</para> <para>Implies <literal>TasksAccounting=true</literal>. The
system default for this setting may be controlled with
<varname>DefaultTasksMax=</varname> in
<citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>

View File

@ -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("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("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("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_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), SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit, SD_BUS_VTABLE_UNPRIVILEGED),

View File

@ -126,7 +126,7 @@ $1.BlockIODeviceWeight, config_parse_blockio_device_weight, 0,
$1.BlockIOReadBandwidth, config_parse_blockio_bandwidth, 0, offsetof($1, cgroup_context) $1.BlockIOReadBandwidth, config_parse_blockio_bandwidth, 0, offsetof($1, cgroup_context)
$1.BlockIOWriteBandwidth, 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.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.Delegate, config_parse_bool, 0, offsetof($1, cgroup_context.delegate)
$1.NetClass, config_parse_netclass, 0, offsetof($1, cgroup_context)' $1.NetClass, config_parse_netclass, 0, offsetof($1, cgroup_context)'
)m4_dnl )m4_dnl

View File

@ -2991,12 +2991,11 @@ int config_parse_tasks_max(
void *data, void *data,
void *userdata) { void *userdata) {
CGroupContext *c = data; uint64_t *tasks_max = data, u;
uint64_t u;
int r; int r;
if (isempty(rvalue) || streq(rvalue, "infinity")) { if (isempty(rvalue) || streq(rvalue, "infinity")) {
c->tasks_max = (uint64_t) -1; *tasks_max = (uint64_t) -1;
return 0; return 0;
} }
@ -3006,7 +3005,7 @@ int config_parse_tasks_max(
return 0; return 0;
} }
c->tasks_max = u; *tasks_max = u;
return 0; return 0;
} }

View File

@ -126,6 +126,7 @@ static bool arg_default_cpu_accounting = false;
static bool arg_default_blockio_accounting = false; static bool arg_default_blockio_accounting = false;
static bool arg_default_memory_accounting = false; static bool arg_default_memory_accounting = false;
static bool arg_default_tasks_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) { 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", "DefaultBlockIOAccounting", config_parse_bool, 0, &arg_default_blockio_accounting },
{ "Manager", "DefaultMemoryAccounting", config_parse_bool, 0, &arg_default_memory_accounting }, { "Manager", "DefaultMemoryAccounting", config_parse_bool, 0, &arg_default_memory_accounting },
{ "Manager", "DefaultTasksAccounting", config_parse_bool, 0, &arg_default_tasks_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_blockio_accounting = arg_default_blockio_accounting;
m->default_memory_accounting = arg_default_memory_accounting; m->default_memory_accounting = arg_default_memory_accounting;
m->default_tasks_accounting = arg_default_tasks_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_set_default_rlimits(m, arg_default_rlimit);
manager_environment_add(m, NULL, arg_default_environment); manager_environment_add(m, NULL, arg_default_environment);

View File

@ -577,6 +577,7 @@ int manager_new(ManagerRunningAs running_as, bool test_run, Manager **_m) {
m->running_as = running_as; m->running_as = running_as;
m->exit_code = _MANAGER_EXIT_CODE_INVALID; m->exit_code = _MANAGER_EXIT_CODE_INVALID;
m->default_timer_accuracy_usec = USEC_PER_MINUTE; m->default_timer_accuracy_usec = USEC_PER_MINUTE;
m->default_tasks_max = (uint64_t) -1;
/* Prepare log fields we can use for structured logging */ /* Prepare log fields we can use for structured logging */
m->unit_log_field = unit_log_fields[running_as]; m->unit_log_field = unit_log_fields[running_as];

View File

@ -260,6 +260,7 @@ struct Manager {
bool default_blockio_accounting; bool default_blockio_accounting;
bool default_tasks_accounting; bool default_tasks_accounting;
uint64_t default_tasks_max;
usec_t default_timer_accuracy_usec; usec_t default_timer_accuracy_usec;
struct rlimit *rlimit[_RLIMIT_MAX]; struct rlimit *rlimit[_RLIMIT_MAX];

View File

@ -41,6 +41,7 @@
#DefaultBlockIOAccounting=no #DefaultBlockIOAccounting=no
#DefaultMemoryAccounting=no #DefaultMemoryAccounting=no
#DefaultTasksAccounting=no #DefaultTasksAccounting=no
#DefaultTasksMax=
#DefaultLimitCPU= #DefaultLimitCPU=
#DefaultLimitFSIZE= #DefaultLimitFSIZE=
#DefaultLimitDATA= #DefaultLimitDATA=

View File

@ -132,6 +132,9 @@ static void unit_init(Unit *u) {
cc->blockio_accounting = u->manager->default_blockio_accounting; cc->blockio_accounting = u->manager->default_blockio_accounting;
cc->memory_accounting = u->manager->default_memory_accounting; cc->memory_accounting = u->manager->default_memory_accounting;
cc->tasks_accounting = u->manager->default_tasks_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); ec = unit_get_exec_context(u);