How can I set a RAM limit for a specific user in Linux?

3

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

Trey G.

Posted 2012-02-26T04:46:36.257

Reputation:

Q: Is there any way that I can accomplish this without virtual machines? A: I don't think so :) – paulsm4 – 2012-02-26T04:52:27.037

can you post your /etc/security/limits.conf file? – jdizzle – 2012-02-26T05:04:23.007

I edited it with a pastebin link to the file. – None – 2012-02-26T05:09:53.903

Answers

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

Posted 2012-02-26T04:46:36.257

Reputation: 5 706

-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

CiCC

Posted 2012-02-26T04:46:36.257

Reputation: 14

link-only answers are not helpful. – Ramhound – 2016-07-18T20:58:34.037