summaryrefslogtreecommitdiff
path: root/src/oom/oomd-util.h
diff options
context:
space:
mode:
authorAnita Zhang <the.anitazha@gmail.com>2021-02-09 01:47:34 -0800
committerAnita Zhang <the.anitazha@gmail.com>2021-02-09 02:27:40 -0800
commit59331b8e292a93bc7a03a51fe54cb65a4257e894 (patch)
tree3b420e7a81168b54d8a6578fd3ea52b593c2a4af /src/oom/oomd-util.h
parent242d75bdaaa6f222a47148f8a83cc425d6ceefb3 (diff)
downloadsystemd-59331b8e292a93bc7a03a51fe54cb65a4257e894.tar.gz
oom: implement avoid/omit xattr support
There may be situations where a cgroup should be protected from killing or deprioritized as a candidate. In FB oomd xattrs are used to bias oomd away from supervisor cgroups and towards worker cgroups in container tasks. On desktops this can be used to protect important units with unpredictable resource consumption. The patch allows systemd-oomd to understand 2 xattrs: "user.oomd_avoid" and "user.oomd_omit". If systemd-oomd sees these xattrs set to 1 on a candidate cgroup (i.e. while attempting to kill something) AND the cgroup is owned by root, it will either deprioritize the cgroup as a candidate (avoid) or remove it completely as a candidate (omit). Usage is restricted to root owned cgroups to prevent situations where an unprivileged user can set their own cgroups lower in the kill priority than another user's (and prevent them from omitting their units from systemd-oomd killing).
Diffstat (limited to 'src/oom/oomd-util.h')
-rw-r--r--src/oom/oomd-util.h15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/oom/oomd-util.h b/src/oom/oomd-util.h
index 650b4efb9c..bffccf75da 100644
--- a/src/oom/oomd-util.h
+++ b/src/oom/oomd-util.h
@@ -3,6 +3,7 @@
#include <stdbool.h>
+#include "cgroup-util.h"
#include "hashmap.h"
#include "psi-util.h"
@@ -29,6 +30,8 @@ struct OomdCGroupContext {
uint64_t last_pgscan;
uint64_t pgscan;
+ ManagedOOMPreference preference;
+
/* These are only used by oomd_pressure_above for acting on high memory pressure. */
loadavg_t mem_pressure_limit;
usec_t mem_pressure_duration_usec;
@@ -61,12 +64,18 @@ bool oomd_memory_reclaim(Hashmap *h);
/* Returns true if the amount of swap free is below the percentage of swap specified by `threshold_percent`. */
bool oomd_swap_free_below(const OomdSystemContext *ctx, uint64_t threshold_percent);
+/* The compare functions will sort from largest to smallest, putting all the contexts with "avoid" at the end
+ * (after the smallest values). */
static inline int compare_pgscan_and_memory_usage(OomdCGroupContext * const *c1, OomdCGroupContext * const *c2) {
int r;
assert(c1);
assert(c2);
+ r = CMP((*c1)->preference, (*c2)->preference);
+ if (r != 0)
+ return r;
+
r = CMP((*c2)->pgscan, (*c1)->pgscan);
if (r != 0)
return r;
@@ -75,9 +84,15 @@ static inline int compare_pgscan_and_memory_usage(OomdCGroupContext * const *c1,
}
static inline int compare_swap_usage(OomdCGroupContext * const *c1, OomdCGroupContext * const *c2) {
+ int r;
+
assert(c1);
assert(c2);
+ r = CMP((*c1)->preference, (*c2)->preference);
+ if (r != 0)
+ return r;
+
return CMP((*c2)->swap_usage, (*c1)->swap_usage);
}