Projects STRLCPY criu Commits 32d6e7b5
🤬
  • ■ ■ ■ ■ ■ ■
    criu/cr-restore.c
    skipped 2325 lines
    2326 2326   return 0;
    2327 2327  }
    2328 2328   
    2329  -static void rlimit_unlimit_nofile_self(void)
    2330  -{
    2331  - struct rlimit new;
    2332  - 
    2333  - new.rlim_cur = kdat.sysctl_nr_open;
    2334  - new.rlim_max = kdat.sysctl_nr_open;
    2335  - 
    2336  - if (prlimit(getpid(), RLIMIT_NOFILE, &new, NULL)) {
    2337  - pr_perror("rlimir: Can't setup RLIMIT_NOFILE for self");
    2338  - return;
    2339  - } else
    2340  - pr_debug("rlimit: RLIMIT_NOFILE unlimited for self\n");
    2341  - service_fd_rlim_cur = kdat.sysctl_nr_open;
    2342  -}
    2343  - 
    2344 2329  int cr_restore_tasks(void)
    2345 2330  {
    2346 2331   int ret = -1;
    2347  - 
    2348  - /*
    2349  - * Service fd engine implies that file descriptors
    2350  - * used won't be borrowed by the rest of the code
    2351  - * and default 1024 limit is not enough for high
    2352  - * loaded test/containers. Thus use kdat engine
    2353  - * to fetch current system level limit for numbers
    2354  - * of files allowed to open up and lift up own
    2355  - * limits.
    2356  - *
    2357  - * Note we have to do it before the service fd
    2358  - * get inited and we dont exit with errors here
    2359  - * because in worst scenario where clash of fd
    2360  - * happen we simply exit with explicit error
    2361  - * during real action stage.
    2362  - */
    2363  - rlimit_unlimit_nofile_self();
    2364 2332   
    2365 2333   if (cr_plugin_init(CR_PLUGIN_STAGE__RESTORE))
    2366 2334   return -1;
    skipped 1215 lines
  • ■ ■ ■ ■ ■ ■
    criu/crtools.c
    skipped 49 lines
    50 50  #include "setproctitle.h"
    51 51  #include "sysctl.h"
    52 52   
    53  -static int early_init(void)
     53 +static void rlimit_unlimit_nofile(void)
     54 +{
     55 + struct rlimit new;
     56 + 
     57 + new.rlim_cur = kdat.sysctl_nr_open;
     58 + new.rlim_max = kdat.sysctl_nr_open;
     59 + 
     60 + if (prlimit(getpid(), RLIMIT_NOFILE, &new, NULL)) {
     61 + pr_perror("rlimit: Can't setup RLIMIT_NOFILE for self");
     62 + return;
     63 + } else
     64 + pr_debug("rlimit: RLIMIT_NOFILE unlimited for self\n");
     65 + 
     66 + service_fd_rlim_cur = kdat.sysctl_nr_open;
     67 +}
     68 + 
     69 +static int early_init(const char *cmd)
    54 70  {
     71 + static const char *nofile_cmds[] = {
     72 + "swrk", "service",
     73 + "dump", "pre-dump",
     74 + "restore",
     75 + };
     76 + size_t i;
     77 + 
     78 + /*
     79 + * Service fd engine implies that file descriptors
     80 + * used won't be borrowed by the rest of the code
     81 + * and default 1024 limit is not enough for high
     82 + * loaded test/containers. Thus use kdat engine
     83 + * to fetch current system level limit for numbers
     84 + * of files allowed to open up and lift up own
     85 + * limits.
     86 + *
     87 + * Note we have to do it before the service fd
     88 + * get inited and we dont exit with errors here
     89 + * because in worst scenario where clash of fd
     90 + * happen we simply exit with explicit error
     91 + * during real action stage.
     92 + *
     93 + * Same time raising limits cause kernel fdtable
     94 + * to bloat so we do this only on the @nofile_cmds:
     95 + *
     96 + * - on dump criu needs additional files for sfd,
     97 + * thus if container already has many files opened
     98 + * we need to have at least not less space when
     99 + * fetching fds from a target process;
     100 + *
     101 + * - on pre-dump we might need a lot of pipes to
     102 + * fetch huge number of pages to dump;
     103 + *
     104 + * - on restore we still need to raise limits since
     105 + * there is no guarantee that on dump we've not
     106 + * been hitting fd limit already;
     107 + *
     108 + * - swrk and service obtain requests on the fly,
     109 + * thus we don't know if on of above will be
     110 + * there thus raise limits.
     111 + */
     112 + for (i = 0; i < ARRAY_SIZE(nofile_cmds); i++) {
     113 + if (strcmp(nofile_cmds[i], cmd))
     114 + continue;
     115 + if (!kerndat_files_stat(true))
     116 + rlimit_unlimit_nofile();
     117 + break;
     118 + }
     119 + 
    55 120   if (init_service_fd())
    56 121   return 1;
    57 122   
    skipped 35 lines
    93 158   
    94 159   log_set_loglevel(opts.log_level);
    95 160   
    96  - if (early_init())
     161 + if (early_init(argv[optind]))
    97 162   return -1;
    98 163   
    99 164   if (!strcmp(argv[1], "swrk")) {
    skipped 358 lines
Please wait...
Page is in error, reload to recover