I'm trying to limit the memory usage of a systemd service, but the MemoryMax setting doesn't seem to be applied. Here's my situation:
In my service file /etc/systemd/system/discordsearch.service, I have set this under [Service]:
MemoryAccounting=true MemoryMax=2GB However, when I check the service status with systemctl status discordsearch, I see:
Memory: 3.6G Furthermore, when I run systemctl show discordsearch.service | grep Memory, I get:
MemoryCurrent=1195773952 MemoryAvailable=infinity MemoryAccounting=yes MemoryHigh=infinity MemoryMax=infinity MemoryLimit=infinity This shows that MemoryMax is set to infinity, not the 2GB I specified in the service file.
I've tried the following:
- Reloading systemd with
sudo systemctl daemon-reload - Restarting the service with
sudo systemctl restart discordsearch
/etc/systemd/system/discordsearch.service:
[Unit] Description=discordsearch [Service] Environment="LOCALE_ARCHIVE=/nix/store/djm14qz135r1cfjsid90qryxgsw2i349-glibc-locales-2.37-45/lib/locale/locale-archive" Environment="PATH=/nix/store/cm1sfanx42miqdzbwd5alxmg9lg96nag-yj-5.1.0/bin:/nix/store/l9mg93sgx50y88p5rr6x1vib6j1rjsds-coreutils-9.1/bin:/nix/store/yknc37wfb1hbnmgwmp4bm96rxwzsc692-findutils-4.9.0/bin:/nix/store/bj8a14pqhmvlha8hyv1p8bkd9kmykgjy-gnugrep-3.7/bin:/nix/store/agq64rvl0aj88ckm0kzaqgk2ddq8bvz8-gnused-4.9/bin:/nix/store/f9wkksb3lslf6q90i6c2r3qji7qcp0f2-systemd-253.6/bin:/nix/store/cm1sfanx42miqdzbwd5alxmg9lg96nag-yj-5.1.0/sbin:/nix/store/l9mg93sgx50y88p5rr6x1vib6j1rjsds-coreutils-9.1/sbin:/nix/store/yknc37wfb1hbnmgwmp4bm96rxwzsc692-findutils-4.9.0/sbin:/nix/store/bj8a14pqhmvlha8hyv1p8bkd9kmykgjy-gnugrep-3.7/sbin:/nix/store/agq64rvl0aj88ckm0kzaqgk2ddq8bvz8-gnused-4.9/sbin:/nix/store/f9wkksb3lslf6q90i6c2r3qji7qcp0f2-systemd-253.6/sbin" Environment="TZDIR=/nix/store/x376xyviyrg5rafwk5a261lviv0l9paw-tzdata-2023c/share/zoneinfo" ExecStart=/nix/store/lj1p39b4sp4k7g6qzdc0m2s6imga9yxy-HaskellNixCabalStarter-0.1.0.0/bin/discord-app MemoryAccounting=true MemoryMax=2GB Restart=always RestartSec=1 Type=simple WorkingDirectory=%h/discordsearch