summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-02-24 23:50:10 +0100
committerLennart Poettering <lennart@poettering.net>2014-02-24 23:50:10 +0100
commit085afe36cb823e7d5b8c5f3ef21ebb9639bac78b (patch)
tree25b26a8b92d8562983b22098d0dfe5777efc8927
parent4e72e29a390e0bd9226eb802d80b9a9c259565cd (diff)
core: add global settings for enabling CPUAccounting=, MemoryAccounting=, BlockIOAccounting= for all units at once
-rw-r--r--man/systemd-system.conf.xml31
-rw-r--r--man/systemd.resource-control.xml20
-rw-r--r--src/core/main.c9
-rw-r--r--src/core/manager.h7
-rw-r--r--src/core/mount.c4
-rw-r--r--src/core/scope.c2
-rw-r--r--src/core/service.c8
-rw-r--r--src/core/slice.c1
-rw-r--r--src/core/socket.c4
-rw-r--r--src/core/swap.c4
-rw-r--r--src/core/system.conf3
-rw-r--r--src/core/unit.c19
-rw-r--r--src/core/unit.h3
13 files changed, 92 insertions, 23 deletions
diff --git a/man/systemd-system.conf.xml b/man/systemd-system.conf.xml
index f3a89ad459..a7dfc0329c 100644
--- a/man/systemd-system.conf.xml
+++ b/man/systemd-system.conf.xml
@@ -292,7 +292,7 @@
<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,
@@ -301,18 +301,20 @@
<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>
@@ -338,6 +340,23 @@
</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>
diff --git a/man/systemd.resource-control.xml b/man/systemd.resource-control.xml
index e923b6da86..c3fd5fcee4 100644
--- a/man/systemd.resource-control.xml
+++ b/man/systemd.resource-control.xml
@@ -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>
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_;