Most of us would have encountered “Max number of open files” or related errors, where in processes fail to open more temporary files/sockets due to the limit on number of allowed files.
Let’s take a tour of how we tweak this on Linux
“File Descriptors are data structures used by programs to get handles on files.
Sum of file descriptors used by all processes cannot exceed the max limit at the OS level.
Each process has a limit on number of file descriptor it can use.”
NOTE: Increasing File descriptors limits can increase memory utilization and thus make the server instable.
Also, the number of file descriptors created cannot be removed without rebooting the box.
Let’s go now:
1. To see the max number of open file descriptors allowed system wide
[root@joshua ~]# cat /proc/sys/fs/file-max
2. To know how many file descriptors are being used
[root@lin-c1u33-zabbix-01 ~]# cat /proc/sys/fs/file-nr
2550 0 1573026
2550: the total number of file descriptors allocated since boot
0: I am yet to find out what this really means. There are weird theories all over the place.
1573026: Max open file descriptors
3. The number of open files by a particular process. ( for example ldap )
[root@joshua ~]# ps aux | grep ldap
ldap 16094 10.8 0.7 351048 129056 ? Ssl 04:10 7:31 /usr/sbin/slapd -h ldap:/// -u ldap
root 19023 0.0 0.0 61152 744 pts/12 S+ 05:19 0:00 grep ldap
[root@joshua ~]# lsof | grep 16094 | wc -l
[root@joshua ~]# ls -l /proc/16094/fd | wc -l
The LDAP process has only 18 open file descriptors but, 54 open files associated with it.
Open files which are not using file descriptors would be library files, the program executable (binary), et all.
The count of these files are maintained in the kernel data structures, and can be seen using `cat /proc/PID/maps`, but they are not using file descriptors and so do not count in the kernel’s file descriptor list.
4. To change the limit on number of open file descriptors you can have,
[root@joshua ~]# echo “1234567″ > /proc/sys/fs/file-max
***This post has More to come… ***