How to Configure Maximum number of open files per process – in Solaris 10 and Solaris 11

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.

Types of limits

The 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.

The 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.

Note: There is no limit for the number of open files per Solaris system. The number of files which can be opened on Solaris 10 and above is only limited by the amount of available memory.

Method 1: Parameter rlim_fd_cur in /etc/system (no longer recommended beginning with Solaris 10)

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.

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. The projmod or projadd command can be used to set the hard and/or soft limit for all processes running in a project (in all examples of this document, PRJ is the name of the project, 13179 is the number of the process used, and sleep 1200 is the process). However, projmod and projadd cannot change /etc/project information which is supplied by a network name service (e.g. LDAP).

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

Because of bug 15611661 “SUNBT6911915-SOLARIS_11 Setting basic file descriptor limit changes the privileged level to unlimited” (fixed in Solaris 10 Update 10), it is necessary to also set the privilege level priv (the hard limit), as in the following example:

$ projmod -s -K “process.max-file-descriptor=(basic,2048,deny),\
(priv,65536,deny)” user.root

Beginning with Solaris 10 Update 10 (= Solaris 10 8/11) or Solaris 10 with kernel patch 144500-19 (SPARC) / 144501-19 (x86) or higher, setting the priv level for process.max-file-descriptor is not necessary when setting just the basic level (the soft limit). And because of bug 15709994 “SUNBT7037497-SOLARIS_11 su fails when trying to set resource control value already set”, you would have to install patch 146670-02 (SPARC) or 146671-02 (x86) in case you want to set both basic and priv levels. Bug 15709994 is also fixed in Solaris 11.

Method 3:The shell’s limit or ulimit builtin command

It is also possible to set the limit for the maximum number of open files per process using the shell’s limit or ulimit commands, up to the hard limit set in /etc/system or to the priv level for process.max-file-descriptor. The commands can be used in an interactive session, in a shell script, or in a shell initialization file (e.g. .kshrc).
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. The only exceptions are commands that create a new task: login, su, cron, and newtask. These command will run in a new task, which will also get a new project assigned, for which the resource controls for that project will be re-examined.

Setting the soft limit

The soft limit can be set regardless of the rlim_fd_cur setting in /etc/system or the basic level of resource control process.max-file-descriptor. For increasing the soft limit from the default 128 to 512 in csh, use the following command:

% limit descriptors 512

An attempt to increase the soft limit to a value higher than the hard limit in csh will result in the following error message:

limit: descriptors: Can’t set limit

For increasing the soft limit from the default 128 to 512 in ksh or sh, use the following command:

$ ulimit -Sn 512

An attempt to increase the soft limit to a value higher than the hard limit will result in one of the following error messages:

ulimit: bad ulimit
ksh: ulimit: exceeds allowable limit
ksh: ulimit: 4097: limit exceeded [Invalid argument]
Setting the hard limit

Setting the hard limit

For decreasing the hard limit from the default 65536 to 4096 in csh, use the following command:

$ limit -h descriptors 4096

An attempt of a user to set the hard limit to a higher value than set by the administrator or than previously set by the user will result in the following error message:

limit: descriptors: Can’t set hard limit

For decreasing the hard limit from the default 65536 to 4096 in ksh or sh, use the following command:

$ ulimit -Hn 4096

An attempt of a user to set the hard limit to a higher value than set by the administrator or than previously set by the user will result in one of the following error messages:

ulimit: bad ulimit
ksh: ulimit: exceeds allowable limit
ksh: ulimit: 4097: limit exceeded [Not owner]

Method 4:The 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:

$ plimit -n 2048,4096 13179

The plimit command with just the process id as the parameter shows the current limits for that process. See the “Checking the maximum number of open files per process” section of this document for an example.

Method 5:The setrctl or setrlimit system call

In a program, the setrctl or setrlimit  system calls can be used to configure the maximum number of open files for that program, up to the hard limit. The preferred way is to use the setrctl system call.

How to Check the Current 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

Ramdev

Ramdev

I have started unixadminschool.com ( aka gurkulindia.com) in 2009 as my own personal reference blog, and later sometime i have realized that my leanings might be helpful for other unixadmins if I manage my knowledge-base in more user friendly format. And the result is today's' unixadminschool.com. You can connect me at - https://www.linkedin.com/in/unixadminschool/

1 Response

  1. September 17, 2015

    […] Read – How to Configure Maximum number of open files per process […]

What is in your mind, about this post ? Leave a Reply

Close
  Our next learning article is ready, subscribe it in your email

What is your Learning Goal for Next Six Months ? Talk to us