Commit 74792bf3 authored by Petr Baudis's avatar Petr Baudis
Browse files

cgroup_set_mem_limit(): Fix increasing the memory limit

parent 7ad86fb9
......@@ -141,7 +141,7 @@ cgroup_get_mem_limit(const char *chier, const char *cgroup)
return nlimit;
}
int
static int
cgroup_set_mem_limit_do(const char *chier, const char *cgroup, size_t nlimit, char *memsw)
{
char limitfile[PATH_MAX];
......@@ -163,21 +163,33 @@ cgroup_set_mem_limit_do(const char *chier, const char *cgroup, size_t nlimit, ch
return 1;
}
int
cgroup_set_mem_limit(const char *chier, const char *cgroup, size_t nlimit)
static int
cgroup_set_mem_limit_twice(const char *chier, const char *cgroup, size_t nlimit, char *memsw1, char *memsw2)
{
/* We need to set both the "normal" and memsw limits, normal first,
* since normal <= memsw must hold. */
int ret = cgroup_set_mem_limit_do(chier, cgroup, nlimit, "");
#if SWAP_LIMIT
int ret = cgroup_set_mem_limit_do(chier, cgroup, nlimit, memsw1);
if (ret >= 0) {
int ret2 = cgroup_set_mem_limit_do(chier, cgroup, nlimit, MEMSW);
int ret2 = cgroup_set_mem_limit_do(chier, cgroup, nlimit, memsw2);
ret = ret2 < 0 ? ret2 : (ret || ret2);
}
#endif
return ret;
}
int
cgroup_set_mem_limit(const char *chier, const char *cgroup, size_t nlimit)
{
#if SWAP_LIMIT
/* We need to set both the "normal" and memsw limits, but in such
* order that normal <= memsw always holds. */
size_t curlimit = cgroup_get_mem_limit(chier, cgroup);
if (nlimit < curlimit)
return cgroup_set_mem_limit_twice(chier, cgroup, nlimit, "", MEMSW);
else
return cgroup_set_mem_limit_twice(chier, cgroup, nlimit, MEMSW, "");
#else
return cgroup_set_mem_limit_do(chier, cgroup, nlimit, "");
#endif
}
size_t
cgroup_get_mem_usage(const char *chier, const char *cgroup)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment