[CRIU] [PATCH 4/4] sfd: Lift up own fd limit on bootup
Cyrill Gorcunov
gorcunov at openvz.org
Tue May 30 11:13:33 PDT 2017
This minimize chances to hit problem where files
used for page transfer are trying to use same number
reserved for service fd.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
criu/crtools.c | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/criu/crtools.c b/criu/crtools.c
index b20d2ec09164..bba52b12856e 100644
--- a/criu/crtools.c
+++ b/criu/crtools.c
@@ -19,6 +19,9 @@
#include <dlfcn.h>
+#include <sys/time.h>
+#include <sys/resource.h>
+
#include "int.h"
#include "page.h"
#include "common/compiler.h"
@@ -47,6 +50,7 @@
#include "fault-injection.h"
#include "lsm.h"
#include "proc_parse.h"
+#include "kerndat.h"
#include "setproctitle.h"
#include "sysctl.h"
@@ -208,6 +212,20 @@ bool deprecated_ok(char *what)
return false;
}
+static void rlimit_unlimit_nofile_self(void)
+{
+ struct rlimit new;
+
+ new.rlim_cur = kdat.sysctl_nr_open;
+ new.rlim_max = kdat.sysctl_nr_open;
+
+ if (prlimit(getpid(), RLIMIT_NOFILE, &new, NULL)) {
+ pr_perror("rlimir: Can't setup RLIMIT_NOFILE for self");
+ return;
+ } else
+ pr_debug("rlimit: RLIMIT_NOFILE unlimited for self\n");
+}
+
int main(int argc, char *argv[], char *envp[])
{
@@ -314,6 +332,24 @@ int main(int argc, char *argv[], char *envp[])
init_opts();
+ /*
+ * Service fd engine implies that file descritprs
+ * used won't be borrowed by the rest of the code
+ * and default 1024 limit is not enough for high
+ * loaded test/containers. Thus use kdat engine
+ * to fetch current system level limit for numbers
+ * of files allowed to open up and lift up own
+ * limits.
+ *
+ * Note we have to do it before the service fd
+ * get inited and we dont exit with errors here
+ * because in worst scenario where clash of fd
+ * happen we simply exit with explicit error
+ * during real action stage.
+ */
+ if (!kerndat_files_stat(true))
+ rlimit_unlimit_nofile_self();
+
if (init_service_fd())
return 1;
--
2.7.4
More information about the CRIU
mailing list