How to put a limit (Memory Max=) on a systemd service in a Raspberry Pi?

  • So, I want to make changes on system.config. But when I type nano /etc/systemd/system.conf says File '/etc/systemd/system.conf' is unwritable.

    I want to make this change because I want to put memory usage limits on some services that I use. I tried added the line MemoryMax=100M in a .service, but does not seem to have any limit on the service. I read a little and people say to edit the system.config to make this changes.

    It's possible? If yes: how?

  • is unwritable

    Because the system partition of LibreELEC is a read-only partition, which is for a good reason. LibreELEC is set up for use as a HTPC environment, it's not meant for the typical tweaking & fiddling IT tinkerer.

    You can edit things of you mount the partition as writeable first.

    Just know that all edits will be gone with the next LibreELEC downgrade/upgrade.

  • Online docs talk about global limits but I believe you can set them in individual service files too, and /storage/.config/system.d/ allows you to override any of the embedded .service files with your own (stop/disable the embedded service, then enable/start the custom one). LE doesn't allow you to install things to the core OS (everything is inside a read-only squashfs image) so any extra things you added via docker (or things wrapped as Kodi binary add-ons) must be using the persistent /storage area which is writeable so you can make direct changes.

  • /storage/.config/system.d/ allows you to override any of the embedded .service files with your own

    I'm testing this How to set limits (ulimit) for services run by systemd in CentOS/RHEL 7 – The Geek Diary

    Creating a file in /storage/.config/system.d/myservice.service.d/ulimit.conf and put it inside

    Code
    [Service]
    MemoryMax=100M

    Don't know if it works! But when I was doing a systemctl show myservice.service -p MemoryMax before said MemoryMax=infinity, and after creating this file says MemoryMax=104857600.

    Hope it work!

  • I'm testing this How to set limits (ulimit) for services run by systemd in CentOS/RHEL 7 – The Geek Diary

    Creating a file in /storage/.config/system.d/myservice.service.d/ulimit.conf and put it inside

    Code
    [Service]
    MemoryMax=100M

    Don't know if it works! But when I was doing a systemctl show myservice.service -p MemoryMax before said MemoryMax=infinity, and after creating this file says MemoryMax=104857600.

    Hope it work!

    This did not work :(

  • You ad this parameter to one real service file or empty one?


    I have added it to tigervnc service and it is in use.

  • You ad this parameter to one real service file or empty one?


    I have added it to tigervnc service and it is in use.

    I added for a real service.

    Can you show your .service to I see how you do?

    Memory: 1.0M

    When I do systemctl status myservice.service never show this!

  • Weird! My .service is like your, but like I said when I do systemctl status it doesn't show Memory: 1.0M (max: 100.0M

    like your.

    You have made alterations on /etc/systemd/system.conf?

  • Do you see Memory line with kodi service?

  • Do you see Memory line with kodi service?

    No. Look:

  • Well, then you are using LE 8.2 I assume.

    Use LE 9 and you will see this line :) Or use MemoryLimit=100M argument ;) Because this is supported with systemd 232.

    No. I'm in LE 9. Before I use LE 9 I'm was in beta version, so I update via own LE.

    You think this has made something wrong?

    How can I check which systemd version I'm on?

    I tried MemoryLimit=100M argument too, and don't work. Does not show in status.

  • systemctl --version

    Show this:

    Code
    systemctl --version
    systemd 239
    -PAM -AUDIT -SELINUX -IMA -APPARMOR -SMACK +SYSVINIT -UTMP -LIBCRYPTSETUP -GCRYPT -GNUTLS -ACL -XZ -LZ4 -SECCOMP +BLKID -ELFUTILS +KMOD -IDN2 -IDN -PCRE2 default-hierarchy=hybrid