summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Down <chris@chrisdown.name>2019-04-16 18:14:09 +0100
committerChris Down <chris@chrisdown.name>2019-04-16 18:39:51 +0100
commit6264b85e92aeddb74b8d8808a08c9eae8390a6a5 (patch)
tree0fc7641f7766a4451e7bf76553f91ab259297f64
parentac9b17271fbe2a840796739c455183e3d89d9e21 (diff)
downloadsystemd-6264b85e92aeddb74b8d8808a08c9eae8390a6a5.tar.gz
cgroup: Create UNIT_DEFINE_ANCESTOR_MEMORY_LOOKUP
This is in preparation for creating unit_get_ancestor_memory_min.
-rw-r--r--src/core/cgroup.c55
1 files changed, 30 insertions, 25 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index ceb7ee2189..8884981b29 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -384,31 +384,36 @@ int cgroup_add_device_allow(CGroupContext *c, const char *dev, const char *mode)
return 0;
}
-uint64_t unit_get_ancestor_memory_low(Unit *u) {
- CGroupContext *c;
-
- /* 1. Is MemoryLow set in this unit? If so, use that.
- * 2. Is DefaultMemoryLow set in any ancestor? If so, use that.
- * 3. Otherwise, return CGROUP_LIMIT_MIN. */
-
- assert(u);
-
- c = unit_get_cgroup_context(u);
-
- if (c->memory_low_set)
- return c->memory_low;
-
- while (UNIT_ISSET(u->slice)) {
- u = UNIT_DEREF(u->slice);
- c = unit_get_cgroup_context(u);
-
- if (c->default_memory_low_set)
- return c->default_memory_low;
- }
-
- /* We've reached the root, but nobody had DefaultMemoryLow set, so set it to the kernel default. */
- return CGROUP_LIMIT_MIN;
-}
+#define UNIT_DEFINE_ANCESTOR_MEMORY_LOOKUP(entry) \
+ uint64_t unit_get_ancestor_##entry(Unit *u) { \
+ CGroupContext *c; \
+ \
+ /* 1. Is entry set in this unit? If so, use that. \
+ * 2. Is the default for this entry set in any \
+ * ancestor? If so, use that. \
+ * 3. Otherwise, return CGROUP_LIMIT_MIN. */ \
+ \
+ assert(u); \
+ \
+ c = unit_get_cgroup_context(u); \
+ \
+ if (c->entry##_set) \
+ return c->entry; \
+ \
+ while (UNIT_ISSET(u->slice)) { \
+ u = UNIT_DEREF(u->slice); \
+ c = unit_get_cgroup_context(u); \
+ \
+ if (c->default_##entry##_set) \
+ return c->default_##entry; \
+ } \
+ \
+ /* We've reached the root, but nobody had default for \
+ * this entry set, so set it to the kernel default. */ \
+ return CGROUP_LIMIT_MIN; \
+}
+
+UNIT_DEFINE_ANCESTOR_MEMORY_LOOKUP(memory_low);
static void cgroup_xattr_apply(Unit *u) {
char ids[SD_ID128_STRING_MAX];