4

How can I set a RAM limit for a specific user? I have tried editing the /etc/security/limits.conf file, and the RAM limits there, but I still see a users process exceeding the limit set.

I know that the limits are specified in kb, so I'm not using an incorrect number.

For instance, I am trying to set it so that a user can't use more than 2,048mb (or 2,097,152kb) of memory, and their program will use like 2500mb.

Is there any way that I can accomplish this without virtual machines? I am also trying to stay away from running virtual machines as an option.

Here's my /etc/sysconfig/limits.conf.

Also, the RSS limit is ignored since the kernel version I'm running is 2.6.18

slhck
  • 235,242

2 Answers2

1

The controls related to memory are enforced via per process resource limits. The process limits related to memory have been partly broken for a long time under Linux. Example:

$ (ulimit -m 1; emacs)

If Emacs starts up, clearly the RSS resource limit is not being enforced. The limits that I have seen work are the data segment and stack limits.

$ (ulimit -d 1; emacs)
emacs: Memory exhausted--use M-x save-some-buffers RET
$ (ulimit -s 1; emacs)
$

So use only the "data" and "stack" memory limits, since these seem to be enforced.

Kyle Jones
  • 6,364
-1

To limit the available resources for a set of processes, for users or for groups, you can use cgroups: https://www.kernel.org/doc/Documentation/cgroup-v1/cgroups.txt

Balázs
  • 124