aboutsummaryrefslogtreecommitdiff
path: root/cgroup2.cc
diff options
context:
space:
mode:
Diffstat (limited to 'cgroup2.cc')
-rw-r--r--cgroup2.cc20
1 files changed, 18 insertions, 2 deletions
diff --git a/cgroup2.cc b/cgroup2.cc
index 6b0dc09..1902c5e 100644
--- a/cgroup2.cc
+++ b/cgroup2.cc
@@ -84,14 +84,30 @@ static void removeCgroup(const std::string &cgroup_path) {
}
static bool initNsFromParentMem(nsjconf_t *nsjconf, pid_t pid) {
- if (nsjconf->cgroup_mem_max == (size_t)0) {
+ ssize_t swap_max = nsjconf->cgroup_mem_swap_max;
+ if (nsjconf->cgroup_mem_memsw_max > (size_t)0) {
+ swap_max = nsjconf->cgroup_mem_memsw_max - nsjconf->cgroup_mem_max;
+ }
+
+ if (nsjconf->cgroup_mem_max == (size_t)0 && swap_max < (ssize_t)0) {
return true;
}
std::string cgroup_path = getCgroupPath(nsjconf, pid);
RETURN_ON_FAILURE(createCgroup(cgroup_path, pid));
RETURN_ON_FAILURE(addPidToProcList(cgroup_path, pid));
- return writeToCgroup(cgroup_path, "memory.max", std::to_string(nsjconf->cgroup_mem_max));
+
+ if (nsjconf->cgroup_mem_max > (size_t)0) {
+ RETURN_ON_FAILURE(writeToCgroup(
+ cgroup_path, "memory.max", std::to_string(nsjconf->cgroup_mem_max)));
+ }
+
+ if (swap_max >= (ssize_t)0) {
+ RETURN_ON_FAILURE(
+ writeToCgroup(cgroup_path, "memory.swap.max", std::to_string(swap_max)));
+ }
+
+ return true;
}
static bool initNsFromParentPids(nsjconf_t *nsjconf, pid_t pid) {