Solaris : How to set limit on the maximum number of open files per process
The maximum limit of open files per process can be limited by setting a hard limit and/or a soft limit. The hard limit can be set by the system administrator and be decreased by any user, whereas the soft limit can be set by any user, up to the hard limit. This document describes the various methods available in Solaris 10 and Solaris 11 for setting the limit for the maximum number of open files per process.
Types of limits
1. hard limit : The hard limit (/etc/system parameter rlim_fd_max or the privileged level of resource control process.max-file-descriptor) is the limit for the maximum number of open files per process which is set by the system administrator. It is meant to be the upper limit for all processes running on a system (when using rlim_fd_max) or in a project (when using the resource control). Any user can decrease the hard limit but not increase it.
2. soft limit : The soft limit (/etc/system parameter rlim_fd_cur or the basic level of resource control process.max-file-descriptor) can be set by any user, up to the hard limit.
Setting the limit
1. method 1 (deprecated) : Parameter rlim_fd_cur in /etc/system
Parameter rlim_fd_cur can be set to a value up to the value of rlim_fd_max (for which the default is 65536, which can also be set to a different value in /etc/system). This method of setting the file descriptor limit is no longer recommended in Solaris 10 and Solaris 11. In general, it is recommended to use resource controls in favor of /etc/system parameters where available.
Parameter rlim_fd_cur can be set to a value up to the value of rlim_fd_max (for which the default is 65536, which can also be set to a different value in /etc/system). This method of setting the file descriptor limit is no longer recommended in Solaris 10 and Solaris 11. In general, it is recommended to use resource controls in favor of /etc/system parameters where available.
2. method 2 : Resource control process.max-file-descriptor
By using the resource control process.max-file-descriptor instead of /etc/system parameter rlim_fd_max, the system administrator can change the value for the maximum number of open files per process while the system remains running, without having to reboot the server. The other advantage is that processes of other projects are not affected.
By using the resource control process.max-file-descriptor instead of /etc/system parameter rlim_fd_max, the system administrator can change the value for the maximum number of open files per process while the system remains running, without having to reboot the server. The other advantage is that processes of other projects are not affected.
For changing the hard limit for project PRJ from the default 65536 to 4096, use the following command:
# projmod -s -K "process.max-file-descriptor=(priv,4096,deny)" PRJ
For changing the soft limit for project PRJ from the default 256 to 1024, use the following command:
# projmod -s -K "process.max-file-descriptor=(basic,1024,deny) PRJ
3. method 3 : limit/ulimit commands
It is also possible to set the limit for the maximum number of open files per process using the limit or ulimit commands, up to the hard limit set in /etc/system or to the priv level for process.max-file-descriptor. The limit is set for the shell and all commands executed in that shell, even if a project with resource control process.max-file-descriptor is defined for that user.
It is also possible to set the limit for the maximum number of open files per process using the limit or ulimit commands, up to the hard limit set in /etc/system or to the priv level for process.max-file-descriptor. The limit is set for the shell and all commands executed in that shell, even if a project with resource control process.max-file-descriptor is defined for that user.
a. setting soft limit
For increasing the soft limit from the default 128 to 512 in csh , use the following command:
For increasing the soft limit from the default 128 to 512 in csh , use the following command:
# limit descriptors 512
For increasing the soft limit from the default 128 to 512 in ksh or sh, use the following command:
# ulimit -Sn 512
b. setting hard limit
For decreasing the hard limit from the default 65536 to 4096 in csh, use the following command:
For decreasing the hard limit from the default 65536 to 4096 in csh, use the following command:
# limit -h descriptors 4096
For decreasing the hard limit from the default 65536 to 4096 in ksh or sh, use the following command:
# ulimit -Hn 4096
4. method 4 : plimit command
The plimit command can be used to set the limit for the maximum number of open files of an already running process. For example, the following command will set the soft limit to 2048 and the hard limit to 4096 for process 13179:
The plimit command can be used to set the limit for the maximum number of open files of an already running process. For example, the following command will set the soft limit to 2048 and the hard limit to 4096 for process 13179:
# plimit -n 2048,4096 13179
Verify the limit
The following commands can be used to check the value for the limit of the maximum number of open files of a running process (Again, in all examples, 13179 is used for the process id):
The prctl command:
# prctl -n process.max-file-descriptor 13179 process: 13179: sleep 1200 NAME PRIVILEGE VALUE FLAG ACTION RECIPIENT process.max-file-descriptor basic 256 - deny 13179 privileged 65.5K - deny - system 2.15G max deny -
The plimit command:
# plimit 13179 13179: sleep 1200 resource current maximum time(seconds) unlimited unlimited file(blocks) unlimited unlimited data(kbytes) unlimited unlimited stack(kbytes) 10240 unlimited coredump(blocks) unlimited unlimited nofiles(descriptors) 256 65536 vmemory(kbytes) unlimited unlimited
The pfiles command:
# pfiles 13179 13179: sleep 1200 Current rlimit: 256 file descriptors 0: S_IFCHR mode:0620 dev:542,0 ino:500877638 uid:60004 gid:7 rdev:133,1 O_RDWR /dev/pts/1 offset:38001 1: S_IFCHR mode:0620 dev:542,0 ino:500877638 uid:60004 gid:7 rdev:133,1 O_RDWR /dev/pts/1 offset:38001 2: S_IFCHR mode:0620 dev:542,0 ino:500877638 uid:60004 gid:7 rdev:133,1 O_RDWR /dev/pts/1 offset:38001
No comments:
Post a Comment