-1

On our Linux RHEL servers fs.file-max is set to 100000

sysctl -p | grep fs.file-max
fs.file-max = 100000

From my understanding the file-max kernel parameter refers to open file descriptors, and file-nr gives us the current number of open file descriptors. But lsof lists all open files, including files which are not using file descriptors – such as current working directories, memory mapped library files, and executable text files.

Is the following lsof really a good indication that we have reached the fs.file-max value?

lsof | wc -l

or

[[ `lsof | wc -l` -gt 100000 ]] && echo "please increase the fs.file-max"

other relevant links - How to display open file descriptors but not using lsof command

yael
  • 13,106

1 Answers1

2

This

[[ `lsof | wc -l` -gt 100000 ]] && echo "please increase the fs.file-max"

will be misleading. See reference below.

Based on RHEL 5 Tuning, the output of cat /proc/sys/fs/file-nr can be used. We can compare the first and last fields of the output. The first field shows total allocated file handles and the last field shows the maximum file handles that can be allocated. So setup a check so that once, say 90% is reached, a warning is displayed:

[[ $(echo "$(cat /proc/sys/fs/file-nr | cut -f1) / $(cat /proc/sys/fs/file-nr | cut -f3) * 100" | bc -l) -ge 90 ]] \
  && echo "90% reached. Please increase the fs.file-max"


Some difference between lsof and file-nr output:

The file-max kernel parameter refers to open file descriptors, and file-nr gives us the current number of open file descriptors. But lsof lists all open files, including files which are not using file descriptors – such as current working directories, memory mapped library files, and executable text files.

See Reference

GMaster
  • 6,322