]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
oomd: check mem free and swap free before doing a swap-based kill 20020/head
authorAnita Zhang <the.anitazha@gmail.com>
Thu, 24 Jun 2021 21:58:40 +0000 (14:58 -0700)
committerAnita Zhang <the.anitazha@gmail.com>
Wed, 30 Jun 2021 10:51:05 +0000 (03:51 -0700)
https://bugzilla.redhat.com/show_bug.cgi?id=1974763

man/oomd.conf.xml
src/oom/oomd-manager.c

index 27914e06999137a04cd1bd0ece21b70e878be42b..1092fee1dae7fb7fab23b6f080783b22237b11e4 100644 (file)
       <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>
index ddfa2fea0dcbb6443a3ec9f51f95a89886441164..ca319f4b0dd94d96de57429c04ab97c189e7aece 100644 (file)
@@ -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;
                 }