1

I have set ulimit -m 1000000 for my shell, then started a process that consumes a bunch of memory (a simple python script from https://unix.stackexchange.com/questions/99334/how-to-fill-90-of-the-free-memory). I tell my python script to consume 2G of memory and it appears to do so (this output from htop):

    Mem[|||||||||||||||||||||||||||||||||1742/1839MB]     Uptime: 137 days(!), 16:56:32
    Swp[|||||||||||||                     591/2047MB]

  PID  USER   PRI  NI  VIRT   RES   SHR S CPU% MEM%   TIME+  Command               
  6207 mikes  20   0  2123M 1625M   156 S  0.0 88.3  0:08.77 python ./consume_memory 2000

...Look at the "RES" column and the "MEM" graph above.

ulimit -a shows:

max memory size         (kbytes, -m) 1000000

...Why didn't my process fail to start? If I set my virtual memory size with ulimit -v 1500000, for example, my process fails as expected:

$ ./consume_memory 900
Traceback (most recent call last):
  File "./consume_memory", line 14, in <module>
    data = megabyte * count
MemoryError

System specs:

CentOS Linux release 7.2.1511 (Core) 
Linux hostname 3.10.0-327.el7.x86_64 #1 SMP Thu Nov 19 22:10:57 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)
1

1 Answer 1

3

In bash if we do command -V ulimit we find ulimit is a shell builtin, so we can do help ulimit which says

 -m        the maximum resident set size

so we are setting the RSS. To see what system call bash is actually using, we can try

$ strace bash -c 'ulimit -m 10000'
setrlimit(RLIMIT_RSS, {rlim_cur=10000*1024, rlim_max=10000*1024}) = 0

and then see in man setrlimit that

RLIMIT_RSS. Specifies the limit (in pages) of the process's resident set (the number of virtual pages resident in RAM). This limit has effect only in Linux 2.4.x, x < 30, and there affects only calls to madvise(2) specifying MADV_WILLNEED.

So it looks like it has no effect in Linux these days.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .