From 7bf47b19826e5d45277a4306fba28d3fd98e88f6 Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Tue, 31 Mar 2020 13:41:50 +0200 Subject: [PATCH] base-linux: boost max open fds to the hard rlimit This patch increases the default limit of the maximum number of open file descriptors to the hard limit of the system. This is needed for complex scenarios, which require more FDs than the default of 1024 at core. Related to issue #3581 Fixes #3721 --- .../src/core/include/core_linux_syscalls.h | 23 +++++++++++++++++++ repos/base-linux/src/core/platform.cc | 3 +++ repos/gems/run/leitzentrale.run | 10 -------- repos/gems/run/tiled_wm.run | 9 -------- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/repos/base-linux/src/core/include/core_linux_syscalls.h b/repos/base-linux/src/core/include/core_linux_syscalls.h index c3bd08514..a18e77d44 100644 --- a/repos/base-linux/src/core/include/core_linux_syscalls.h +++ b/repos/base-linux/src/core/include/core_linux_syscalls.h @@ -19,6 +19,7 @@ #define size_t __SIZE_TYPE__ /* see comment in 'linux_syscalls.h' */ #include +#include #include #undef size_t @@ -72,6 +73,7 @@ inline int lx_stat(const char *path, struct stat64 *buf) #endif } + /*********************************************************** ** Functions used by core's io port session support code ** ***********************************************************/ @@ -180,6 +182,27 @@ inline void lx_disable_aslr() } +/*********************************** + ** Resource-limit initialization ** + ***********************************/ + +inline void lx_boost_rlimit() +{ + rlimit rlimit { }; + + if (int const res = lx_syscall(SYS_getrlimit, RLIMIT_NOFILE, &rlimit)) { + Genode::warning("unable to obtain RLIMIT_NOFILE (", res, "), keeping limit unchanged"); + return; + } + + /* increase soft limit to hard limit */ + rlimit.rlim_cur = rlimit.rlim_max; + + if (int const res = lx_syscall(SYS_setrlimit, RLIMIT_NOFILE, &rlimit)) + Genode::warning("unable to boost RLIMIT_NOFILE (", res, "), keeping limit unchanged"); +} + + /******************************************** ** Communication over Unix-domain sockets ** ********************************************/ diff --git a/repos/base-linux/src/core/platform.cc b/repos/base-linux/src/core/platform.cc index 927baf19c..d4ff1d7fb 100644 --- a/repos/base-linux/src/core/platform.cc +++ b/repos/base-linux/src/core/platform.cc @@ -94,6 +94,9 @@ Platform::Platform() /* make 'mmap' behave deterministically */ lx_disable_aslr(); + /* increase maximum number of open file descriptors to the hard limit */ + lx_boost_rlimit(); + /* catch control-c */ lx_sigaction(LX_SIGINT, sigint_handler, false); diff --git a/repos/gems/run/leitzentrale.run b/repos/gems/run/leitzentrale.run index 6dc91398e..cded4fe7c 100644 --- a/repos/gems/run/leitzentrale.run +++ b/repos/gems/run/leitzentrale.run @@ -350,15 +350,5 @@ build { server/lx_block app/menu_view app/sculpt_manager } build_boot_image { lx_block menu_view sculpt_manager ahci-1.img } -if {[have_spec linux]} { - set max_fds [exec bash -c "ulimit -n"] - if {$max_fds < 4096} { - puts stderr "\nMaximum number of file descriptors is too low for this run script." - puts stderr "You may use the following command to increase the limit:\n" - puts stderr " ulimit -n 4096\n" - exit 1 - } -} - run_genode_until forever diff --git a/repos/gems/run/tiled_wm.run b/repos/gems/run/tiled_wm.run index ca9238350..8c9a11fce 100644 --- a/repos/gems/run/tiled_wm.run +++ b/repos/gems/run/tiled_wm.run @@ -12,15 +12,6 @@ if {[have_spec odroid_xu]} { exit 0 } -if {[have_spec linux]} { - set max_fds [exec bash -c "ulimit -n"] - if {$max_fds < 4096} { - puts stderr "\nMaximum number of file descriptors is too low for this run script." - puts stderr "You may use the following command to increase the limit:\n" - puts stderr " ulimit -n 4096\n" - exit 1 - } -} # # Generate config