passt: Set soft limit for number of open files to hard limit

Default value for /proc/sys/fs/nr_open is 2^20, which is more than
enough: set this hard limit as current (soft) limit on start, and
drop the 'ulimit -n' from the demo script.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
Stefano Brivio 2021-03-18 11:36:55 +01:00
parent 48ca38c606
commit ef25cb39a9
2 changed files with 12 additions and 1 deletions

View file

@ -75,7 +75,6 @@ sysctl -w net.ipv6.conf.all.forwarding=1
ethtool -K veth_passt tx off ethtool -K veth_passt tx off
ip netns exec passt ethtool -K veth_passt tx off ip netns exec passt ethtool -K veth_passt tx off
ip netns exec passt sysctl -w net.ipv4.ping_group_range="0 2147483647" ip netns exec passt sysctl -w net.ipv4.ping_group_range="0 2147483647"
ulimit -n 300000
ip netns exec passt ./passt ip netns exec passt ./passt

12
passt.c
View file

@ -18,6 +18,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/resource.h>
#include <sys/un.h> #include <sys/un.h>
#include <ifaddrs.h> #include <ifaddrs.h>
#include <linux/if_ether.h> #include <linux/if_ether.h>
@ -513,6 +514,7 @@ int main(int argc, char **argv)
struct timespec last_time; struct timespec last_time;
struct ctx c = { 0 }; struct ctx c = { 0 };
int nfds, i, fd_unix; int nfds, i, fd_unix;
struct rlimit limit;
if (argc != 1) if (argc != 1)
usage(argv[0]); usage(argv[0]);
@ -528,6 +530,16 @@ int main(int argc, char **argv)
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (getrlimit(RLIMIT_NOFILE, &limit)) {
perror("getrlimit");
exit(EXIT_FAILURE);
}
limit.rlim_cur = limit.rlim_max;
if (setrlimit(RLIMIT_NOFILE, &limit)) {
perror("setrlimit");
exit(EXIT_FAILURE);
}
if (icmp_sock_init(&c) || tcp_sock_init(&c) || udp_sock_init(&c)) if (icmp_sock_init(&c) || tcp_sock_init(&c) || udp_sock_init(&c))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);