chiark / gitweb /
core: add global settings for enabling CPUAccounting=, MemoryAccounting=, BlockIOAcco...
authorLennart Poettering <lennart@poettering.net>
Mon, 24 Feb 2014 22:50:10 +0000 (23:50 +0100)
committerLennart Poettering <lennart@poettering.net>
Mon, 24 Feb 2014 22:50:10 +0000 (23:50 +0100)
13 files changed:
man/systemd-system.conf.xml
man/systemd.resource-control.xml
src/core/main.c
src/core/manager.h
src/core/mount.c
src/core/scope.c
src/core/service.c
src/core/slice.c
src/core/socket.c
src/core/swap.c
src/core/system.conf
src/core/unit.c
src/core/unit.h

index f3a89ad..a7dfc03 100644 (file)
                                 <varname>TimeoutStartSec=</varname>,
                                 <varname>TimeoutStopSec=</varname> and
                                 <varname>RestartSec=</varname> (for
-                                service units, see
+                                services, see
                                 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
                                 for details on the per-unit
                                 settings). For non-service units,
                                 <varname>TimeoutSec=</varname> value.
                                 </para></listitem>
                         </varlistentry>
+
                         <varlistentry>
                                 <term><varname>DefaultStartLimitInterval=</varname></term>
                                 <term><varname>DefaultStartLimitBurst=</varname></term>
 
-                                <listitem><para>Configure the default start rate
-                                limiting, as configured per-service by
-                                <varname>StartLimitInterval=</varname> and
+                                <listitem><para>Configure the default
+                                unit start rate limiting, as
+                                configured per-service by
+                                <varname>StartLimitInterval=</varname>
+                                and
                                 <varname>StartLimitBurst=</varname>. See
                                 <citerefentry><refentrytitle>systemd.service</refentrytitle><manvolnum>5</manvolnum></citerefentry>
                                 for details on the per-service
-                                settings).
-                                </para></listitem>
+                                settings.</para></listitem>
                         </varlistentry>
 
                         <varlistentry>
                         </varlistentry>
 
                         <varlistentry>
+                                <term><varname>DefaultCPUAccounting=</varname></term>
+                                <term><varname>DefaultBlockIOAccounting=</varname></term>
+                                <term><varname>DefaultMemoryAccounting=</varname></term>
+
+                                <listitem><para>Configure the default
+                                resource accounting settings, as
+                                configured per-unit by
+                                <varname>CPUAccounting=</varname>,
+                                <varname>BlockIOAccounting=</varname>
+                                and
+                                <varname>MemoryAccounting=</varname>. See
+                                <citerefentry><refentrytitle>systemd.resource-control</refentrytitle><manvolnum>5</manvolnum></citerefentry>
+                                for details on the per-unit
+                                settings.</para></listitem>
+                        </varlistentry>
+
+                        <varlistentry>
                                 <term><varname>DefaultLimitCPU=</varname></term>
                                 <term><varname>DefaultLimitFSIZE=</varname></term>
                                 <term><varname>DefaultLimitDATA=</varname></term>
index e923b6d..c3fd5fc 100644 (file)
@@ -105,8 +105,11 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
           <para>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.</para>
+          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
+          <varname>DefaultCPUAccounting=</varname> in
+          <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
         </listitem>
       </varlistentry>
 
@@ -132,8 +135,10 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
           <para>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.</para>
+          all its parent slices. The system default for this setting
+          maybe controlled with
+          <varname>DefaultMemoryAccounting=</varname> in
+          <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
         </listitem>
       </varlistentry>
 
@@ -164,8 +169,11 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>.
           <para>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.</para>
+          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
+          <varname>DefaultBlockIOAccounting=</varname> in
+          <citerefentry><refentrytitle>systemd-system.conf</refentrytitle><manvolnum>5</manvolnum></citerefentry>.</para>
         </listitem>
       </varlistentry>
 
index 4e24f85..d3581fc 100644 (file)
@@ -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;
index 948ea98..9dee48d 100644 (file)
@@ -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, */
index a0cea1e..814674a 100644 (file)
@@ -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;
 
index 16758fe..be2a637 100644 (file)
@@ -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;
 }
index ca71788..6977774 100644 (file)
@@ -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;
         }
index 1e42df2..ae9a54b 100644 (file)
@@ -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) {
index 0ccda2f..8e39032 100644 (file)
@@ -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;
 
index 24c4611..96cf38a 100644 (file)
@@ -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;
         }
index 7a2d7b4..5be158d 100644 (file)
@@ -31,6 +31,9 @@
 #DefaultStartLimitInterval=10s
 #DefaultStartLimitBurst=5
 #DefaultEnvironment=
+#DefaultCPUAccounting=no
+#DefaultBlockIOAccounting=no
+#DefaultMemoryAccounting=no
 #DefaultLimitCPU=
 #DefaultLimitFSIZE=
 #DefaultLimitDATA=
index 1bbcb39..9d54147 100644 (file)
@@ -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]) {
index 808929e..34afe93 100644 (file)
@@ -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_;