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";