Linux handle restrictions
Linux handle restrictions
Linux handles can be divided into 1 system level limit and 2 user level limit:
/Proc/sys/fs/nr_open>/proc/sys/fs/file-max> = ulimit-Hn> = ulimit-Sn
1 system-level limit: 1.1/proc/sys/fs/nr_open
The maximum number of file handles supported by the System File System. The default value is 1048576 (1 M). The maximum value is limited by the system memory. This is the maximum value for all restrictions.
1.2/proc/sys/fs/file-max
The maximum number of file handles supported by the system file system must be smaller than nr_open. view the command (the following three commands are equivalent ):
[root@vm-cdh4 ~]# sysctl -a | grep -i file-max --colorfs.file-max = 188436[root@vm-cdh4 ~]# cat /proc/sys/fs/file-max188436[root@vm-cdh4 ~]# sysctl -e fs.file-maxfs.file-max = 188436
Run the following command to view the number of opened file descriptors used by the current system:
[root@vm-cdh4 ~]# cat /proc/sys/fs/file-nr832 0 188436
File-max = 188436
1.3 change file-max
Temporary changes, disappears after restart:
[root@vm-cdh4 ~]# sysctl -w fs.file-max=102400
Permanent changes, In
/Etc/sysctl. conf(Applicable to kernels 2.2 and 2.4 ):
Fs. file-max = 102400 #### only for the 2.2 kernel: #### fs. inode-max = 102400
When
/Etc/sysctl. confAfter the change, run the following command to make the change take effect immediately:
[root@vm-cdh4 ~]# sysctl -p
2. user-level limit: 2.1 hard upper limit: ulimit-Hn
The maximum number of handles of a single process. <= file-max. view the command:
[root@vm-cdh4 ~]# ulimit -Hn4096
Temporary changes,
Disappears after restart:
[root@vm-cdh4 ~]# ulimit -Hn 8192[root@vm-cdh4 ~]# ulimit -Hn8192
2.2 Soft Upper Limit ulimit-Sn
The maximum number of handles for a single process. <= ulimit-Hn. view the command:
[root@vm-cdh4 ~]# ulimit -Sn1024[root@vm-cdh4 ~]# ulimit -n1024
Temporary changes,
Disappears after restart:
[root@vm-cdh4 ~]# ulimit -Sn 8000[root@vm-cdh4 ~]# ulimit -n8000
2.3 modify the maximum number of handles of a single process
Modify the soft and hardware limits temporarily (<= file-max)Disappears after restart:
[root@vm-cdh4 ~]# ulimit-SHn 10240
Permanently modify the hard and soft limits (RHEL6.4 )./Etc/security/limits. conf(* Indicates all users ):
#......#@student - maxlogins 4* hard nofile 10240* soft nofile 10240# End of file