66#include <sys/types.h>
77#include <sys/stat.h>
88#include <sys/wait.h>
9+ #include <sys/resource.h>
910#include <fcntl.h>
1011#include <dirent.h>
1112#include <sched.h>
@@ -1144,6 +1145,8 @@ static int hyper_loop(void)
11441145 struct epoll_event * events ;
11451146 struct hyper_pod * pod = & global_pod ;
11461147 sigset_t mask , omask ;
1148+ struct rlimit limit ;
1149+ char * filemax = "1000000" ;
11471150
11481151 sigemptyset (& mask );
11491152 sigaddset (& mask , SIGCHLD );
@@ -1162,6 +1165,31 @@ static int hyper_loop(void)
11621165 sigdelset (& omask , SIGCHLD );
11631166 signal (SIGCHLD , hyper_init_sigchld );
11641167
1168+ if (hyper_write_file ("/proc/sys/fs/file-max" , filemax , strlen (filemax )) < 0 ) {
1169+ fprintf (stderr , "sysctl: setup default file-max(%s) failed\n" , filemax );
1170+ return -1 ;
1171+ }
1172+
1173+ // setup open file limit
1174+ limit .rlim_cur = limit .rlim_max = atoi (filemax );
1175+ if (setrlimit (RLIMIT_NOFILE , & limit ) < 0 ) {
1176+ perror ("set rlimit for NOFILE failed" );
1177+ return -1 ;
1178+ }
1179+
1180+ // setup process num limit
1181+ limit .rlim_cur = limit .rlim_max = 30604 ;
1182+ if (setrlimit (RLIMIT_NPROC , & limit ) < 0 ) {
1183+ perror ("set rlimit for NPROC failed" );
1184+ return -1 ;
1185+ }
1186+
1187+ // setup pending signal limit, same with NRPROC
1188+ if (setrlimit (RLIMIT_SIGPENDING , & limit ) < 0 ) {
1189+ perror ("set rlimit for SIGPENDING failed" );
1190+ return -1 ;
1191+ }
1192+
11651193 ctl .efd = epoll_create1 (EPOLL_CLOEXEC );
11661194 if (ctl .efd < 0 ) {
11671195 perror ("epoll_create failed" );
0 commit comments