LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   ulimit and /etc/security/limits.conf (https://www.linuxquestions.org/questions/linux-general-1/ulimit-and-etc-security-limits-conf-646807/)

chakkerz 06-03-2008 07:51 PM

ulimit and /etc/security/limits.conf
 
I've taken a look at the threads on here and found various text's that tell me:

1) limits don't work the way people think they work
2) limits may not have the affect that one would expected, unless the code they are supposed to affect is written with limits in mind
3) IF they are used they should be used as part of a startup script, rather than refining the standard ones

Alas this does not dissuade people from demanding we tune them. Seeing as there is the potential for learning something interesting, i'm not disinclined to try :)

The central theme that continues to arise is that we want to limit the amount of RAM a process can consume. Thus i set the RSS to a hard limit of 8MB, and load my 64MB file into RAM using a quick perl script (three lines of code that reinforce once again that i need to learns some perl), and in another shell observe that the script is indeed consuming 13% of my 512MB RAM, which is my file + a slight overhead.

ulimit -a tells me my RSS is fixed at 8192 KBs, which is also what i set the Data Size to in /etc/security/limits.conf

Code:

*  hard  data 8192
*  hard  rss    8192


If anything this validates point 1 from above, it doesn't work the way at the very least i think it works, and 2) my code definitely did not consider what limits might be imposed. 3) is a mute point.

Any ideas how i can set a limit which limits memory consumption at xMB and actually have it honoured?

Cheers

chakkerz

chakkerz 06-04-2008 05:43 AM

incidentally. I've found that if i set the ulimit -v (virtual memory) which can not be set via /etc/security/limits.conf i can affect an "out of memory" message. But (as indicated above) this is not a straight forward 64MB limit, but rather it works at 256MB, but not at 128MB, even though my actual memory consumption is 64ish, but 140ish reserved for Virtual Memory.

jetole 01-23-2011 01:42 AM

If you read the man page for limits.conf, under the section for rss, you should see the line "maximum resident set size (KB) (Ignored in Linux 2.4.30 and higher)". Virtual memory is also the worst item to set relating to rss usage. Many applications have a much larger virtual size then they have resident size. If you want to get some idea of the comparison between the two then the following command will show the virtual size and the rss for each application on your system, in megabytes, sorted by virtual size ascending and you can see how the virtual size is much larger then resident size:

while read rss vsz command; do rss="$(bc <<< "scale=2; ${rss}/1024")"; vsz="$(bc <<< "scale=2; ${vsz}/1024")"; echo "${rss} ${vsz} $command"; done < <(ps --no-headers -A -o rss,vsz,comm --sort vsz)


All times are GMT -5. The time now is 07:34 AM.