summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAnita Zhang <the.anitazha@gmail.com>2021-01-24 07:10:42 +0100
committerAnita Zhang <the.anitazha@gmail.com>2021-01-24 10:59:03 +0100
commit408a3bbd76326793ea5d1cf4e0a9444a4c252d86 (patch)
treecf0878be9c40811a312514ca610eadbd1c8b87ac /src
parentoom: make memory pressure duration configurable through oomd.conf (diff)
downloadsystemd-408a3bbd76326793ea5d1cf4e0a9444a4c252d86.tar.xz
systemd-408a3bbd76326793ea5d1cf4e0a9444a4c252d86.zip
oom: make swap a soft requirement
Diffstat (limited to 'src')
-rw-r--r--src/oom/oomd-manager.c8
-rw-r--r--src/oom/oomd.c6
-rw-r--r--src/oom/test-oomd-util.c11
3 files changed, 19 insertions, 6 deletions
diff --git a/src/oom/oomd-manager.c b/src/oom/oomd-manager.c
index e8ed6a5273..814fda51f3 100644
--- a/src/oom/oomd-manager.c
+++ b/src/oom/oomd-manager.c
@@ -6,6 +6,7 @@
#include "cgroup-util.h"
#include "fd-util.h"
#include "fileio.h"
+#include "memory-util.h"
#include "oomd-manager-bus.h"
#include "oomd-manager.h"
#include "path-util.h"
@@ -294,9 +295,12 @@ static int monitor_cgroup_contexts_handler(sd_event_source *s, uint64_t usec, vo
return log_error_errno(r, "Failed to update monitored memory pressure cgroup contexts");
r = oomd_system_context_acquire("/proc/swaps", &m->system_context);
- /* If there aren't units depending on swap actions, the only error we exit on is ENOMEM */
- if (r == -ENOMEM || (r < 0 && !hashmap_isempty(m->monitored_swap_cgroup_contexts)))
+ /* If there aren't units depending on swap actions, the only error we exit on is ENOMEM.
+ * Allow ENOENT in the event that swap is disabled on the system. */
+ if (r == -ENOMEM || (r < 0 && r != -ENOENT && !hashmap_isempty(m->monitored_swap_cgroup_contexts)))
return log_error_errno(r, "Failed to acquire system context");
+ else if (r == -ENOENT)
+ zero(m->system_context);
/* If we're still recovering from a kill, don't try to kill again yet */
if (m->post_action_delay_start > 0) {
diff --git a/src/oom/oomd.c b/src/oom/oomd.c
index 1b0f8ff6c4..1fbcf41492 100644
--- a/src/oom/oomd.c
+++ b/src/oom/oomd.c
@@ -142,10 +142,8 @@ static int run(int argc, char *argv[]) {
return log_error_errno(r, "Failed to get SwapTotal from /proc/meminfo: %m");
r = safe_atollu(swap, &s);
- if (r < 0)
- return log_error_errno(r, "Failed to parse SwapTotal from /proc/meminfo: %s: %m", swap);
- if (s == 0)
- return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Requires swap to operate");
+ if (r < 0 || s == 0)
+ log_warning("Swap is currently not detected; memory pressure usage will be degraded");
if (!is_pressure_supported())
return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Pressure Stall Information (PSI) is not supported");
diff --git a/src/oom/test-oomd-util.c b/src/oom/test-oomd-util.c
index 8143408902..54fe2a03d1 100644
--- a/src/oom/test-oomd-util.c
+++ b/src/oom/test-oomd-util.c
@@ -159,6 +159,11 @@ static void test_oomd_system_context_acquire(void) {
assert_se(ctx.swap_total == 0);
assert_se(ctx.swap_used == 0);
+ assert_se(write_string_file(path, "Filename Type Size Used Priority", WRITE_STRING_FILE_CREATE) == 0);
+ assert_se(oomd_system_context_acquire(path, &ctx) == 0);
+ assert_se(ctx.swap_total == 0);
+ assert_se(ctx.swap_used == 0);
+
assert_se(write_string_file(path, "Filename Type Size Used Priority\n"
"/swapvol/swapfile file 18971644 0 -3\n"
"/dev/vda2 partition 1999868 993780 -2", WRITE_STRING_FILE_CREATE) == 0);
@@ -268,6 +273,12 @@ static void test_oomd_swap_free_below(void) {
.swap_used = 3310136 * 1024U,
};
assert_se(oomd_swap_free_below(&ctx, 20) == false);
+
+ ctx = (OomdSystemContext) {
+ .swap_total = 0,
+ .swap_used = 0,
+ };
+ assert_se(oomd_swap_free_below(&ctx, 20) == false);
}
static void test_oomd_sort_cgroups(void) {