diff options
| author | Dan Engelbrecht <[email protected]> | 2022-04-12 22:19:39 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-04-12 22:19:39 +0200 |
| commit | e20b70dd594108c21e8bff0dd813dd8dacdf007b (patch) | |
| tree | 3a7826231931df259f5feda355d92dcc850628b1 /zencore/filesystem.cpp | |
| parent | reduce number of chunks in compactcas.threadedinsert (diff) | |
| parent | wait until work is completed, not just picked up (diff) | |
| download | zen-e20b70dd594108c21e8bff0dd813dd8dacdf007b.tar.xz zen-e20b70dd594108c21e8bff0dd813dd8dacdf007b.zip | |
Merge pull request #72 from EpicGames/de/set-ulimit
attempt to change the maximum number of files open at startup
Diffstat (limited to 'zencore/filesystem.cpp')
| -rw-r--r-- | zencore/filesystem.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/zencore/filesystem.cpp b/zencore/filesystem.cpp index e2778089b..7ff0dc45c 100644 --- a/zencore/filesystem.cpp +++ b/zencore/filesystem.cpp @@ -23,6 +23,7 @@ #if ZEN_PLATFORM_LINUX # include <dirent.h> # include <fcntl.h> +# include <sys/resource.h> # include <sys/stat.h> # include <unistd.h> #endif @@ -31,6 +32,7 @@ # include <dirent.h> # include <fcntl.h> # include <libproc.h> +# include <sys/resource.h> # include <sys/stat.h> # include <sys/syslimits.h> # include <unistd.h> @@ -986,6 +988,31 @@ GetRunningExecutablePath() #endif // ZEN_PLATFORM_WINDOWS } +void +MaximizeOpenFileCount() +{ +#if ZEN_PLATFORM_LINUX || ZEN_PLATFORM_MAC + struct rlimit Limit; + int Error = getrlimit(RLIMIT_NOFILE, &Limit); + if (Error) + { + ZEN_WARN("failed getting rlimit RLIMIT_NOFILE, reason '{}'", zen::MakeErrorCode(Error).message()); + } + else + { + struct rlimit NewLimit = Limit; + NewLimit.rlim_cur = NewLimit.rlim_max; + ZEN_INFO("changing RLIMIT_NOFILE from rlim_cur = {}, rlim_max {} to rlim_cur = {}, rlim_max {}", Limit.rlim_cur, Limit.rlim_max, NewLimit.rlim_cur, NewLimit.rlim_max); + + Error = setrlimit(RLIMIT_NOFILE, &NewLimit); + if (Error != 0) + { + ZEN_WARN("failed to set RLIMIT_NOFILE limits from rlim_cur = {}, rlim_max {} to rlim_cur = {}, rlim_max {}, reason '{}'", Limit.rlim_cur, Limit.rlim_max, NewLimit.rlim_cur, NewLimit.rlim_max, zen::MakeErrorCode(Error).message()); + } + } +#endif +} + ////////////////////////////////////////////////////////////////////////// // // Testing related code follows... |