1 nr_open
This denotes the maximum number of file-handles a process can allocate.
Default value is 1024*1024 (1048576) which should be
enough for most machines.
Actual limit depends on RLIMIT_NOFILE
resource limit.
- 单个进程打开文件句柄数上限
2 file-max & file-nr
file-max:
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 kernel was able to allocate file handles
dynamically, but not to free them again.
file-nr:
The three values in file-nr denote 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”.
- file-max中指定了系统范围内所有进程可打开的文件句柄的数量限制(系统级别, kernel-level)。
file-max一般为内存大小(KB)的10%来计算,如果使用shell,可以这样计算:
grep MemTotal /proc/meminfo | awk ‘{printf(“%d”,$2/10)}’
410556 # 本人主机测算的数据
cat /proc/sys/fs/file-max
406262
我们不需要主动设置这个值,除非这个值确实较小。
(可能有各种其他原因导致file-max没有设置为内存的10%)- 注意:
If you increase /proc/sys/fs/file-max,
be sure to increase /proc/sys/fs/inode-max to 3-4
times the new value of /proc/sys/fs/file-max,
or you will run out of inodes.
即修改file-max,最好也要修改inode-max
inode-max 约等于 3或4 倍file-max。 3 ulimit
Provides control over the resources available to the shell and to processes started by it,
on systems that allow such control.- 提供对shell及其启动的进程的可用资源(包括文件句柄, 进程数量, core文件大小等)的控制。
- 这是进程级别的, 也就是说系统中某个session及其启动的每个进程能打开多少个文件描述符,
能fork出多少个子进程等… 。
ulimit -n 1024 这表示当前用户的每个进程最多允许同时打开1024个文件。 这1024个文件中还得除去每个进程必然打开的标准输入, 标准输出,标准错误,服务器监听 socket,进程间通讯的unix域socket等文件, 那么剩下的可用于客户端socket连接的文件数就只有大概1024-10=1014个左右。 也就是说缺省情况下,基于Linux的通讯程序最多 允许同时1014个TCP并发连接。
参考文献:
[1] https://www.kernel.org/doc/Documentation/sysctl/fs.txt
[2] http://blog.csdn.net/guowake/article/details/6615728 博主:guowake
[3] http://www.cnblogs.com/zengkefu/p/5635153.html 作者:zengkefu