Setting memory limits on Linux

You might not be aware of this, but since some time during the glibc 2.3 era, Linux apparently doesn’t enforce the RSS memory limit. (ulimit -m) My tests seem to confirm this.

As such, the only way I could find to limit a program’s memory allocations was by the VIRT size (ulimit -v)… which can differ a lot from the RSS. (Upon which the “percentage of memory used” value in system monitors is based on, if you weren’t sure)

Firefox exhibited the greatest difference I could find with just over 900MB VIRT and roughly 300MB RSS while having 48 tabs open. However, the highest I could get any program to go was 1021MB with GIMP while editing a 5000×5000 image. (I use them for practicing drawing with my Wacom tablet) In general, VIRT ranged from RSS + 200MB to RSS * 3.

Therefore, if you have a lot of RAM, you want to set a limit that can only be crossed by misbehaving programs, and you use resource-heavy stuff, I’d suggest a VIRT limit in the range of 1.2GB to 2.0GB. If you aren’t a heavy user, 800MB to 1GB should do it. (Lighter Firefox use and use of torrent clients which use mmap() produced VIRT sizes in the 600-700MB range)

Of course, if you’ve got the time, it’s always best to just open up top, KSysGuard, or whatever other system monitor you prefer, test out your favorite apps, and see where their memory usage peaks.

If you want to set it system wide, the equivalent keyword to ulimit -v in /etc/security/limits.conf is as.

CC BY-SA 4.0 Setting memory limits on Linux by Stephan Sokolow is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.

This entry was posted in Geek Stuff. Bookmark the permalink.

1 Response to Setting memory limits on Linux

  1. Pingback: Ubuntu:Mount /usr in RAM (loading from HDD when starting, and saving to when shutting down) – Ubuntu Linux Questions

Leave a Reply

Your email address will not be published. Required fields are marked *

By submitting a comment here you grant this site a perpetual license to reproduce your words and name/web site in attribution under the same terms as the associated post.

All comments are moderated. If your comment is generic enough to apply to any post, it will be assumed to be spam. Borderline comments will have their URL field erased before being approved.