Why isn't "(ulimit -d 1000; firefox) &" working?

1

2

I'm trying to limit the memory usage of firefox to prevent it from stalling the whole system with problematic web sites.

I tried, in bash:

(ulimit -d 1000; firefox) &

This should limit the memory usage to 1000kB. Then I opened YouTube, and noticed, in top, that firefox is using 2.6% of the memory, or about 200MB, and not crashing. Clearly the limit is being ignored. Why is that, and how can I enforce it correctly?

MaxB

Posted 2014-08-24T00:42:22.950

Reputation: 186

Er, I'm confused. Is -d supposed to limit the heap? I thought the heap was considered separate from the data segment, but the manpage for setrlimit(2) says that RLIMIT_DATA sets The maximum size of the process's data segment (initialized data, uninitialized data, and heap). – rakslice – 2014-08-24T04:28:35.520

@rakslice as your quote suggests, the data segment includes everything. On Linux, I believe a process just asks the OS to resize its "space" (data segment). It's up to the library (libc) to present a convenient interface (malloc/heap). – MaxB – 2014-08-24T05:37:51.380

1Does it work without the sub-shell? I.e., what happens if you do ulimit -d 1000; firefox? Also, does ulimit -m do what you want? – sds – 2014-08-24T05:52:00.163

Answers

3

Use ulimit -v instead.

Explanation:

Current libc implementations resize the data segment only for small mallocs, big mallocs use anonymous mmap()ing so the only way to really limit the program is to limit virtual memory instead (-v switch).

Hope this helps.

PS: I know this question is very old but failed to find a solution with Google so decided to answer anyway.

Matías Moreno

Posted 2014-08-24T00:42:22.950

Reputation: 46