diff options
Diffstat (limited to 'cgroup2.cc')
-rw-r--r-- | cgroup2.cc | 20 |
1 files changed, 18 insertions, 2 deletions
@@ -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) { |