From 543b50dcf51f39d21e9b0a27d25d0c4b00076119 Mon Sep 17 00:00:00 2001 From: h7x4 Date: Wed, 24 Dec 2025 08:47:14 +0900 Subject: [PATCH] Add `withJemalloc` setting, enable by default --- synapse-module/default.nix | 13 +++++++++++++ synapse-module/workers.nix | 6 ++++++ 2 files changed, 19 insertions(+) diff --git a/synapse-module/default.nix b/synapse-module/default.nix index 52efe58..9867425 100644 --- a/synapse-module/default.nix +++ b/synapse-module/default.nix @@ -70,6 +70,14 @@ in ''; }; + withJemalloc = mkOption { + type = types.bool; + default = true; + description = '' + Whether to preload jemalloc to reduce memory fragmentation and overall usage. + ''; + }; + dataDir = mkOption { type = types.path; default = "/var/lib/matrix-synapse"; @@ -425,6 +433,11 @@ in partOf = [ "matrix-synapse.target" ]; wantedBy = [ "matrix-synapse.target" ]; + environment = lib.optionalAttrs cfg.withJemalloc { + LD_PRELOAD = "${pkgs.jemalloc}/lib/libjemalloc.so"; + PYTHONMALLOC = "malloc"; + }; + serviceConfig = { Type = "notify"; User = "matrix-synapse"; diff --git a/synapse-module/workers.nix b/synapse-module/workers.nix index b0a20ec..9e4dbd3 100644 --- a/synapse-module/workers.nix +++ b/synapse-module/workers.nix @@ -374,6 +374,12 @@ in { wantedBy = [ "matrix-synapse.target" ]; after = [ "matrix-synapse.service" ]; requires = [ "matrix-synapse.service" ]; + + environment = lib.optionalAttrs cfg.withJemalloc { + LD_PRELOAD = "${pkgs.jemalloc}/lib/libjemalloc.so"; + PYTHONMALLOC = "malloc"; + }; + serviceConfig = { Type = "notify"; User = "matrix-synapse";