|
|
834f04 |
From c20aa7b17166b9f331da33ad9288f9ede75c72db Mon Sep 17 00:00:00 2001
|
|
|
834f04 |
From: Anita Zhang <the.anitazha@gmail.com>
|
|
|
834f04 |
Date: Sun, 24 Jan 2021 00:16:19 -0800
|
|
|
834f04 |
Subject: [PATCH 1/4] oom: make memory pressure duration configurable through
|
|
|
834f04 |
oomd.conf
|
|
|
834f04 |
|
|
|
834f04 |
---
|
|
|
834f04 |
man/oomd.conf.xml | 12 +++++++++++-
|
|
|
834f04 |
src/oom/oomd-manager.c | 13 +++++++++----
|
|
|
834f04 |
src/oom/oomd-manager.h | 5 +++--
|
|
|
834f04 |
src/oom/oomd-util.h | 1 +
|
|
|
834f04 |
src/oom/oomd.c | 4 +++-
|
|
|
834f04 |
src/oom/oomd.conf | 1 +
|
|
|
834f04 |
test/units/testsuite-56.sh | 3 +++
|
|
|
834f04 |
7 files changed, 31 insertions(+), 8 deletions(-)
|
|
|
834f04 |
|
|
|
834f04 |
diff --git a/man/oomd.conf.xml b/man/oomd.conf.xml
|
|
|
834f04 |
index 35a0686bc50..bb5da87c548 100644
|
|
|
834f04 |
--- a/man/oomd.conf.xml
|
|
|
834f04 |
+++ b/man/oomd.conf.xml
|
|
|
834f04 |
@@ -65,13 +65,23 @@
|
|
|
834f04 |
will take action. A unit can override this value with <varname>ManagedOOMMemoryPressureLimitPercent=</varname>.
|
|
|
834f04 |
The memory pressure for this property represents the fraction of time in a 10 second window in which all tasks
|
|
|
834f04 |
in the cgroup were delayed. For each monitored cgroup, if the memory pressure on that cgroup exceeds the
|
|
|
834f04 |
- limit set for more than 30 seconds, <command>systemd-oomd</command> will act on eligible descendant cgroups,
|
|
|
834f04 |
+ limit set for longer than the duration set by <varname>DefaultMemoryPressureDurationSec=</varname>,
|
|
|
834f04 |
+ <command>systemd-oomd</command> will act on eligible descendant cgroups,
|
|
|
834f04 |
starting from the ones with the most reclaim activity to the least reclaim activity. Which cgroups are
|
|
|
834f04 |
monitored and what action gets taken depends on what the unit has configured for
|
|
|
834f04 |
<varname>ManagedOOMMemoryPressure=</varname>. Takes a percentage value between 0% and 100%, inclusive.
|
|
|
834f04 |
Defaults to 60%.</para></listitem>
|
|
|
834f04 |
</varlistentry>
|
|
|
834f04 |
|
|
|
834f04 |
+ <varlistentry>
|
|
|
834f04 |
+ <term><varname>DefaultMemoryPressureDurationSec=</varname></term>
|
|
|
834f04 |
+
|
|
|
834f04 |
+ <listitem><para>Sets the amount of time a unit's cgroup needs to have exceeded memory pressure limits before
|
|
|
834f04 |
+ <command>systemd-oomd</command> will take action. Memory pressure limits are defined by
|
|
|
834f04 |
+ <varname>DefaultMemoryPressureLimitPercent=</varname> and <varname>ManagedOOMMemoryPressureLimitPercent=</varname>.
|
|
|
834f04 |
+ Defaults to 30 seconds when this property is unset or set to 0.</para></listitem>
|
|
|
834f04 |
+ </varlistentry>
|
|
|
834f04 |
+
|
|
|
834f04 |
</variablelist>
|
|
|
834f04 |
</refsect1>
|
|
|
834f04 |
|
|
|
834f04 |
diff --git a/src/oom/oomd-manager.c b/src/oom/oomd-manager.c
|
|
|
834f04 |
index fec96519e01..e8ed6a52739 100644
|
|
|
834f04 |
--- a/src/oom/oomd-manager.c
|
|
|
834f04 |
+++ b/src/oom/oomd-manager.c
|
|
|
834f04 |
@@ -306,7 +306,7 @@ static int monitor_cgroup_contexts_handler(sd_event_source *s, uint64_t usec, vo
|
|
|
834f04 |
m->post_action_delay_start = 0;
|
|
|
834f04 |
}
|
|
|
834f04 |
|
|
|
834f04 |
- r = oomd_pressure_above(m->monitored_mem_pressure_cgroup_contexts, PRESSURE_DURATION_USEC, &targets;;
|
|
|
834f04 |
+ r = oomd_pressure_above(m->monitored_mem_pressure_cgroup_contexts, m->default_mem_pressure_duration_usec, &targets;;
|
|
|
834f04 |
if (r == -ENOMEM)
|
|
|
834f04 |
return log_error_errno(r, "Failed to check if memory pressure exceeded limits");
|
|
|
834f04 |
else if (r == 1) {
|
|
|
834f04 |
@@ -325,7 +325,7 @@ static int monitor_cgroup_contexts_handler(sd_event_source *s, uint64_t usec, vo
|
|
|
834f04 |
|
|
|
834f04 |
SET_FOREACH(t, targets) {
|
|
|
834f04 |
log_notice("Memory pressure for %s is greater than %lu for more than %"PRIu64" seconds and there was reclaim activity",
|
|
|
834f04 |
- t->path, LOAD_INT(t->mem_pressure_limit), PRESSURE_DURATION_USEC / USEC_PER_SEC);
|
|
|
834f04 |
+ t->path, LOAD_INT(t->mem_pressure_limit), m->default_mem_pressure_duration_usec / USEC_PER_SEC);
|
|
|
834f04 |
|
|
|
834f04 |
r = oomd_kill_by_pgscan(candidates, t->path, m->dry_run);
|
|
|
834f04 |
if (r == -ENOMEM)
|
|
|
834f04 |
@@ -471,7 +471,7 @@ static int manager_connect_bus(Manager *m) {
|
|
|
834f04 |
return 0;
|
|
|
834f04 |
}
|
|
|
834f04 |
|
|
|
834f04 |
-int manager_start(Manager *m, bool dry_run, int swap_used_limit, int mem_pressure_limit) {
|
|
|
834f04 |
+int manager_start(Manager *m, bool dry_run, int swap_used_limit, int mem_pressure_limit, usec_t mem_pressure_usec) {
|
|
|
834f04 |
unsigned long l;
|
|
|
834f04 |
int r;
|
|
|
834f04 |
|
|
|
834f04 |
@@ -487,6 +487,8 @@ int manager_start(Manager *m, bool dry_run, int swap_used_limit, int mem_pressur
|
|
|
834f04 |
if (r < 0)
|
|
|
834f04 |
return r;
|
|
|
834f04 |
|
|
|
834f04 |
+ m->default_mem_pressure_duration_usec = mem_pressure_usec ?: DEFAULT_MEM_PRESSURE_DURATION_USEC;
|
|
|
834f04 |
+
|
|
|
834f04 |
r = manager_connect_bus(m);
|
|
|
834f04 |
if (r < 0)
|
|
|
834f04 |
return r;
|
|
|
834f04 |
@@ -505,6 +507,7 @@ int manager_start(Manager *m, bool dry_run, int swap_used_limit, int mem_pressur
|
|
|
834f04 |
int manager_get_dump_string(Manager *m, char **ret) {
|
|
|
834f04 |
_cleanup_free_ char *dump = NULL;
|
|
|
834f04 |
_cleanup_fclose_ FILE *f = NULL;
|
|
|
834f04 |
+ char buf[FORMAT_TIMESPAN_MAX];
|
|
|
834f04 |
OomdCGroupContext *c;
|
|
|
834f04 |
size_t size;
|
|
|
834f04 |
char *key;
|
|
|
834f04 |
@@ -521,10 +524,12 @@ int manager_get_dump_string(Manager *m, char **ret) {
|
|
|
834f04 |
"Dry Run: %s\n"
|
|
|
834f04 |
"Swap Used Limit: %u%%\n"
|
|
|
834f04 |
"Default Memory Pressure Limit: %lu%%\n"
|
|
|
834f04 |
+ "Default Memory Pressure Duration: %s\n"
|
|
|
834f04 |
"System Context:\n",
|
|
|
834f04 |
yes_no(m->dry_run),
|
|
|
834f04 |
m->swap_used_limit,
|
|
|
834f04 |
- LOAD_INT(m->default_mem_pressure_limit));
|
|
|
834f04 |
+ LOAD_INT(m->default_mem_pressure_limit),
|
|
|
834f04 |
+ format_timespan(buf, sizeof(buf), m->default_mem_pressure_duration_usec, USEC_PER_SEC));
|
|
|
834f04 |
oomd_dump_system_context(&m->system_context, f, "\t");
|
|
|
834f04 |
|
|
|
834f04 |
fprintf(f, "Swap Monitored CGroups:\n");
|
|
|
834f04 |
diff --git a/src/oom/oomd-manager.h b/src/oom/oomd-manager.h
|
|
|
834f04 |
index 3f3eb5aa4b6..ede9903e5a6 100644
|
|
|
834f04 |
--- a/src/oom/oomd-manager.h
|
|
|
834f04 |
+++ b/src/oom/oomd-manager.h
|
|
|
834f04 |
@@ -16,7 +16,7 @@
|
|
|
834f04 |
* percentage of time all tasks were delayed (i.e. unproductive).
|
|
|
834f04 |
* Generally 60 or higher might be acceptable for something like system.slice with no memory.high set; processes in
|
|
|
834f04 |
* system.slice are assumed to be less latency sensitive. */
|
|
|
834f04 |
-#define PRESSURE_DURATION_USEC (30 * USEC_PER_SEC)
|
|
|
834f04 |
+#define DEFAULT_MEM_PRESSURE_DURATION_USEC (30 * USEC_PER_SEC)
|
|
|
834f04 |
#define DEFAULT_MEM_PRESSURE_LIMIT 60
|
|
|
834f04 |
#define DEFAULT_SWAP_USED_LIMIT 90
|
|
|
834f04 |
|
|
|
834f04 |
@@ -33,6 +33,7 @@ struct Manager {
|
|
|
834f04 |
bool dry_run;
|
|
|
834f04 |
unsigned swap_used_limit;
|
|
|
834f04 |
loadavg_t default_mem_pressure_limit;
|
|
|
834f04 |
+ usec_t default_mem_pressure_duration_usec;
|
|
|
834f04 |
|
|
|
834f04 |
/* k: cgroup paths -> v: OomdCGroupContext
|
|
|
834f04 |
* Used to detect when to take action. */
|
|
|
834f04 |
@@ -53,7 +54,7 @@ DEFINE_TRIVIAL_CLEANUP_FUNC(Manager*, manager_free);
|
|
|
834f04 |
|
|
|
834f04 |
int manager_new(Manager **ret);
|
|
|
834f04 |
|
|
|
834f04 |
-int manager_start(Manager *m, bool dry_run, int swap_used_limit, int mem_pressure_limit);
|
|
|
834f04 |
+int manager_start(Manager *m, bool dry_run, int swap_used_limit, int mem_pressure_limit, usec_t mem_pressure_usec);
|
|
|
834f04 |
|
|
|
834f04 |
int manager_get_dump_string(Manager *m, char **ret);
|
|
|
834f04 |
|
|
|
834f04 |
diff --git a/src/oom/oomd-util.h b/src/oom/oomd-util.h
|
|
|
834f04 |
index 0834cbf09d7..d7a9890e7a2 100644
|
|
|
834f04 |
--- a/src/oom/oomd-util.h
|
|
|
834f04 |
+++ b/src/oom/oomd-util.h
|
|
|
834f04 |
@@ -31,6 +31,7 @@ struct OomdCGroupContext {
|
|
|
834f04 |
|
|
|
834f04 |
/* These are only used by oomd_pressure_above for acting on high memory pressure. */
|
|
|
834f04 |
loadavg_t mem_pressure_limit;
|
|
|
834f04 |
+ usec_t mem_pressure_duration_usec;
|
|
|
834f04 |
usec_t last_hit_mem_pressure_limit;
|
|
|
834f04 |
};
|
|
|
834f04 |
|
|
|
834f04 |
diff --git a/src/oom/oomd.c b/src/oom/oomd.c
|
|
|
834f04 |
index 8cf776ec0f5..1b0f8ff6c40 100644
|
|
|
834f04 |
--- a/src/oom/oomd.c
|
|
|
834f04 |
+++ b/src/oom/oomd.c
|
|
|
834f04 |
@@ -19,11 +19,13 @@
|
|
|
834f04 |
static bool arg_dry_run = false;
|
|
|
834f04 |
static int arg_swap_used_limit = -1;
|
|
|
834f04 |
static int arg_mem_pressure_limit = -1;
|
|
|
834f04 |
+static usec_t arg_mem_pressure_usec = 0;
|
|
|
834f04 |
|
|
|
834f04 |
static int parse_config(void) {
|
|
|
834f04 |
static const ConfigTableItem items[] = {
|
|
|
834f04 |
{ "OOM", "SwapUsedLimitPercent", config_parse_percent, 0, &arg_swap_used_limit },
|
|
|
834f04 |
{ "OOM", "DefaultMemoryPressureLimitPercent", config_parse_percent, 0, &arg_mem_pressure_limit },
|
|
|
834f04 |
+ { "OOM", "DefaultMemoryPressureDurationSec", config_parse_sec, 0, &arg_mem_pressure_usec },
|
|
|
834f04 |
{}
|
|
|
834f04 |
};
|
|
|
834f04 |
|
|
|
834f04 |
@@ -160,7 +162,7 @@ static int run(int argc, char *argv[]) {
|
|
|
834f04 |
if (r < 0)
|
|
|
834f04 |
return log_error_errno(r, "Failed to create manager: %m");
|
|
|
834f04 |
|
|
|
834f04 |
- r = manager_start(m, arg_dry_run, arg_swap_used_limit, arg_mem_pressure_limit);
|
|
|
834f04 |
+ r = manager_start(m, arg_dry_run, arg_swap_used_limit, arg_mem_pressure_limit, arg_mem_pressure_usec);
|
|
|
834f04 |
if (r < 0)
|
|
|
834f04 |
return log_error_errno(r, "Failed to start up daemon: %m");
|
|
|
834f04 |
|
|
|
834f04 |
diff --git a/src/oom/oomd.conf b/src/oom/oomd.conf
|
|
|
834f04 |
index 8ac97169610..766cb1717f7 100644
|
|
|
834f04 |
--- a/src/oom/oomd.conf
|
|
|
834f04 |
+++ b/src/oom/oomd.conf
|
|
|
834f04 |
@@ -14,3 +14,4 @@
|
|
|
834f04 |
[OOM]
|
|
|
834f04 |
#SwapUsedLimitPercent=90%
|
|
|
834f04 |
#DefaultMemoryPressureLimitPercent=60%
|
|
|
834f04 |
+#DefaultMemoryPressureDurationSec=30s
|
|
|
834f04 |
diff --git a/test/units/testsuite-56.sh b/test/units/testsuite-56.sh
|
|
|
834f04 |
index 1846248855b..6e7941a57fc 100755
|
|
|
834f04 |
--- a/test/units/testsuite-56.sh
|
|
|
834f04 |
+++ b/test/units/testsuite-56.sh
|
|
|
834f04 |
@@ -14,12 +14,15 @@ if [[ "$cgroup_type" != *"cgroup2"* ]] && [[ "$cgroup_type" != *"0x63677270"* ]]
|
|
|
834f04 |
fi
|
|
|
834f04 |
[[ -e /skipped ]] && exit 0 || true
|
|
|
834f04 |
|
|
|
834f04 |
+echo "DefaultMemoryPressureDurationSec=5s" >> /etc/systemd/oomd.conf
|
|
|
834f04 |
+
|
|
|
834f04 |
systemctl start testsuite-56-testbloat.service
|
|
|
834f04 |
systemctl start testsuite-56-testchill.service
|
|
|
834f04 |
|
|
|
834f04 |
# Verify systemd-oomd is monitoring the expected units
|
|
|
834f04 |
oomctl | grep "/testsuite-56-workload.slice"
|
|
|
834f04 |
oomctl | grep "1%"
|
|
|
834f04 |
+oomctl | grep "Default Memory Pressure Duration: 5s"
|
|
|
834f04 |
|
|
|
834f04 |
# systemd-oomd watches for elevated pressure for 30 seconds before acting.
|
|
|
834f04 |
# It can take time to build up pressure so either wait 5 minutes or for the service to fail.
|
|
|
834f04 |
|
|
|
834f04 |
From 408a3bbd76326793ea5d1cf4e0a9444a4c252d86 Mon Sep 17 00:00:00 2001
|
|
|
834f04 |
From: Anita Zhang <the.anitazha@gmail.com>
|
|
|
834f04 |
Date: Sat, 23 Jan 2021 22:10:42 -0800
|
|
|
834f04 |
Subject: [PATCH 2/4] oom: make swap a soft requirement
|
|
|
834f04 |
|
|
|
834f04 |
---
|
|
|
834f04 |
man/systemd-oomd.service.xml | 4 ++--
|
|
|
834f04 |
src/oom/oomd-manager.c | 8 ++++++--
|
|
|
834f04 |
src/oom/oomd.c | 6 ++----
|
|
|
834f04 |
src/oom/test-oomd-util.c | 11 +++++++++++
|
|
|
834f04 |
4 files changed, 21 insertions(+), 8 deletions(-)
|
|
|
834f04 |
|
|
|
834f04 |
diff --git a/man/systemd-oomd.service.xml b/man/systemd-oomd.service.xml
|
|
|
834f04 |
index 9cb9c6076a9..ebd2467ee23 100644
|
|
|
834f04 |
--- a/man/systemd-oomd.service.xml
|
|
|
834f04 |
+++ b/man/systemd-oomd.service.xml
|
|
|
834f04 |
@@ -56,8 +56,8 @@
|
|
|
834f04 |
|
|
|
834f04 |
<para>You will need a kernel compiled with PSI support. This is available in Linux 4.20 and above.</para>
|
|
|
834f04 |
|
|
|
834f04 |
- <para>The system must also have swap enabled for <command>systemd-oomd</command> to function correctly. With swap
|
|
|
834f04 |
- enabled, the system spends enough time swapping pages to let <command>systemd-oomd</command> react.
|
|
|
834f04 |
+ <para>It is highly recommended for the system to have swap enabled for <command>systemd-oomd</command> to function
|
|
|
834f04 |
+ optimally. With swap enabled, the system spends enough time swapping pages to let <command>systemd-oomd</command> react.
|
|
|
834f04 |
Without swap, the system enters a livelocked state much more quickly and may prevent <command>systemd-oomd</command>
|
|
|
834f04 |
from responding in a reasonable amount of time. See
|
|
|
834f04 |
<ulink url="https://chrisdown.name/2018/01/02/in-defence-of-swap.html">"In defence of swap: common misconceptions"</ulink>
|
|
|
834f04 |
diff --git a/src/oom/oomd-manager.c b/src/oom/oomd-manager.c
|
|
|
834f04 |
index e8ed6a52739..814fda51f31 100644
|
|
|
834f04 |
--- a/src/oom/oomd-manager.c
|
|
|
834f04 |
+++ b/src/oom/oomd-manager.c
|
|
|
834f04 |
@@ -6,6 +6,7 @@
|
|
|
834f04 |
#include "cgroup-util.h"
|
|
|
834f04 |
#include "fd-util.h"
|
|
|
834f04 |
#include "fileio.h"
|
|
|
834f04 |
+#include "memory-util.h"
|
|
|
834f04 |
#include "oomd-manager-bus.h"
|
|
|
834f04 |
#include "oomd-manager.h"
|
|
|
834f04 |
#include "path-util.h"
|
|
|
834f04 |
@@ -294,9 +295,12 @@ static int monitor_cgroup_contexts_handler(sd_event_source *s, uint64_t usec, vo
|
|
|
834f04 |
return log_error_errno(r, "Failed to update monitored memory pressure cgroup contexts");
|
|
|
834f04 |
|
|
|
834f04 |
r = oomd_system_context_acquire("/proc/swaps", &m->system_context);
|
|
|
834f04 |
- /* If there aren't units depending on swap actions, the only error we exit on is ENOMEM */
|
|
|
834f04 |
- if (r == -ENOMEM || (r < 0 && !hashmap_isempty(m->monitored_swap_cgroup_contexts)))
|
|
|
834f04 |
+ /* If there aren't units depending on swap actions, the only error we exit on is ENOMEM.
|
|
|
834f04 |
+ * Allow ENOENT in the event that swap is disabled on the system. */
|
|
|
834f04 |
+ if (r == -ENOMEM || (r < 0 && r != -ENOENT && !hashmap_isempty(m->monitored_swap_cgroup_contexts)))
|
|
|
834f04 |
return log_error_errno(r, "Failed to acquire system context");
|
|
|
834f04 |
+ else if (r == -ENOENT)
|
|
|
834f04 |
+ zero(m->system_context);
|
|
|
834f04 |
|
|
|
834f04 |
/* If we're still recovering from a kill, don't try to kill again yet */
|
|
|
834f04 |
if (m->post_action_delay_start > 0) {
|
|
|
834f04 |
diff --git a/src/oom/oomd.c b/src/oom/oomd.c
|
|
|
834f04 |
index 1b0f8ff6c40..1fbcf41492d 100644
|
|
|
834f04 |
--- a/src/oom/oomd.c
|
|
|
834f04 |
+++ b/src/oom/oomd.c
|
|
|
834f04 |
@@ -142,10 +142,8 @@ static int run(int argc, char *argv[]) {
|
|
|
834f04 |
return log_error_errno(r, "Failed to get SwapTotal from /proc/meminfo: %m");
|
|
|
834f04 |
|
|
|
834f04 |
r = safe_atollu(swap, &s);
|
|
|
834f04 |
- if (r < 0)
|
|
|
834f04 |
- return log_error_errno(r, "Failed to parse SwapTotal from /proc/meminfo: %s: %m", swap);
|
|
|
834f04 |
- if (s == 0)
|
|
|
834f04 |
- return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Requires swap to operate");
|
|
|
834f04 |
+ if (r < 0 || s == 0)
|
|
|
834f04 |
+ log_warning("Swap is currently not detected; memory pressure usage will be degraded");
|
|
|
834f04 |
|
|
|
834f04 |
if (!is_pressure_supported())
|
|
|
834f04 |
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Pressure Stall Information (PSI) is not supported");
|
|
|
834f04 |
diff --git a/src/oom/test-oomd-util.c b/src/oom/test-oomd-util.c
|
|
|
834f04 |
index 8143408902b..54fe2a03d14 100644
|
|
|
834f04 |
--- a/src/oom/test-oomd-util.c
|
|
|
834f04 |
+++ b/src/oom/test-oomd-util.c
|
|
|
834f04 |
@@ -159,6 +159,11 @@ static void test_oomd_system_context_acquire(void) {
|
|
|
834f04 |
assert_se(ctx.swap_total == 0);
|
|
|
834f04 |
assert_se(ctx.swap_used == 0);
|
|
|
834f04 |
|
|
|
834f04 |
+ assert_se(write_string_file(path, "Filename Type Size Used Priority", WRITE_STRING_FILE_CREATE) == 0);
|
|
|
834f04 |
+ assert_se(oomd_system_context_acquire(path, &ctx) == 0);
|
|
|
834f04 |
+ assert_se(ctx.swap_total == 0);
|
|
|
834f04 |
+ assert_se(ctx.swap_used == 0);
|
|
|
834f04 |
+
|
|
|
834f04 |
assert_se(write_string_file(path, "Filename Type Size Used Priority\n"
|
|
|
834f04 |
"/swapvol/swapfile file 18971644 0 -3\n"
|
|
|
834f04 |
"/dev/vda2 partition 1999868 993780 -2", WRITE_STRING_FILE_CREATE) == 0);
|
|
|
834f04 |
@@ -268,6 +273,12 @@ static void test_oomd_swap_free_below(void) {
|
|
|
834f04 |
.swap_used = 3310136 * 1024U,
|
|
|
834f04 |
};
|
|
|
834f04 |
assert_se(oomd_swap_free_below(&ctx, 20) == false);
|
|
|
834f04 |
+
|
|
|
834f04 |
+ ctx = (OomdSystemContext) {
|
|
|
834f04 |
+ .swap_total = 0,
|
|
|
834f04 |
+ .swap_used = 0,
|
|
|
834f04 |
+ };
|
|
|
834f04 |
+ assert_se(oomd_swap_free_below(&ctx, 20) == false);
|
|
|
834f04 |
}
|
|
|
834f04 |
|
|
|
834f04 |
static void test_oomd_sort_cgroups(void) {
|
|
|
834f04 |
|
|
|
834f04 |
From 924c89e9fe95d47b6ad94544bfdd5f087646daea Mon Sep 17 00:00:00 2001
|
|
|
834f04 |
From: Anita Zhang <the.anitazha@gmail.com>
|
|
|
834f04 |
Date: Sun, 24 Jan 2021 01:22:51 -0800
|
|
|
834f04 |
Subject: [PATCH 3/4] oom: fix reclaim activity detection
|
|
|
834f04 |
|
|
|
834f04 |
This should have been checking for any reclaim activity within a larger interval
|
|
|
834f04 |
of time rather than within the past second. On systems with swap this
|
|
|
834f04 |
doesn't seem to have mattered too much as reclaim would always increase when
|
|
|
834f04 |
memory pressure was elevated. But testing in the no swap case having
|
|
|
834f04 |
this larger interval made a difference between oomd killing or not.
|
|
|
834f04 |
---
|
|
|
834f04 |
src/oom/oomd-manager.c | 7 +++++--
|
|
|
834f04 |
src/oom/oomd-manager.h | 2 ++
|
|
|
834f04 |
2 files changed, 7 insertions(+), 2 deletions(-)
|
|
|
834f04 |
|
|
|
834f04 |
diff --git a/src/oom/oomd-manager.c b/src/oom/oomd-manager.c
|
|
|
834f04 |
index 814fda51f31..3efa629002e 100644
|
|
|
834f04 |
--- a/src/oom/oomd-manager.c
|
|
|
834f04 |
+++ b/src/oom/oomd-manager.c
|
|
|
834f04 |
@@ -302,6 +302,9 @@ static int monitor_cgroup_contexts_handler(sd_event_source *s, uint64_t usec, vo
|
|
|
834f04 |
else if (r == -ENOENT)
|
|
|
834f04 |
zero(m->system_context);
|
|
|
834f04 |
|
|
|
834f04 |
+ if (oomd_memory_reclaim(m->monitored_mem_pressure_cgroup_contexts))
|
|
|
834f04 |
+ m->last_reclaim_at = usec_now;
|
|
|
834f04 |
+
|
|
|
834f04 |
/* If we're still recovering from a kill, don't try to kill again yet */
|
|
|
834f04 |
if (m->post_action_delay_start > 0) {
|
|
|
834f04 |
if (m->post_action_delay_start + POST_ACTION_DELAY_USEC > usec_now)
|
|
|
834f04 |
@@ -314,12 +317,12 @@ static int monitor_cgroup_contexts_handler(sd_event_source *s, uint64_t usec, vo
|
|
|
834f04 |
if (r == -ENOMEM)
|
|
|
834f04 |
return log_error_errno(r, "Failed to check if memory pressure exceeded limits");
|
|
|
834f04 |
else if (r == 1) {
|
|
|
834f04 |
- /* Check if there was reclaim activity in the last interval. The concern is the following case:
|
|
|
834f04 |
+ /* Check if there was reclaim activity in the given interval. The concern is the following case:
|
|
|
834f04 |
* Pressure climbed, a lot of high-frequency pages were reclaimed, and we killed the offending
|
|
|
834f04 |
* cgroup. Even after this, well-behaved processes will fault in recently resident pages and
|
|
|
834f04 |
* this will cause pressure to remain high. Thus if there isn't any reclaim pressure, no need
|
|
|
834f04 |
* to kill something (it won't help anyways). */
|
|
|
834f04 |
- if (oomd_memory_reclaim(m->monitored_mem_pressure_cgroup_contexts)) {
|
|
|
834f04 |
+ if ((usec_now - m->last_reclaim_at) <= RECLAIM_DURATION_USEC) {
|
|
|
834f04 |
_cleanup_hashmap_free_ Hashmap *candidates = NULL;
|
|
|
834f04 |
OomdCGroupContext *t;
|
|
|
834f04 |
|
|
|
834f04 |
diff --git a/src/oom/oomd-manager.h b/src/oom/oomd-manager.h
|
|
|
834f04 |
index ede9903e5a6..ee17abced26 100644
|
|
|
834f04 |
--- a/src/oom/oomd-manager.h
|
|
|
834f04 |
+++ b/src/oom/oomd-manager.h
|
|
|
834f04 |
@@ -20,6 +20,7 @@
|
|
|
834f04 |
#define DEFAULT_MEM_PRESSURE_LIMIT 60
|
|
|
834f04 |
#define DEFAULT_SWAP_USED_LIMIT 90
|
|
|
834f04 |
|
|
|
834f04 |
+#define RECLAIM_DURATION_USEC (30 * USEC_PER_SEC)
|
|
|
834f04 |
#define POST_ACTION_DELAY_USEC (15 * USEC_PER_SEC)
|
|
|
834f04 |
|
|
|
834f04 |
typedef struct Manager Manager;
|
|
|
834f04 |
@@ -42,6 +43,7 @@ struct Manager {
|
|
|
834f04 |
|
|
|
834f04 |
OomdSystemContext system_context;
|
|
|
834f04 |
|
|
|
834f04 |
+ usec_t last_reclaim_at;
|
|
|
834f04 |
usec_t post_action_delay_start;
|
|
|
834f04 |
|
|
|
834f04 |
sd_event_source *cgroup_context_event_source;
|
|
|
834f04 |
|
|
|
834f04 |
From 2e744a2cd89fc0ea67cf78cfba617b5105a26215 Mon Sep 17 00:00:00 2001
|
|
|
834f04 |
From: Anita Zhang <the.anitazha@gmail.com>
|
|
|
834f04 |
Date: Sun, 24 Jan 2021 01:34:23 -0800
|
|
|
834f04 |
Subject: [PATCH 4/4] oom: update extended test to remove swap gating
|
|
|
834f04 |
|
|
|
834f04 |
---
|
|
|
834f04 |
test/units/testsuite-56.sh | 3 +--
|
|
|
834f04 |
1 file changed, 1 insertion(+), 2 deletions(-)
|
|
|
834f04 |
|
|
|
834f04 |
diff --git a/test/units/testsuite-56.sh b/test/units/testsuite-56.sh
|
|
|
834f04 |
index 6e7941a57fc..4dc9d8c7a86 100755
|
|
|
834f04 |
--- a/test/units/testsuite-56.sh
|
|
|
834f04 |
+++ b/test/units/testsuite-56.sh
|
|
|
834f04 |
@@ -6,7 +6,6 @@ systemd-analyze log-level debug
|
|
|
834f04 |
systemd-analyze log-target console
|
|
|
834f04 |
|
|
|
834f04 |
# Loose checks to ensure the environment has the necessary features for systemd-oomd
|
|
|
834f04 |
-[[ "$( awk '/SwapTotal/ { print $2 }' /proc/meminfo )" != "0" ]] || echo "no swap" >> /skipped
|
|
|
834f04 |
[[ -e /proc/pressure ]] || echo "no PSI" >> /skipped
|
|
|
834f04 |
cgroup_type=$(stat -fc %T /sys/fs/cgroup/)
|
|
|
834f04 |
if [[ "$cgroup_type" != *"cgroup2"* ]] && [[ "$cgroup_type" != *"0x63677270"* ]]; then
|
|
|
834f04 |
@@ -16,8 +15,8 @@ fi
|
|
|
834f04 |
|
|
|
834f04 |
echo "DefaultMemoryPressureDurationSec=5s" >> /etc/systemd/oomd.conf
|
|
|
834f04 |
|
|
|
834f04 |
-systemctl start testsuite-56-testbloat.service
|
|
|
834f04 |
systemctl start testsuite-56-testchill.service
|
|
|
834f04 |
+systemctl start testsuite-56-testbloat.service
|
|
|
834f04 |
|
|
|
834f04 |
# Verify systemd-oomd is monitoring the expected units
|
|
|
834f04 |
oomctl | grep "/testsuite-56-workload.slice"
|