Linux – Limits on the number of file descriptors

file-descriptorslinuxulimit

I'm trying to install 389-ds, And it gives me this warning:

WARNING: There are only 1024 file descriptors (hard limit) available, which limit the number of simultaneous connections.

I understand about file descriptors, but I don't understand about soft and hard limits.

When I run cat /proc/sys/fs/file-max, I get back 590432. This should imply that I can open up to 590432 files (i.e. have up to 590432 file descriptors.

But when I run ulimit, it gives me different results:

$ ulimit
unlimited

$ ulimit -Hn    # Hard limit
4096

$ ulimit -Sn    # Soft limit
1024

But what are the hard / soft limit from ulimit, and how do they relate to the number stored at /proc/sys/fs/file-max?

Best Answer

According to the kernel documentation, /proc/sys/fs/file-max is the maximum, total, global number of file descriptors the kernel will allocate before choking. This is the kernel's limit, not your current user's. So you can open 590432, provided you're alone on an idle system (single-user mode, no daemons running).

Note that the documentation is out of date: the file has been /proc/sys/fs/file-max for a long time. Thanks to Martin Jambon for pointing this out.

The difference between soft and hard limits is answered here, on SE. You can raise or lower a soft limit as an ordinary user, provided you don't overstep the hard limit. You can also lower a hard limit (but you can't raise it again for that process). As the superuser, you can raise and lower both hard and soft limits. The dual limit scheme is used to enforce system policies, but also allow ordinary users to set temporary limits for themselves and later change them.

Note that if you try to lower a hard limit below the soft limit (and you're not the superuser), you'll get EINVAL back (Invalid Argument).

So, in your particular case, ulimit (which is the same as ulimit -Sf) says you don't have a soft limit on the size of files written by the shell and its subprocesses. (that's probably a good idea in most cases)

Your other invocation, ulimit -Hn reports on the -n limit (maximum number of open file descriptors), not the -f limit, which is why the soft limit seems higher than the hard limit. If you enter ulimit -Hf you'll also get unlimited.

Related Question