daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
803fb7
From fc7fdb72096d2baeec3238a0ef324569a05da4ae Mon Sep 17 00:00:00 2001
803fb7
From: Lennart Poettering <lennart@poettering.net>
803fb7
Date: Fri, 13 Nov 2015 17:13:55 +0100
803fb7
Subject: [PATCH] core: add new DefaultTasksMax= setting for system.conf
803fb7
803fb7
This allows initializing the TasksMax= setting of all units by default
803fb7
to some fixed value, instead of leaving it at infinity as before.
803fb7
803fb7
Cherry-picked from: 0af20ea2ee2af2bcf2258e7a8e1a13181a6a75d6
803fb7
Related: #1337244
803fb7
---
803fb7
 man/systemd-system.conf.xml           | 13 ++++++++++++-
803fb7
 man/systemd.resource-control.xml      |  5 ++++-
803fb7
 src/core/dbus-manager.c               |  1 +
803fb7
 src/core/load-fragment-gperf.gperf.m4 |  2 +-
803fb7
 src/core/load-fragment.c              |  7 ++++---
803fb7
 src/core/main.c                       |  3 +++
803fb7
 src/core/manager.h                    |  1 +
803fb7
 src/core/system.conf                  |  2 ++
803fb7
 src/core/unit.c                       |  3 +++
803fb7
 src/shared/cgroup-util.c              |  3 ++-
803fb7
 10 files changed, 33 insertions(+), 7 deletions(-)
803fb7
803fb7
diff --git a/man/systemd-system.conf.xml b/man/systemd-system.conf.xml
803fb7
index d367ccd13..53e8ff665 100644
803fb7
--- a/man/systemd-system.conf.xml
803fb7
+++ b/man/systemd-system.conf.xml
803fb7
@@ -1,4 +1,4 @@
803fb7
- 
803fb7
+ 
803fb7
 
803fb7
   "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
803fb7
 
803fb7
@@ -319,6 +319,17 @@
803fb7
         for details on the per-unit settings.</para></listitem>
803fb7
       </varlistentry>
803fb7
 
803fb7
+      <varlistentry>
803fb7
+        <term><varname>DefaultTasksMax=</varname></term>
803fb7
+
803fb7
+        <listitem><para>Configure the default value for the per-unit
803fb7
+        <varname>TasksMax=</varname> setting. See
803fb7
+        <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
803fb7
+        for details. This setting applies to all unit types that
803fb7
+        support resource control settings, with the exception of slice
803fb7
+        units.</para></listitem>
803fb7
+      </varlistentry>
803fb7
+
803fb7
       <varlistentry>
803fb7
         <term><varname>DefaultLimitCPU=</varname></term>
803fb7
         <term><varname>DefaultLimitFSIZE=</varname></term>
803fb7
diff --git a/man/systemd.resource-control.xml b/man/systemd.resource-control.xml
803fb7
index 6b9329bbe..217105ee5 100644
803fb7
--- a/man/systemd.resource-control.xml
803fb7
+++ b/man/systemd.resource-control.xml
803fb7
@@ -231,7 +231,10 @@
803fb7
           see 
803fb7
           url="https://www.kernel.org/doc/Documentation/cgroups/pids.txt">pids.txt</ulink>.</para>
803fb7
 
803fb7
-          <para>Implies <literal>TasksAccounting=true</literal>.</para>
803fb7
+          <para>Implies <literal>TasksAccounting=true</literal>. The
803fb7
+          system default for this setting may be controlled with
803fb7
+          <varname>DefaultTasksMax=</varname> in
803fb7
+          <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
803fb7
         </listitem>
803fb7
       </varlistentry>
803fb7
 
