diff --git a/man/oomd.conf.xml b/man/oomd.conf.xml index 27914e06999..1092fee1dae 100644 --- a/man/oomd.conf.xml +++ b/man/oomd.conf.xml @@ -50,10 +50,10 @@ SwapUsedLimit= - Sets the limit for swap usage on the system before systemd-oomd - will take action. If the fraction of swap used on the system is more than what is defined here, - systemd-oomd will act on eligible descendant control groups with swap usage greater - than 5% of total swap, starting from the ones with the highest swap usage. Which + Sets the limit for memory and swap usage on the system before systemd-oomd + will take action. If the fraction of memory used and the fraction of swap used on the system are both more than + what is defined here, systemd-oomd will act on eligible descendant control groups with swap + usage greater than 5% of total swap, starting from the ones with the highest swap usage. Which control groups are monitored and what action gets taken depends on what the unit has configured for ManagedOOMSwap=. Takes a value specified in percent (when suffixed with "%"), permille ("‰") or permyriad ("‱"), between 0% and 100%, inclusive. Defaults to 90%. diff --git a/src/oom/oomd-manager.c b/src/oom/oomd-manager.c index ddfa2fea0dc..ca319f4b0dd 100644 --- a/src/oom/oomd-manager.c +++ b/src/oom/oomd-manager.c @@ -338,12 +338,16 @@ static int monitor_swap_contexts_handler(sd_event_source *s, uint64_t usec, void * is only used to decide which cgroups to kill (and even then only the resource usages of its descendent * nodes are the ones that matter). */ - if (oomd_swap_free_below(&m->system_context, 10000 - m->swap_used_limit_permyriad)) { + /* Check amount of memory free and swap free so we don't free up swap when memory is still available. */ + if (oomd_mem_free_below(&m->system_context, 10000 - m->swap_used_limit_permyriad) && + oomd_swap_free_below(&m->system_context, 10000 - m->swap_used_limit_permyriad)) { _cleanup_hashmap_free_ Hashmap *candidates = NULL; _cleanup_free_ char *selected = NULL; uint64_t threshold; - log_debug("Swap used (%"PRIu64") / total (%"PRIu64") is more than " PERMYRIAD_AS_PERCENT_FORMAT_STR, + log_debug("Memory used (%"PRIu64") / total (%"PRIu64") and " + "swap used (%"PRIu64") / total (%"PRIu64") is more than " PERMYRIAD_AS_PERCENT_FORMAT_STR, + m->system_context.mem_used, m->system_context.mem_total, m->system_context.swap_used, m->system_context.swap_total, PERMYRIAD_AS_PERCENT_FORMAT_VAL(m->swap_used_limit_permyriad)); @@ -361,9 +365,12 @@ static int monitor_swap_contexts_handler(sd_event_source *s, uint64_t usec, void log_notice_errno(r, "Failed to kill any cgroup(s) based on swap: %m"); else { if (selected) - log_notice("Killed %s due to swap used (%"PRIu64") / total (%"PRIu64") being more than " + log_notice("Killed %s due to memory used (%"PRIu64") / total (%"PRIu64") and " + "swap used (%"PRIu64") / total (%"PRIu64") being more than " PERMYRIAD_AS_PERCENT_FORMAT_STR, - selected, m->system_context.swap_used, m->system_context.swap_total, + selected, + m->system_context.mem_used, m->system_context.mem_total, + m->system_context.swap_used, m->system_context.swap_total, PERMYRIAD_AS_PERCENT_FORMAT_VAL(m->swap_used_limit_permyriad)); return 0; }