Increasing ulimit and file descriptors limit on Linux

Getting “too many open files” errors? Here is how to increase ulimit and file descriptors settings on Linux

file-max is the maximum File Descriptors (FD). It is a kernel setting enforced at the system level. ulimit is enforced at the user level. It should be configured to be less than file-max.

Default settings for ulimit and file-max on a Linux system assume that several users (not applications) would share the system.  These settings limit the number of resources used by each user. The default settings are  very low for high performance servers and should be increased.

To change the file descriptor setting, edit the kernel parameter file /etc/sysctl.conf. Add line fs.file-max=[new value] to it.

# vi /etc/sysctl.conf
fs.file-max = 500000

Apply the changes:

#sysctl -p

To change the ulimit setting, edit the file /etc/security/limits.conf and set the hard and soft limits.

# vi /etc/security/limits.conf
* soft nofile 60000
* hard nofile 60000

Apply the changes:

# reboot

Now test the new system settings using the following commands:

#ulimit -a
open files (-n) 60000

Check the current open file descriptor limit:

# more /proc/sys/fs/file-max

Another way to check the file descriptor limit:

# sysctl -a | grep fs.file-max
fs.file-max = 500000

To find out how many file descriptors are currently being used:

# more /proc/sys/fs/file-nr

To find out how many files are currently open:

# lsof | wc -l

5 thoughts on “Increasing ulimit and file descriptors limit on Linux

  1. Pingback: MySQL process taking 150-400% CPU – Website Information

  2. Pingback: Khắc phục lỗi “Too many open file ” in linux – Do it , make it and got it

  3. Pingback: Installer Solr 4.3.0 sous tomcat 7 | Eolya Consulting

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s