Tags

, , , , , ,


These were some approaches that I came across while trying to limit Resident Memory Consumption for software on our Deployment Boxes. 

Setting Virtual Memory

#Sets Virtual size of the program. Eventual termination condition
ulimit -v <size_in_kb>

Setting Real Memory / RSS

Via limits.conf

In /etc/security/limits.conf :-

RSS can be set but this does not work on Ubuntu:-
Bug Report: https://bugs.launchpad.net/ubuntu/+source/linux/+bug/701141

Via UpStart

http://upstart.ubuntu.com/wiki/Stanzas#limit
http://manpages.ubuntu.com/manpages/maverick/man5/init.5.html

Via cgroup

You can accomplish this using cgroups. The short version (tested on Ubuntu 11.04) is:
Install the cgroup-bin package.
Edit /etc/cgconfig.config and create a group with limited memory. For instance, I added:

group limited {
  memory {
    memory.limit_in_bytes = 50M;
  }
}

Run

$ sudo restart cgconfig
$ sudo chown -R jlebar /sys/fs/cgroup/memory/limited
$ cgexec -g memory:limited your/program

I observed my process with an RSS of 93M when I asked it to use only 50M, but that wasn’t a problem for me, since my goal was just to get the program to page.

cgclassify theoretically lets you attach restrictions to a running process, but it didn’t appear to restrict RSS at all.

Reference : http://stackoverflow.com/questions/3043709/resident-set-size-rss-limit-has-no-effect
Reference Long : http://jlebar.com/2011/6/15/Limiting_the_amount_of_RAM_a_program_can_use.html

This was originally compiled from various sources on a Redmine wiki. All references have been included.

Advertisements