Some specific applications or processes may need higher resource values than the default systemd assigned values. It’s possible to override the default resource limits assigned by systemd.
Basically systemd sets the default limits for any process when it starts. For example:
# cat /proc/1696/limits | grep "Max locked memory" Max locked memory 65536 65536 bytes
From the above example, the Max Locked memory is 64K for the PID 1696, and for some process or application this may not be enough. There are a couple of ways to change this.
Method 1 – Change Globally
Change the default value globally, This will take effect for all process. Edit the file /etc/systemd/system.conf and change the value there.
1. If you check, by default this value will be commented out and hence the default 64K is in effect.
# cat /etc/systemd/system.conf | grep DefaultLimitMEMLOCK #DefaultLimitMEMLOCK=
2. To change this, edit the file and uncomment the desire resource line and add desired value. For example.
# vi /etc/systemd/system.conf DefaultLimitMEMLOCK=128000
This will change the Max locked memory for “all” process to 128K when it starts.
Method 2 – Change for Specific Service or Process
If the requirement is to change the resource limit for any specific process or application, then the below method will help.
1. To change the resource value for any specific process/Service.
This can be done by editing the service unit-file and add the limit detail there with the service section. Example as below for service “test”
# vi test.service [Unit] Description=TEST SERVICE Wants=network.target network-online.target autofs.service After=network.target network-online.target autofs.service [Service] Type=simple User=farmer ExecStart=/path/to/service/executable <> LimitMEMLOCK=128000 PIDFile=/var/run/test.pid [Install] WantedBy=multi-user.target
With the above service unit file, the new line “LimitMEMLOCK=128000” will assign 128K Max Locked Memory for the specific process when it starts. All other processes will have the default value as per systemd.