diff options
author | Vaxry <[email protected]> | 2024-06-18 21:52:55 +0200 |
---|---|---|
committer | Vaxry <[email protected]> | 2024-06-18 21:53:01 +0200 |
commit | e0e3c4c6ae15af88ac5fd5ab959adfe45a2e1dca (patch) | |
tree | 62c79e8df3b436b549ca31833dab876b6672fca9 | |
parent | b98e0876d3b54b7625bacf14e3546dd2d0e600d0 (diff) | |
download | Hyprland-e0e3c4c6ae15af88ac5fd5ab959adfe45a2e1dca.tar.gz Hyprland-e0e3c4c6ae15af88ac5fd5ab959adfe45a2e1dca.zip |
compositor: bump nofile rlimits on launch
ref #6584
-rw-r--r-- | src/Compositor.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp index 2f972335..af46b0ff 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -29,6 +29,7 @@ using namespace Hyprutils::String; #include <sys/types.h> #include <sys/stat.h> +#include <sys/resource.h> int handleCritSignal(int signo, void* data) { Debug::log(LOG, "Hyprland received signal {}", signo); @@ -70,6 +71,46 @@ void handleUserSignal(int sig) { } } +static void bumpNofile() { + unsigned long limit = 1024; + + try { + std::ifstream f("/proc/sys/fs/nr_open"); + if (!f.good()) + limit = 1073741816; + else { + std::string content((std::istreambuf_iterator<char>(f)), (std::istreambuf_iterator<char>())); + f.close(); + + limit = std::stoll(content); + } + + } catch (...) { limit = 1073741816; } + + struct rlimit rlimit_; + if (!getrlimit(RLIMIT_NOFILE, &rlimit_)) + Debug::log(LOG, "Old rlimit: soft -> {}, hard -> {}", rlimit_.rlim_cur, rlimit_.rlim_max); + + if (rlimit_.rlim_max <= 1024) + rlimit_.rlim_max = limit; + + unsigned long oldHardLimit = rlimit_.rlim_max; + + rlimit_.rlim_max = limit; + + if (setrlimit(RLIMIT_NOFILE, &rlimit_) < 0) { + Debug::log(LOG, "Failed bumping NOFILE limits higher, retrying with previous hard."); + rlimit_.rlim_max = oldHardLimit; + rlimit_.rlim_cur = std::clamp((unsigned long)limit, 1UL, (unsigned long)rlimit_.rlim_max); + + if (setrlimit(RLIMIT_NOFILE, &rlimit_) < 0) + Debug::log(LOG, "Failed bumping NOFILE limits higher for the second time."); + } + + if (!getrlimit(RLIMIT_NOFILE, &rlimit_)) + Debug::log(LOG, "New rlimit: soft -> {}, hard -> {}", rlimit_.rlim_cur, rlimit_.rlim_max); +} + CCompositor::CCompositor() { m_iHyprlandPID = getpid(); @@ -131,6 +172,8 @@ CCompositor::CCompositor() { setRandomSplash(); Debug::log(LOG, "\nCurrent splash: {}\n\n", m_szCurrentSplash); + + bumpNofile(); } CCompositor::~CCompositor() { |