Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do linux file descriptor limits work?

I was told that my server refused to accept client network connections at a specific port could be due to the lack of file descriptors. I looked up what this is all about and read about it here: http://www.netadmintools.com/art295.html

So I tested my system and I got this:

cat /proc/sys/fs/file-nr
1088    0   331287

What does this mean?

The second column actually stays at 0 even after I shutdown my server, it even stays at 0 even right after a boot!

like image 454
erotsppa Avatar asked Oct 21 '10 19:10

erotsppa


People also ask

How does Linux file descriptor work?

A file descriptor is a number that uniquely identifies an open file in a computer's operating system. It describes a data resource, and how that resource may be accessed. When a program asks to open a file — or another data resource, like a network socket — the kernel: Grants access.

Why is there a file descriptor limit?

A Too many open files error happens when a process needs to open more files than the operating system allows. This number is controlled by the maximum number of file descriptors the process has. If you experience such an issue, you can increase the operating system file descriptor limit.

How many file descriptors can a process have?

The number of file descriptors that can be allocated to a process is governed by a resource limit. The default value is set in the /etc/security/limits file and is typically set at 2000. The limit can be changed by the ulimit command or the setrlimit subroutine.


1 Answers

You want to look at /proc/sys/fs/file-max instead

From recent linux/Documentation/sysctl/fs.txt:

file-max & file-nr:

The kernel allocates file handles dynamically, but as yet it doesn't free them again.

The value in file-max denotes the maximum number of file- handles that the Linux kernel will allocate. When you get lots of error messages about running out of file handles, you might want to increase this limit.

Historically, the three values in file-nr denoted the number of allocated file handles, the number of allocated but unused file handles, and the maximum number of file handles. Linux 2.6 always reports 0 as the number of free file handles -- this is not an error, it just means that the number of allocated file handles exactly matches the number of used file handles.

Attempts to allocate more file descriptors than file-max are reported with printk, look for "VFS: file-max limit reached".

EDIT: the underlying error is probably not the system running out of global filedescriptors, but just your process. It seems likely that the problem is the maximum size limit of select.

like image 129
wnoise Avatar answered Sep 18 '22 21:09

wnoise