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?

    Supercalifragilisticexpialidocious! (inscribed in large friendly letters)

    My hardware is a Raspberry Pi 3b

  • 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.

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

    How can I make it writable?

    Supercalifragilisticexpialidocious! (inscribed in large friendly letters)

    My hardware is a Raspberry Pi 3b

  • /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
    1. [Service]
    2. 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!

    Supercalifragilisticexpialidocious! (inscribed in large friendly letters)

    My hardware is a Raspberry Pi 3b

  • 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
    1. [Service]
    2. 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 :(

    Supercalifragilisticexpialidocious! (inscribed in large friendly letters)

    My hardware is a Raspberry Pi 3b

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


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

    Gone...

  • 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!

    Supercalifragilisticexpialidocious! (inscribed in large friendly letters)

    My hardware is a Raspberry Pi 3b

  • Gone...

  • 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?

    Supercalifragilisticexpialidocious! (inscribed in large friendly letters)

    My hardware is a Raspberry Pi 3b

  • Do you see Memory line with kodi service?

    Gone...

  • Do you see Memory line with kodi service?

    No. Look:

    Supercalifragilisticexpialidocious! (inscribed in large friendly letters)

    My hardware is a Raspberry Pi 3b

  • 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.

    Gone...

  • 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.

    Supercalifragilisticexpialidocious! (inscribed in large friendly letters)

    My hardware is a Raspberry Pi 3b

  • systemctl --version

    Show this:

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

    Supercalifragilisticexpialidocious! (inscribed in large friendly letters)

    My hardware is a Raspberry Pi 3b