Monday, September 14, 2015

RHEL 6.5 out of memory (actually out of threads/open files)

Had a user that kept saying his machine ran out of memory.  How that is possible was confusing me.  This machine had 32 gb of ram.  No way is it running out of memory which was the case. 

Some error messages:

Java can't start. Out of memory.
Java garbage collector can't start.  No memory available.

By default the max open files is only set to 1024.  It is more about process threads instead of actual open files.  Here is how I fixed it.

To find out how many threads you currently have open:

ps -eLf | "username" (don't type the quotes) | wc -l

Compare that number to:

cat /proc/self/limit

2 numbers that matter:
-Max processes
-Max open files

Need to change the following:

edit /etc/sysctl.conf

add fs.file-max = 65536

edit /etc/security/limits.conf
add the following:

* soft nproc 65535
* hard nproc 65535
* soft nofile 65535
* hard nofile 65535

Rerun cat /proc/self/limit or ulimit -n

Verify the number has changed.  If it has not you will also have to comment out the one line in this file.

/etc/security/limits.d/90-nproc.conf
Comment out the line with * nproc.

Check again.

Also if you wanted to script this:

echo "fs.file-max = 65536" >> /etc/sysconf.
echo "* soft nproc 65535" >> /etc/security/limits.conf
echo "* hard nproc 65535" >> /etc/security/limits.conf
echo "* soft nofile 65535" >> /etc/security/limits.conf
echo "* hard nofile 65535" >> /etc/security/limits.conf
sed  -i 's|'"* soft nproc 1024"'.*|'"#* soft nproc 1024"'|' /etc/security/limits.d/90-nproc.conf

Source:  Link Link Link

ShareThis