Skip to content

Commit

Permalink
lkl: lkl_set_fd_limit
Browse files Browse the repository at this point in the history
So we can have more file descriptors (tcp connections).

Signed-off-by: Yuan Liu <[email protected]>
  • Loading branch information
liuyuan10 committed Nov 3, 2016
1 parent 72159d3 commit 20679a9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tools/lkl/include/lkl.h
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,12 @@ int lkl_if_del_ip(int ifindex, int af, void *addr, unsigned int netprefix_len);
*/
int lkl_if_wait_ipv6_dad(int ifindex, void *addr);

/**
* lkl_set_fd_limit - set the maximum number of file descriptors allowed
* @fd_limit - fd max limit
*/
int lkl_set_fd_limit(unsigned int fd_limit);

#ifdef __cplusplus
}
#endif
Expand Down
9 changes: 9 additions & 0 deletions tools/lkl/lib/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -363,3 +363,12 @@ int lkl_dirfd(struct lkl_dir *dir)
{
return dir->fd;
}

int lkl_set_fd_limit(unsigned int fd_limit)
{
struct lkl_rlimit rlim = {
.rlim_cur = fd_limit,
.rlim_max = fd_limit,
};
return lkl_sys_setrlimit(LKL_RLIMIT_NOFILE, &rlim);
}
7 changes: 6 additions & 1 deletion tools/lkl/lib/hijack/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ hijack_init(void)
if (single_cpu_mode == 1)
PinToFirstCpu(&ori_cpu);

ret = lkl_start_kernel(&lkl_host_ops, 64 * 1024 * 1024, "");
ret = lkl_start_kernel(&lkl_host_ops, 64 * 1024 * 1024UL, "");
if (ret) {
fprintf(stderr, "can't start kernel: %s\n", lkl_strerror(ret));
return;
Expand All @@ -335,6 +335,11 @@ hijack_init(void)
if (single_cpu_mode)
PinToCpus(&ori_cpu);

ret = lkl_set_fd_limit(65535);
if (ret)
fprintf(stderr, "lkl_set_fd_limit failed: %s\n",
lkl_strerror(ret));

/* fillup FDs up to LKL_FD_OFFSET */
ret = lkl_sys_mknod("/dev_null", LKL_S_IFCHR | 0600, LKL_MKDEV(1, 3));
dev_null = lkl_sys_open("/dev_null", LKL_O_RDONLY, 0);
Expand Down

0 comments on commit 20679a9

Please sign in to comment.