803fb7
diff --git a/src/core/dbus-manager.c b/src/core/dbus-manager.c
803fb7
index 7ba1b519e..c92f8c6bf 100644
803fb7
--- a/src/core/dbus-manager.c
803fb7
+++ b/src/core/dbus-manager.c
803fb7
@@ -2039,6 +2039,7 @@ const sd_bus_vtable bus_manager_vtable[] = {
803fb7
         SD_BUS_WRITABLE_PROPERTY("ShutdownWatchdogUSec", "t", bus_property_get_usec, bus_property_set_usec, offsetof(Manager, shutdown_watchdog), 0),
803fb7
         SD_BUS_PROPERTY("ControlGroup", "s", NULL, offsetof(Manager, cgroup_root), 0),
803fb7
         SD_BUS_PROPERTY("SystemState", "s", property_get_system_state, 0, 0),
803fb7
+        SD_BUS_PROPERTY("DefaultTasksMax", "t", NULL, offsetof(Manager, default_tasks_max), SD_BUS_VTABLE_PROPERTY_CONST),
803fb7
 
803fb7
         SD_BUS_METHOD("GetUnit", "s", "o", method_get_unit, SD_BUS_VTABLE_UNPRIVILEGED),
803fb7
         SD_BUS_METHOD("GetUnitByPID", "u", "o", method_get_unit_by_pid, SD_BUS_VTABLE_UNPRIVILEGED),
803fb7
diff --git a/src/core/load-fragment-gperf.gperf.m4 b/src/core/load-fragment-gperf.gperf.m4
803fb7
index 26e4c618e..b2fe627af 100644
803fb7
--- a/src/core/load-fragment-gperf.gperf.m4
803fb7
+++ b/src/core/load-fragment-gperf.gperf.m4
803fb7
@@ -126,7 +126,7 @@ $1.BlockIODeviceWeight,          config_parse_blockio_device_weight, 0,
803fb7
 $1.BlockIOReadBandwidth,         config_parse_blockio_bandwidth,     0,                             offsetof($1, cgroup_context)
803fb7
 $1.BlockIOWriteBandwidth,        config_parse_blockio_bandwidth,     0,                             offsetof($1, cgroup_context)
803fb7
 $1.TasksAccounting,              config_parse_bool,                  0,                             offsetof($1, cgroup_context.tasks_accounting)
803fb7
-$1.TasksMax,                     config_parse_tasks_max,             0,                             offsetof($1, cgroup_context)
803fb7
+$1.TasksMax,                     config_parse_tasks_max,             0,                             offsetof($1, cgroup_context.tasks_max)
803fb7
 $1.Delegate,                     config_parse_bool,                  0,                             offsetof($1, cgroup_context.delegate)'
803fb7
 )m4_dnl
803fb7
 Unit.Description,                config_parse_unit_string_printf,    0,                             offsetof(Unit, description)
803fb7
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
803fb7
index 7d2e737d0..c1ffee2c7 100644
803fb7
--- a/src/core/load-fragment.c
803fb7
+++ b/src/core/load-fragment.c
803fb7
@@ -3081,12 +3081,11 @@ int config_parse_tasks_max(
803fb7
                 void *data,
803fb7
                 void *userdata) {
803fb7
 
803fb7
-        CGroupContext *c = data;
803fb7
-        uint64_t u;
803fb7
+        uint64_t *tasks_max = data, u;
803fb7
         int r;
803fb7
 
803fb7
         if (isempty(rvalue) || streq(rvalue, "infinity")) {
803fb7
-                c->tasks_max = (uint64_t) -1;
803fb7
+                *tasks_max = (uint64_t) -1;
803fb7
                 return 0;
803fb7
         }
803fb7
 
803fb7
@@ -3096,6 +3095,8 @@ int config_parse_tasks_max(
803fb7
                 return 0;
803fb7
         }
803fb7
 
803fb7
+        *tasks_max = u;
803fb7
+
803fb7
         return 0;
803fb7
 }
803fb7
 
803fb7
diff --git a/src/core/main.c b/src/core/main.c
803fb7
index aca05a535..50c9714f7 100644
803fb7
--- a/src/core/main.c
803fb7
+++ b/src/core/main.c
803fb7
@@ -118,6 +118,7 @@ static bool arg_default_blockio_accounting = false;
803fb7
 static bool arg_default_memory_accounting = false;
803fb7
 static EmergencyAction arg_cad_burst_action = EMERGENCY_ACTION_REBOOT_FORCE;
803fb7
 static bool arg_default_tasks_accounting = false;
803fb7
+static uint64_t arg_default_tasks_max = (uint64_t) -1;
803fb7
 
803fb7
 static void nop_handler(int sig) {}
803fb7
 
