Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the max opened files limitation on Linux?

Tags:

linux

ulimit

On Linux, when a process opens a file, the OS will check the max opened files limitation.

If the limitation was 1024, what's the number mean?

Does it represent

  • the number of files opened by the process
  • the number of files opened by the user who owns the process
  • the number of all the opened files in OS currently?
like image 598
kino lucky Avatar asked Jul 25 '14 12:07

kino lucky


People also ask

What is too many open files Linux?

The "Too many open files" message means that the operating system has reached the maximum "open files" limit and will not allow SecureTransport, or any other running applications to open any more files. The open file limit can be viewed with the ulimit command: The ulimit -aS command displays the current limit.

What is an open file limit?

The open-file limit is a setting that controls the maximum number of open files for individual users (such as non-root users). The default open-file limit is typically 1024.

How do you increase open files limit in Linux?

You can increase the maximum number of open files on the Linux host by setting a new value in the kernel variable file, /proc/sys/fs/file-max. This command forces the limit to 262144 files which is four times the default setting. (The default setting is appropriate for many environments.)


2 Answers

You can check the Soft limits and hard limits of your system by ulimit -a command.

  1. soft limits are simply the currently enforced limits.
  2. hard limits mark the maximum value which cannot be exceeded by setting a soft limit.

Soft limits could be set by any user while hard limits are changeable only by root. Limits are a property of a process. They are inherited when a child process is created so system-wide limits should be set during the system initialization in init scripts and user limits should be set during user login for example by using pam_limits.

There are often defaults set when the machine boots. So, even though you may reset your ulimit in an individual shell, you may find that it resets back to the previous value on reboot. You may want to grep your boot scripts for the existence ulimit commands if you want to change the default.

If the limitation was 1024, means you/process can open maximum 1024 files. if you exceed this limit means open, pipe and dup system calls will fail:

RLIMIT_NOFILE:

Specifies a value one greater than the maximum file descriptor number that can be opened by this process. Attempts (open(2), pipe(2), dup(2), etc.) to exceed this limit yield the error EMFILE.

like image 86
Sathish Avatar answered Oct 09 '22 00:10

Sathish


It is a number of open file descriptors per process. They can all refer to the same file, or different files.

You can see the current limits with ulimit -a in the shell, or programatically with getrlimit. The system-wide limits are set in /etc/security/limits.conf.

The filesystem object model on Linux is:

file descriptor -> file description -> dentry -> inode
  1. file descriptor is the integer number used by the application.
  2. file description is the kernel data structure to which one or more file descriptors refer to.
  3. dentry is the filename. One file can have many names (hard links).
  4. inode is the file contents.

dup creates a new file descriptor to the same file description. open creates a new file descriptor and a file description.

like image 33
Maxim Egorushkin Avatar answered Oct 09 '22 00:10

Maxim Egorushkin