6
6
#include <sys/types.h>
7
7
#include <sys/stat.h>
8
8
#include <sys/wait.h>
9
+ #include <sys/resource.h>
9
10
#include <fcntl.h>
10
11
#include <dirent.h>
11
12
#include <sched.h>
@@ -1144,6 +1145,8 @@ static int hyper_loop(void)
1144
1145
struct epoll_event * events ;
1145
1146
struct hyper_pod * pod = & global_pod ;
1146
1147
sigset_t mask , omask ;
1148
+ struct rlimit limit ;
1149
+ char * filemax = "1000000" ;
1147
1150
1148
1151
sigemptyset (& mask );
1149
1152
sigaddset (& mask , SIGCHLD );
@@ -1162,6 +1165,31 @@ static int hyper_loop(void)
1162
1165
sigdelset (& omask , SIGCHLD );
1163
1166
signal (SIGCHLD , hyper_init_sigchld );
1164
1167
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
+
1165
1193
ctl .efd = epoll_create1 (EPOLL_CLOEXEC );
1166
1194
if (ctl .efd < 0 ) {
1167
1195
perror ("epoll_create failed" );
0 commit comments