core: add mallopt to modify trim threshold

This commit is contained in:
Vaxry
2025-02-09 17:38:20 +00:00
parent 56f6f61596
commit 1f97643e83
2 changed files with 17 additions and 2 deletions

View File

@@ -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")) {

View File

@@ -52,8 +52,6 @@ class CCompositor {
void startCompositor();
void stopCompositor();
void cleanup();
void createLockFile();
void removeLockFile();
void bumpNofile();
void restoreNofile();
@@ -163,6 +161,9 @@ class CCompositor {
void setRandomSplash();
void initManagers(eManagersInitStage stage);
void prepareFallbackOutput();
void createLockFile();
void removeLockFile();
void setMallocThreshold();
uint64_t m_iHyprlandPID = 0;
wl_event_source* m_critSigSource = nullptr;