mirror of
https://github.com/AuxXxilium/eudev.git
synced 2024-11-24 07:20:56 +07:00
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.
This commit is contained in:
parent
71916d3fff
commit
dd6c17b159
4
fixme
4
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:
|
||||
|
@ -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>
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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])
|
||||
|
@ -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;
|
||||
|
@ -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 }, \
|
||||
|
@ -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
|
||||
|
||||
#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 */
|
||||
#endif
|
||||
|
||||
#ifndef AUDIT_SERVICE_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);
|
||||
}
|
||||
|
||||
#ifndef AUDIT_SERVICE_START
|
||||
#define AUDIT_SERVICE_START 1130 /* Service (daemon) start */
|
||||
#endif
|
||||
|
||||
#ifndef AUDIT_SERVICE_STOP
|
||||
#define AUDIT_SERVICE_STOP 1131 /* Service (daemon) stop */
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user