chiark / gitweb /
exec: replace OOMAdjust= by OOMScoreAdjust= to follow new kernel interface
authorLennart Poettering <lennart@poettering.net>
Mon, 30 Aug 2010 23:33:39 +0000 (01:33 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 30 Aug 2010 23:33:43 +0000 (01:33 +0200)
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.

fixme
man/systemd.exec.xml
src/dbus-execute.c
src/dbus-execute.h
src/execute.c
src/execute.h
src/load-fragment.c
src/missing.h
test1/systemd-logger.service

diff --git a/fixme b/fixme
index f244b5cb8946c71856a14e7f23c784494ee5057f..38f92a4c2cc2f3cda39040dd84b6486a9d744fef 100644 (file)
--- 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:
index a47a62daec890a4fe4ef93b252c2456cae65041e..c71d42912bf0d634d3ab3132542f8a596e14e665 100644 (file)
                         </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>
index 4f8a3da0d17f28a8f46a73321f1f32ba19c4238e..cdc15b25cef15f9902654ac910d8c25d70aa6301 100644 (file)
@@ -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;
                 }
         }
 
index 03a474ede250b3c82868b73dfec9a45fb8f32c3a..f1814315f7ab8353bf68ab907b45ca62fb6895fa 100644 (file)
@@ -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" \
         { 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)                         }, \
 
 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);
index 2443d9c74d08e65c543ebed36350bed31593d5d6..755b4700fc0c02fbbe1bcb1b03459ff45998e6db 100644 (file)
@@ -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])
index 0dc5a1d252a14a0a5fb75bd3f0a9cee07cefd02d..31cce5d7d289bf401158b2e5a1b5387ac891e4e0 100644 (file)
@@ -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;
index c9ed6798ae2adc06af3ff3e5c06cba53d8fe40f9..636de8d1036f7461a99b84a65e025c805b0c71fd 100644 (file)
@@ -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   }, \
index eaeeeab19f6ae36dc90a319c75feac832702221c..418dbb8c0dae8f8b872176623c78d1228ac7f24a 100644 (file)
 #include <sys/syscall.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <linux/oom.h>
+
+#ifdef HAVE_AUDIT
+#include <libaudit.h>
+#endif
 
 #include "macro.h"
 
 #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
index e817909433b1269aa8e9bc727811c65b9696b6b3..c406d26f3579606d50edf7cf469d8e701e5a032c 100644 (file)
@@ -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