803fb7
@@ -678,6 +679,7 @@ static int parse_config_file(void) {
803fb7
                 { "Manager", "DefaultMemoryAccounting",   config_parse_bool,             0, &arg_default_memory_accounting         },
803fb7
                 { "Manager", "CtrlAltDelBurstAction",     config_parse_emergency_action, 0, &arg_cad_burst_action                  },
803fb7
                 { "Manager", "DefaultTasksAccounting",    config_parse_bool,             0, &arg_default_tasks_accounting          },
803fb7
+                { "Manager", "DefaultTasksMax",           config_parse_tasks_max,        0, &arg_default_tasks_max                 },
803fb7
                 {}
803fb7
         };
803fb7
 
803fb7
@@ -1688,6 +1690,7 @@ int main(int argc, char *argv[]) {
803fb7
         m->default_blockio_accounting = arg_default_blockio_accounting;
803fb7
         m->default_memory_accounting = arg_default_memory_accounting;
803fb7
         m->default_tasks_accounting = arg_default_tasks_accounting;
803fb7
+        m->default_tasks_max = arg_default_tasks_max;
803fb7
         m->runtime_watchdog = arg_runtime_watchdog;
803fb7
         m->shutdown_watchdog = arg_shutdown_watchdog;
803fb7
 
803fb7
diff --git a/src/core/manager.h b/src/core/manager.h
803fb7
index 96dcd83dc..e91e7bd8b 100644
803fb7
--- a/src/core/manager.h
803fb7
+++ b/src/core/manager.h
803fb7
@@ -263,6 +263,7 @@ struct Manager {
803fb7
         bool default_blockio_accounting;
803fb7
         bool default_tasks_accounting;
803fb7
 
803fb7
+        uint64_t default_tasks_max;
803fb7
         usec_t default_timer_accuracy_usec;
803fb7
 
803fb7
         struct rlimit *rlimit[_RLIMIT_MAX];
803fb7
diff --git a/src/core/system.conf b/src/core/system.conf
803fb7
index a11f59903..91ef01cd0 100644
803fb7
--- a/src/core/system.conf
803fb7
+++ b/src/core/system.conf
803fb7
@@ -40,6 +40,8 @@
803fb7
 #DefaultCPUAccounting=no
803fb7
 #DefaultBlockIOAccounting=no
803fb7
 #DefaultMemoryAccounting=no
803fb7
+#DefaultTasksAccounting=no
803fb7
+#DefaultTasksMax=
803fb7
 #DefaultLimitCPU=
803fb7
 #DefaultLimitFSIZE=
803fb7
 #DefaultLimitDATA=
803fb7
diff --git a/src/core/unit.c b/src/core/unit.c
803fb7
index 2fcb4fbf0..6a2ad6ed3 100644
803fb7
--- a/src/core/unit.c
803fb7
+++ b/src/core/unit.c
803fb7
@@ -127,6 +127,9 @@ static void unit_init(Unit *u) {
803fb7
                 cc->blockio_accounting = u->manager->default_blockio_accounting;
803fb7
                 cc->memory_accounting = u->manager->default_memory_accounting;
803fb7
                 cc->tasks_accounting = u->manager->default_tasks_accounting;
803fb7
+
803fb7
+                if (u->type != UNIT_SLICE)
803fb7
+                        cc->tasks_max = u->manager->default_tasks_max;
803fb7
         }
803fb7
 
803fb7
         ec = unit_get_exec_context(u);
803fb7
diff --git a/src/shared/cgroup-util.c b/src/shared/cgroup-util.c
803fb7
index cf757d2b2..c5d9e4bb5 100644
803fb7
--- a/src/shared/cgroup-util.c
803fb7
+++ b/src/shared/cgroup-util.c
803fb7
@@ -1606,7 +1606,8 @@ static const char mask_names[] =
803fb7
         "cpuacct\0"
803fb7
         "blkio\0"
803fb7
         "memory\0"
803fb7
-        "devices\0";
803fb7
+        "devices\0"
803fb7
+        "pids\0";
803fb7
 
803fb7
 int cg_create_everywhere(CGroupControllerMask supported, CGroupControllerMask mask, const char *path) {
803fb7
         CGroupControllerMask bit = 1;