[Devel,libvzctl] nsops: cgroup, pids -- Don't exceed kernel limit on write

Submitted by Kirill Gorkunov on March 24, 2017, 12:09 p.m.

Details

Message ID 20170324120925.GA11058@uranus
State New
Series "nsops: cgroup, pids -- Don't exceed kernel limit on write"
Headers show

Commit Message

Kirill Gorkunov March 24, 2017, 12:09 p.m.
The kernel has own compiled in limit for pids.max inside
cgroup (see pids_max_write in kernel code).

Thus don't exceed it on write.

https://jira.sw.ru/browse/PSBM-62906

Signed-off-by: Cyrill Gorcunov <gorcunov@openvz.org>
---
 lib/cgroup.h    | 4 ++++
 lib/env_nsops.c | 2 ++
 2 files changed, 6 insertions(+)

Patch hide | download patch | download mbox

diff --git a/lib/cgroup.h b/lib/cgroup.h
index 8dd74a2..23bd45a 100644
--- a/lib/cgroup.h
+++ b/lib/cgroup.h
@@ -40,6 +40,10 @@ 
 #define CG_SWAP_LIMIT	"memory.memsw.limit_in_bytes"
 #define CG_NET_CLASSID	"net_cls.classid"
 
+/* For x86-64 kernels */
+#define PID_MAX_LIMIT		(4 * 1024 * 1024)
+#define PIDS_MAX		(PID_MAX_LIMIT + 1ULL)
+
 struct vzctl_env_handle;
 
 const char *cg_get_slice_name(void);
diff --git a/lib/env_nsops.c b/lib/env_nsops.c
index 3ebb8fb..4c6404a 100644
--- a/lib/env_nsops.c
+++ b/lib/env_nsops.c
@@ -393,6 +393,8 @@  static int ns_apply_res_param(struct vzctl_env_handle *h,
 
 	if (env->res->ub->numproc) {
 		ret = cg_set_ull(EID(h), CG_PIDS, "pids.max",
+				env->res->ub->numproc->l >= PIDS_MAX ?
+				PID_MAX_LIMIT :
 				env->res->ub->numproc->l);
 		if (ret == -1)
 			goto err;