• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Set Resource Limits for a Process with Systemd in CentOS/RHEL 7 and 8

by admin

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.

Filed Under: CentOS/RHEL 7, CentOS/RHEL 8, Linux

Some more articles you might also be interested in …

  1. How to restore files under user’s home directory to default in Linux
  2. Oracle OS watcher (OSWatcher) – Understanding oswmpstat
  3. How to disable avahi-daemon service in CentOS/RHEL
  4. certbot: command not found
  5. How to merge 2 volume groups (VGs) into one using vgmerge in LVM
  6. How to change the PATH variable in Linux
  7. “yum clean all” not clearing yum repository cache in CentOS/RHEL/OEL
  8. Apache HTTP server – most commonly used configuration directives
  9. kdialog: command not found
  10. openfortivpn Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright