diff options
| author | Vaxry <vaxry@vaxry.net> | 2025-02-09 17:38:20 +0000 |
|---|---|---|
| committer | Vaxry <vaxry@vaxry.net> | 2025-02-09 17:38:20 +0000 |
| commit | 1f97643e830d513cafc2057860bbefa5cc01a0ee (patch) | |
| tree | 204412a834a2eda76c0f011e2f16d9cedfe546ed /src/Compositor.cpp | |
| parent | 56f6f61596a547cdcdfb7aa7c3550e380b487ee3 (diff) | |
core: add mallopt to modify trim threshold
Diffstat (limited to 'src/Compositor.cpp')
| -rw-r--r-- | src/Compositor.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp index aebb0ac1..88a2530b 100644 --- a/src/Compositor.cpp +++ b/src/Compositor.cpp @@ -69,6 +69,8 @@ #include <sys/types.h> #include <sys/stat.h> #include <sys/resource.h> +#include <malloc.h> +#include <unistd.h> using namespace Hyprutils::String; using namespace Aquamarine; @@ -162,10 +164,22 @@ void CCompositor::restoreNofile() { Debug::log(ERR, "Failed restoring NOFILE limits"); } +void CCompositor::setMallocThreshold() { +#ifdef M_TRIM_THRESHOLD + // The default is 128 pages, + // which is very large and can lead to a lot of memory used for no reason + // because trimming hasn't happened + static const int PAGESIZE = sysconf(_SC_PAGESIZE); + mallopt(M_TRIM_THRESHOLD, 6 * PAGESIZE); +#endif +} + CCompositor::CCompositor(bool onlyConfig) : m_bOnlyConfigVerification(onlyConfig), m_iHyprlandPID(getpid()) { if (onlyConfig) return; + setMallocThreshold(); + m_szHyprTempDataRoot = std::string{getenv("XDG_RUNTIME_DIR")} + "/hypr"; if (m_szHyprTempDataRoot.starts_with("/hypr")) { |
