Skip to content

Tune and change max open files limit in Linux



In Linux, the maximum number of files that can be opened simultaneously is determined by the value of the ulimit command. By default, the maximum number of open files is set to a relatively low value. However, in some cases, you may need to increase this limit to allow for more concurrent connections or to improve the performance of certain applications. In this blog post, we will discuss how to tune and change the maximum number of open files in Linux.

Increasing the Max Open Files Limit

To increase the max open files limit in Linux, we need to modify the system configuration file named “/etc/security/limits.conf”. This file contains settings for user and group resource limits. To change the max open files limit, we need to add the following lines to the file:

* soft nofile 65535
* hard nofile 65535

The first line sets the soft limit for the max open files to 65535, which is the maximum number of open files that can be used by a process. The second line sets the hard limit, which is the maximum number of open files that can be used by the system as a whole. Once these changes are made, we need to reboot the system for them to take effect.

Checking the Max Open Files Limit


## File number limit
ulimit -n
ulimit -Sn
ulimit -Hn

## Maximum file descriptor
cat /proc/sys/fs/file-max

## fs.nr_open, process level
## fs.file-max, system level

## Temporary modification
sysctl -w fs.nr_open=100000000
sysctl -w fs.file-max=10000000

## Permanent modification
echo "fs.nr_open = 10000000" >> /etc/sysctl.conf
echo "fs.file-max = 11000000" >> /etc/sysctl.conf

## Temporary modification of maximum open file number
ulimit -n 10240000

## View the current number of open files
sysctl fs.file-nr

## Number of used file descriptors
cat /proc/sys/fs/file-nr |cut -f1

## Maximum number of threads
cat /proc/sys/kernel/threads-max

## Number of used threads
ps -eLf | wc -l


In conclusion, changing the max open files limit in Linux can be a useful way to improve system performance and allow more files to be opened simultaneously. By following the steps outlined in this blog post, we can increase the max open files limit and check to ensure that the changes have taken effect. As with any system configuration changes, it is important to proceed with caution and ensure that the changes are properly tested before they are implemented in a production environment.


Small world. Big idea!
  • Welcome to visit the knowledge base of SRE and DevOps!
  • License under CC BY-NC 4.0
  • Made with Material for MkDocs and improve writing by generative AI tools
  • Copyright issue feedback, replace # with @