mirror of
https://github.com/systemd/systemd.git
synced 2025-02-22 09:57:34 +03:00
oomd: check mem free and swap free before doing a swap-based kill
https://bugzilla.redhat.com/show_bug.cgi?id=1974763
This commit is contained in:
parent
eeeaa42284
commit
cb5ce676d9
@ -50,10 +50,10 @@
|
||||
<varlistentry>
|
||||
<term><varname>SwapUsedLimit=</varname></term>
|
||||
|
||||
<listitem><para>Sets the limit for swap usage on the system before <command>systemd-oomd</command>
|
||||
will take action. If the fraction of swap used on the system is more than what is defined here,
|
||||
<command>systemd-oomd</command> 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
|
||||
<listitem><para>Sets the limit for memory and swap usage on the system before <command>systemd-oomd</command>
|
||||
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, <command>systemd-oomd</command> 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
|
||||
<varname>ManagedOOMSwap=</varname>. Takes a value specified in percent (when suffixed with "%"),
|
||||
permille ("‰") or permyriad ("‱"), between 0% and 100%, inclusive. Defaults to 90%.</para></listitem>
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user