From f0b1ce0a8734f8dfd6dc6f4f693ca2bf1c26376a Mon Sep 17 00:00:00 2001 From: h7x4 Date: Wed, 24 Dec 2025 08:47:14 +0900 Subject: [PATCH] synapse: 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 77f642c..2ef20d1 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 7d8e490..34c29ef 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";