summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2010-08-31 01:33:39 +0200
committerLennart Poettering <lennart@poettering.net>2010-08-31 01:33:43 +0200
commitdd6c17b1595ff8a78ebae6cf571fd222c80bfd17 (patch)
tree1c3409f81d533008deeb3725b27b1f2de57e204a
parent71916d3fff97c6026b5e8bb2c8e4169ab14dc3ad (diff)
exec: replace OOMAdjust= by OOMScoreAdjust= to follow new kernel interface
This replaces OOMAdjust= by OOMScoreAdjust= in the config files, breaking compatibility with older unit files. However, this keeps compat with older kernels which lack the new OOM rework.
-rw-r--r--fixme4
-rw-r--r--man/systemd.exec.xml6
-rw-r--r--src/dbus-execute.c16
-rw-r--r--src/dbus-execute.h6
-rw-r--r--src/execute.c30
-rw-r--r--src/execute.h4
-rw-r--r--src/load-fragment.c16
-rw-r--r--src/missing.h23
-rw-r--r--test1/systemd-logger.service2
9 files changed, 69 insertions, 38 deletions
diff --git a/fixme b/fixme
index f244b5cb89..38f92a4c2c 100644
--- a/fixme
+++ b/fixme
@@ -82,10 +82,6 @@ v9:
* follow LSB exit codes spec in "systemctl start"
-* oom_score_adj
-
-* rename failed/maintenance https://bugzilla.redhat.com/show_bug.cgi?id=614619
-
* systemctl wrapping https://bugzilla.redhat.com/show_bug.cgi?id=626891 https://bugzilla.redhat.com/show_bug.cgi?id=626443
External:
diff --git a/man/systemd.exec.xml b/man/systemd.exec.xml
index a47a62daec..c71d42912b 100644
--- a/man/systemd.exec.xml
+++ b/man/systemd.exec.xml
@@ -146,13 +146,13 @@
</varlistentry>
<varlistentry>
- <term><varname>OOMAdjust=</varname></term>
+ <term><varname>OOMScoreAdjust=</varname></term>
<listitem><para>Sets the adjustment
level for the Out-Of-Memory killer for
executed processes. Takes an integer
- between -17 (to disable OOM killing
- for this process) and 15 (to make
+ between -1000 (to disable OOM killing
+ for this process) and 1000 (to make
killing of this process under memory
pressure very likely). See <ulink
url="http://www.kernel.org/doc/Documentation/filesystems/proc.txt">proc.txt</ulink>
diff --git a/src/dbus-execute.c b/src/dbus-execute.c
index 4f8a3da0d1..cdc15b25ce 100644
--- a/src/dbus-execute.c
+++ b/src/dbus-execute.c
@@ -33,7 +33,7 @@ DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_kill_mode, kill_mode, KillMod
DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_input, exec_input, ExecInput);
DEFINE_BUS_PROPERTY_APPEND_ENUM(bus_execute_append_output, exec_output, ExecOutput);
-int bus_execute_append_oom_adjust(Manager *m, DBusMessageIter *i, const char *property, void *data) {
+int bus_execute_append_oom_score_adjust(Manager *m, DBusMessageIter *i, const char *property, void *data) {
ExecContext *c = data;
int32_t n;
@@ -42,15 +42,23 @@ int bus_execute_append_oom_adjust(Manager *m, DBusMessageIter *i, const char *pr
assert(property);
assert(c);
- if (c->oom_adjust_set)
- n = c->oom_adjust;
+ if (c->oom_score_adjust_set)
+ n = c->oom_score_adjust;
else {
char *t;
n = 0;
- if (read_one_line_file("/proc/self/oom_adj", &t) >= 0) {
+ if (read_one_line_file("/proc/self/oom_score_adj", &t) >= 0) {
safe_atoi(t, &n);
free(t);
+ } else if (read_one_line_file("/proc/self/oom_adj", &t) >= 0) {
+ safe_atoi(t, &n);
+ free(t);
+
+ if (n == OOM_ADJUST_MAX)
+ n = OOM_SCORE_ADJ_MAX;
+ else
+ n = (n * OOM_SCORE_ADJ_MAX) / -OOM_DISABLE;
}
}
diff --git a/src/dbus-execute.h b/src/dbus-execute.h
index 03a474ede2..f1814315f7 100644
--- a/src/dbus-execute.h
+++ b/src/dbus-execute.h
@@ -54,7 +54,7 @@
" <property name=\"LimitRTTIME\" type=\"t\" access=\"read\"/>\n" \
" <property name=\"WorkingDirectory\" type=\"s\" access=\"read\"/>\n" \
" <property name=\"RootDirectory\" type=\"s\" access=\"read\"/>\n" \
- " <property name=\"OOMAdjust\" type=\"i\" access=\"read\"/>\n" \
+ " <property name=\"OOMScoreAdjust\" type=\"i\" access=\"read\"/>\n" \
" <property name=\"Nice\" type=\"i\" access=\"read\"/>\n" \
" <property name=\"IOScheduling\" type=\"i\" access=\"read\"/>\n" \
" <property name=\"CPUSchedulingPolicy\" type=\"i\" access=\"read\"/>\n" \
@@ -111,7 +111,7 @@
{ interface, "LimitRTTIME", bus_execute_append_rlimits, "t", &(context) }, \
{ interface, "WorkingDirectory", bus_property_append_string, "s", (context).working_directory }, \
{ interface, "RootDirectory", bus_property_append_string, "s", (context).root_directory }, \
- { interface, "OOMAdjust", bus_execute_append_oom_adjust, "i", &(context) }, \
+ { interface, "OOMScoreAdjust", bus_execute_append_oom_score_adjust, "i", &(context) }, \
{ interface, "Nice", bus_execute_append_nice, "i", &(context) }, \
{ interface, "IOScheduling", bus_execute_append_ioprio, "i", &(context) }, \
{ interface, "CPUSchedulingPolicy", bus_execute_append_cpu_sched_policy, "i", &(context) }, \
@@ -156,7 +156,7 @@
int bus_execute_append_output(Manager *m, DBusMessageIter *i, const char *property, void *data);
int bus_execute_append_input(Manager *m, DBusMessageIter *i, const char *property, void *data);
-int bus_execute_append_oom_adjust(Manager *m, DBusMessageIter *i, const char *property, void *data);
+int bus_execute_append_oom_score_adjust(Manager *m, DBusMessageIter *i, const char *property, void *data);
int bus_execute_append_nice(Manager *m, DBusMessageIter *i, const char *property, void *data);
int bus_execute_append_ioprio(Manager *m, DBusMessageIter *i, const char *property, void *data);
int bus_execute_append_cpu_sched_policy(Manager *m, DBusMessageIter *i, const char *property, void *data);
diff --git a/src/execute.c b/src/execute.c
index 2443d9c74d..755b4700fc 100644
--- a/src/execute.c
+++ b/src/execute.c
@@ -36,6 +36,7 @@
#include <pwd.h>
#include <sys/mount.h>
#include <linux/fs.h>
+#include <linux/oom.h>
#ifdef HAVE_PAM
#include <security/pam_appl.h>
@@ -52,6 +53,7 @@
#include "namespace.h"
#include "tcpwrap.h"
#include "exit-status.h"
+#include "missing.h"
/* This assumes there is a 'tty' group */
#define TTY_MODE 0620
@@ -1066,15 +1068,27 @@ int exec_spawn(ExecCommand *command,
goto fail;
}
- if (context->oom_adjust_set) {
+ if (context->oom_score_adjust_set) {
char t[16];
- snprintf(t, sizeof(t), "%i", context->oom_adjust);
+ snprintf(t, sizeof(t), "%i", context->oom_score_adjust);
char_array_0(t);
- if (write_one_line_file("/proc/self/oom_adj", t) < 0) {
- r = EXIT_OOM_ADJUST;
- goto fail;
+ if (write_one_line_file("/proc/self/oom_score_adj", t) < 0) {
+ /* Compatibility with Linux <= 2.6.35 */
+
+ int adj;
+
+ adj = (context->oom_score_adjust * -OOM_DISABLE) / OOM_SCORE_ADJ_MAX;
+ adj = CLAMP(adj, OOM_DISABLE, OOM_ADJUST_MAX);
+
+ snprintf(t, sizeof(t), "%i", adj);
+ char_array_0(t);
+
+ if (write_one_line_file("/proc/self/oom_adj", t) < 0) {
+ r = EXIT_OOM_ADJUST;
+ goto fail;
+ }
}
}
@@ -1461,10 +1475,10 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) {
"%sNice: %i\n",
prefix, c->nice);
- if (c->oom_adjust_set)
+ if (c->oom_score_adjust_set)
fprintf(f,
- "%sOOMAdjust: %i\n",
- prefix, c->oom_adjust);
+ "%sOOMScoreAdjust: %i\n",
+ prefix, c->oom_score_adjust);
for (i = 0; i < RLIM_NLIMITS; i++)
if (c->rlimit[i])
diff --git a/src/execute.h b/src/execute.h
index 0dc5a1d252..31cce5d7d2 100644
--- a/src/execute.h
+++ b/src/execute.h
@@ -97,7 +97,7 @@ struct ExecContext {
char *working_directory, *root_directory;
mode_t umask;
- int oom_adjust;
+ int oom_score_adjust;
int nice;
int ioprio;
int cpu_sched_policy;
@@ -153,7 +153,7 @@ struct ExecContext {
* don't enter a trigger loop. */
bool same_pgrp;
- bool oom_adjust_set:1;
+ bool oom_score_adjust_set:1;
bool nice_set:1;
bool ioprio_set:1;
bool cpu_sched_set:1;
diff --git a/src/load-fragment.c b/src/load-fragment.c
index c9ed6798ae..636de8d103 100644
--- a/src/load-fragment.c
+++ b/src/load-fragment.c
@@ -299,7 +299,7 @@ static int config_parse_nice(
return 0;
}
-static int config_parse_oom_adjust(
+static int config_parse_oom_score_adjust(
const char *filename,
unsigned line,
const char *section,
@@ -317,17 +317,17 @@ static int config_parse_oom_adjust(
assert(data);
if ((r = safe_atoi(rvalue, &oa)) < 0) {
- log_error("[%s:%u] Failed to parse OOM adjust value, ignoring: %s", filename, line, rvalue);
+ log_error("[%s:%u] Failed to parse the OOM score adjust value, ignoring: %s", filename, line, rvalue);
return 0;
}
- if (oa < OOM_DISABLE || oa > OOM_ADJUST_MAX) {
- log_error("[%s:%u] OOM adjust value out of range, ignoring: %s", filename, line, rvalue);
+ if (oa < OOM_SCORE_ADJ_MIN || oa > OOM_SCORE_ADJ_MAX) {
+ log_error("[%s:%u] OOM score adjust value out of range, ignoring: %s", filename, line, rvalue);
return 0;
}
- c->oom_adjust = oa;
- c->oom_adjust_set = true;
+ c->oom_score_adjust = oa;
+ c->oom_score_adjust_set = true;
return 0;
}
@@ -1425,7 +1425,7 @@ static void dump_items(FILE *f, const ConfigItem *items) {
{ config_parse_path, "PATH" },
{ config_parse_strv, "STRING [...]" },
{ config_parse_nice, "NICE" },
- { config_parse_oom_adjust, "OOMADJUST" },
+ { config_parse_oom_score_adjust, "OOMSCOREADJUST" },
{ config_parse_io_class, "IOCLASS" },
{ config_parse_io_priority, "IOPRIORITY" },
{ config_parse_cpu_sched_policy, "CPUSCHEDPOLICY" },
@@ -1515,7 +1515,7 @@ static int load_from_path(Unit *u, const char *path) {
{ "Group", config_parse_string_printf, &(context).group, section }, \
{ "SupplementaryGroups", config_parse_strv, &(context).supplementary_groups, section }, \
{ "Nice", config_parse_nice, &(context), section }, \
- { "OOMAdjust", config_parse_oom_adjust, &(context), section }, \
+ { "OOMScoreAdjust", config_parse_oom_score_adjust,&(context), section }, \
{ "IOSchedulingClass", config_parse_io_class, &(context), section }, \
{ "IOSchedulingPriority", config_parse_io_priority, &(context), section }, \
{ "CPUSchedulingPolicy", config_parse_cpu_sched_policy,&(context), section }, \
diff --git a/src/missing.h b/src/missing.h
index eaeeeab19f..418dbb8c0d 100644
--- a/src/missing.h
+++ b/src/missing.h
@@ -28,6 +28,11 @@
#include <sys/syscall.h>
#include <fcntl.h>
#include <unistd.h>
+#include <linux/oom.h>
+
+#ifdef HAVE_AUDIT
+#include <libaudit.h>
+#endif
#include "macro.h"
@@ -51,16 +56,24 @@
#define IP_FREEBIND 15
#endif
-static inline int pivot_root(const char *new_root, const char *put_old) {
- return syscall(SYS_pivot_root, new_root, put_old);
-}
+#ifndef OOM_SCORE_ADJ_MIN
+#define OOM_SCORE_ADJ_MIN (-1000)
+#endif
+
+#ifndef OOM_SCORE_ADJ_MAX
+#define OOM_SCORE_ADJ_MAX 1000
+#endif
#ifndef AUDIT_SERVICE_START
-#define AUDIT_SERVICE_START 1130 /* Service (daemon) start */
+#define AUDIT_SERVICE_START 1130 /* Service (daemon) start */
#endif
#ifndef AUDIT_SERVICE_STOP
-#define AUDIT_SERVICE_STOP 1131 /* Service (daemon) stop */
+#define AUDIT_SERVICE_STOP 1131 /* Service (daemon) stop */
#endif
+static inline int pivot_root(const char *new_root, const char *put_old) {
+ return syscall(SYS_pivot_root, new_root, put_old);
+}
+
#endif
diff --git a/test1/systemd-logger.service b/test1/systemd-logger.service
index e817909433..c406d26f35 100644
--- a/test1/systemd-logger.service
+++ b/test1/systemd-logger.service
@@ -5,7 +5,7 @@ Description=systemd Logging Daemon
ExecStart=/home/lennart/projects/systemd/systemd-logger
Type=simple
TimerSlackNS=1000000
-OOMAdjust=4
+OOMScoreAdjust=40
LimitCORE=0
LimitFSIZE=0
LimitLOCKS=0