Simply put, Max-file represents the number of file handles that can be opened at the system level, while the Ulimit-n controls the number of file handles that can be opened at the process level.
Man 5 proc, find the explanation of File-max:
FILE-MAX Specifies the number of file handles that can be opened by all processes in the system-wide (System level, kernel-level). (The value in File-max denotes the maximum number of file handles this Linux kernel would allocate). When received "Too many open F This value should have been added to the error message Iles in System.
# Cat/proc/sys/fs/file-max
185230
# echo 100000 >/proc/sys/fs/file-max
Or
# echo "fs.file-max=65535" >>/etc/sysctl.conf
# sysctl-p
The kernel constant Nr_open imposes an upper to on the value of May is limit in placed. What is the meaning of this sentence?
For 2.2 of the kernel, also need to consider Inode-max, the general Inode-max set to File-max 4 times times. For kernel 2.4 and beyond, this file is not Inode-max.
File-nr can view the number of file handles currently open in the system. He includes 3 numbers: The first represents the number of file descriptors that have been allocated, the second represents the number of idle file handles, and the third represents the maximum value that can open a file handle (consistent with File-max). The kernel will dynamically allocate file handles, but will not release them again (this may not adapt to the latest kernel, I see in my file-nr that the second column has been 0, and the first column has increased and reduced)
Man bash, find the section stating Ulimit:
Provides control over the resources available to the shell and its initiated processes, including file handles, number of processes, core file size, and so on. This is a process-level, that is, how many file descriptors can be opened by a session in the system and each process it starts, and how many fork the child processes ...
When the ceiling is reached, the error "Too many open files" or encounter Socket/file:can ' t open so many files, etc.
It is also important to note that each resource has its own soft and hard limits, and the soft limit is the limit that the kernel imposes on the resource, and the hard limit is the maximum value of the soft limit. The 0~ call process can only specify its soft limit as a value in the hard limit range, while reducing its hard limit irreversibly. The authorization process can arbitrarily change its soft and hard limits. The value of the rlim_infinity indicates no resource restrictions.
Use the-H and-s options to specify settings that require a hard limit/soft limit on the resource. If none is specified, both the hard limit and the soft limit are set.
The limit value of the print resource, if-H is not explicitly specified, and the print is-s
To change the ULIMIT of Apache, you can modify the value of Ulimit_max_files in the/usr/sbin/apachectl script.
The number of open file handles is set too large to be harmful:
If The file descriptors are TCP sockets, etc, then you risk using up a large amount of memory for the socket buffers and O ther kernel objects; This memory isn't going to be swappable.
Also remember is the socket connection is also a file.