Limit memory usage per user on CentOS/RHEL

Scenario: How to limit memory usage per user on CentOS/RHEL
System: CentOS/RHEL 6/7

I would like to cap the amount of memory the users on a server can use. The applications developed by our users have memory leaks and I want to prevent them from using all the memory and crashing the system.

It is possible to limit the amount of memory that each process can allocate with the RLIMIT facility in Red Hat Enterprise Linux. RLIMIT_AS limits the size of the virtual address space and it is a suitable solution in many cases which require limiting per-process memory consumption even though there are many limits related to memory.

1) Edit limit.conf
# vi /etc/security/limits.conf

2) Reboot the server
3) Show the ulimit

In the example above, processes running as ‘bachem‘ user can only use 2GB virtual address space. So, each application used by bachem cannot allocate more than 2 GB memory space.
Note : this limitation does not affect an amount of physical memory directly, and the values are in KiB (1024-byte).

Show the ulimit hard type:

Show the ulimit soft type:

For more information, refer to its manual page or examples of the configuration file:
# man ulimit
# cat /etc/security/limits.conf

Related posts:

Leave a Reply

Your email address will not be published. Required fields are marked *