2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-30 22:05:36 +00:00

sfd: Lift up own fd limit on bootup

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@openvz.org>
This commit is contained in:
Cyrill Gorcunov
2017-05-30 21:13:33 +03:00
committed by Andrei Vagin
parent b55eb53c1e
commit d0ffc478ea

View File

@@ -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"
@@ -231,6 +234,20 @@ static void soccr_print_on_level(unsigned int loglevel, const char *format, ...)
va_end(args);
}
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[])
{
@@ -339,6 +356,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;