X Tutup
Skip to content

Commit cb5ce67

Browse files
committed
oomd: check mem free and swap free before doing a swap-based kill
https://bugzilla.redhat.com/show_bug.cgi?id=1974763
1 parent eeeaa42 commit cb5ce67

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

man/oomd.conf.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@
5050
<varlistentry>
5151
<term><varname>SwapUsedLimit=</varname></term>
5252

53-
<listitem><para>Sets the limit for swap usage on the system before <command>systemd-oomd</command>
54-
will take action. If the fraction of swap used on the system is more than what is defined here,
55-
<command>systemd-oomd</command> will act on eligible descendant control groups with swap usage greater
56-
than 5% of total swap, starting from the ones with the highest swap usage. Which
53+
<listitem><para>Sets the limit for memory and swap usage on the system before <command>systemd-oomd</command>
54+
will take action. If the fraction of memory used and the fraction of swap used on the system are both more than
55+
what is defined here, <command>systemd-oomd</command> will act on eligible descendant control groups with swap
56+
usage greater than 5% of total swap, starting from the ones with the highest swap usage. Which
5757
control groups are monitored and what action gets taken depends on what the unit has configured for
5858
<varname>ManagedOOMSwap=</varname>. Takes a value specified in percent (when suffixed with "%"),
5959
permille ("‰") or permyriad ("‱"), between 0% and 100%, inclusive. Defaults to 90%.</para></listitem>

src/oom/oomd-manager.c

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -338,12 +338,16 @@ static int monitor_swap_contexts_handler(sd_event_source *s, uint64_t usec, void
338338
* is only used to decide which cgroups to kill (and even then only the resource usages of its descendent
339339
* nodes are the ones that matter). */
340340

341-
if (oomd_swap_free_below(&m->system_context, 10000 - m->swap_used_limit_permyriad)) {
341+
/* Check amount of memory free and swap free so we don't free up swap when memory is still available. */
342+
if (oomd_mem_free_below(&m->system_context, 10000 - m->swap_used_limit_permyriad) &&
343+
oomd_swap_free_below(&m->system_context, 10000 - m->swap_used_limit_permyriad)) {
342344
_cleanup_hashmap_free_ Hashmap *candidates = NULL;
343345
_cleanup_free_ char *selected = NULL;
344346
uint64_t threshold;
345347

346-
log_debug("Swap used (%"PRIu64") / total (%"PRIu64") is more than " PERMYRIAD_AS_PERCENT_FORMAT_STR,
348+
log_debug("Memory used (%"PRIu64") / total (%"PRIu64") and "
349+
"swap used (%"PRIu64") / total (%"PRIu64") is more than " PERMYRIAD_AS_PERCENT_FORMAT_STR,
350+
m->system_context.mem_used, m->system_context.mem_total,
347351
m->system_context.swap_used, m->system_context.swap_total,
348352
PERMYRIAD_AS_PERCENT_FORMAT_VAL(m->swap_used_limit_permyriad));
349353

@@ -361,9 +365,12 @@ static int monitor_swap_contexts_handler(sd_event_source *s, uint64_t usec, void
361365
log_notice_errno(r, "Failed to kill any cgroup(s) based on swap: %m");
362366
else {
363367
if (selected)
364-
log_notice("Killed %s due to swap used (%"PRIu64") / total (%"PRIu64") being more than "
368+
log_notice("Killed %s due to memory used (%"PRIu64") / total (%"PRIu64") and "
369+
"swap used (%"PRIu64") / total (%"PRIu64") being more than "
365370
PERMYRIAD_AS_PERCENT_FORMAT_STR,
366-
selected, m->system_context.swap_used, m->system_context.swap_total,
371+
selected,
372+
m->system_context.mem_used, m->system_context.mem_total,
373+
m->system_context.swap_used, m->system_context.swap_total,
367374
PERMYRIAD_AS_PERCENT_FORMAT_VAL(m->swap_used_limit_permyriad));
368375
return 0;
369376
}

0 commit comments

Comments
 (0)
X Tutup