* 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:
</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>
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;
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;
}
}
" <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);
#include <pwd.h>
#include <sys/mount.h>
#include <linux/fs.h>
+#include <linux/oom.h>
#ifdef HAVE_PAM
#include <security/pam_appl.h>
#include "namespace.h"
#include "tcpwrap.h"
#include "exit-status.h"
+#include "missing.h"
/* This assumes there is a 'tty' group */
#define TTY_MODE 0620
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;
+ }
}
}
"%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])
char *working_directory, *root_directory;
mode_t umask;
- int oom_adjust;
+ int oom_score_adjust;
int nice;
int ioprio;
int cpu_sched_policy;
* 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;
return 0;
}
-static int config_parse_oom_adjust(
+static int config_parse_oom_score_adjust(
const char *filename,
unsigned line,
const char *section,
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;
}
{ 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" },
{ "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 }, \
#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
ExecStart=/home/lennart/projects/systemd/systemd-logger
Type=simple
TimerSlackNS=1000000
-OOMAdjust=4
+OOMScoreAdjust=40
LimitCORE=0
LimitFSIZE=0
LimitLOCKS=0