From a27585b383cc6eb7760dc66d3c2313b4173e5a43 Mon Sep 17 00:00:00 2001 From: Vaxry Date: Sun, 9 Feb 2025 17:39:23 +0000 Subject: [PATCH] core: add mallopt to modify trim threshold --- src/core/hyprlock.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/core/hyprlock.cpp b/src/core/hyprlock.cpp index 4e2ba05..144b288 100644 --- a/src/core/hyprlock.cpp +++ b/src/core/hyprlock.cpp @@ -20,10 +20,23 @@ #include #include #include +#include using namespace Hyprutils::OS; +static void 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 +} + CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediate, const bool immediateRender) { + setMallocThreshold(); + m_sWaylandState.display = wl_display_connect(wlDisplay.empty() ? nullptr : wlDisplay.c_str()); if (!m_sWaylandState.display) { Debug::log(CRIT, "Couldn't connect to a wayland compositor");