Tuesday, January 6, 2015

Linux -- Soft vs Hard Limits -- from Oracle's perspective

As known, we set the limits for our operating system user using limits.conf , ulimit command or similar techniques..
We set two type of limits.. I mean, Soft limits and hard limits.
When we look from the Oracle's perspective; we set these limits according to our Oracle Product's needs.

For example; Oracle documents says set files limits as follows;

oracle soft nofile 1024
oracle hard nofile 65536

The explanation of these setting is ;

A process that is owned by oracle user can open 1024 files at a time, but if the process that is owned by oracle user wants the increase this limit, it can increase this limit up to 65536.

Another example:

oracle soft nproc 2047
oracle hard nproc 16384

nproc is a little different..
oracle user can create 2047 processes at a time, but if oracle user want the increase this limit, it can increase this limit up to 16384.

Focus on the words : if oracle user want the increase this limit

So, we set the soft limit and hard limit right?  Then , both of them are used  ..
Lets consider the scenario; 
Suppose we login to the server using oracle Os user, 
Note that :Our soft open file limit is 20 and our hard open file limit is 20000 .

ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 94934
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 20    ---> our open file limit is set to soft open files limit initially (in our bash when we login)
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 16384
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

As seen above, the soft limit for our session is 20 and it is our current open files limit when we login to the server with oracle user..
lets start the database and trace the system calls;

getrlimit(RLIMIT_NOFILE, {rlim_cur=20, rlim_max=20000}) = 0
setrlimit(RLIMIT_NOFILE, {rlim_cur=20000, rlim_max=20000}) = 0

You see, the session is under control of the soft limit. 
During startup 
(
I mean 
sqlplus "/as sysdba "
SQL>startup
)
oracle binary first uses getrlimit system call to see the current and max limits.. Then uses setrlimit system call to set the max number of files limit to be equal to the hard limit value.

Oracle does this even if soft proc is 39000 and hard proc is 40000.. It basically sets the number of file limit as equal to the hard limit..

getrlimit(RLIMIT_NOFILE, {rlim_cur=39000, rlim_max=40000}) = 0
setrlimit(RLIMIT_NOFILE, {rlim_cur=40000, rlim_max=40000}) = 0

LOCAL=NO , background processes and beq connections also behaves the same.. they set the hard limit as their soft limit... 
 (note that with local=no , the listener process limits applies) .. So if you change the limits of your  shell, remember to restart your listener. ( or lets say restart every related thing :))

Then why do we have soft limits for open files or lets say soft limit at all?
I guess there are some oracle processes which cant modify their soft limits , I mean there may be some oracle processes which cant increase their open file limits up to hard limit.. So, that's why oracle recommends a soft limit such as 16384 for soft limit of open files. 
Or
Maybe there are some points in the code, that can not break.. The soft limits are there to guarantee these points to be executed without any problems..
Or
It may be related with the db_file init.ora parameter (or with maxdatafiles) .. I mean the required soft nofile limit specified in the Oracle documents is 1024, so it may be derived by these parameters + a bunch of library files mapped by the process
In addition to that, these limits are supplies security in a manner.

Anyways,  what we can say is that ; with the settings in Oracle docs; an Oracle process will have open files limit as 1024(at worst) , when it starts to its execution.
This seems to be sufficient in the first start.. But then an Oracle process sets its soft nofile limit to be the same as its hard nofile limit, to support more complicated/complex operations ,which may require more files to be opened in process level.

At the end of the day; Oracle recommends that...
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240

No comments :

Post a Comment

If you will ask a question, please don't comment here..

For your questions, please create an issue into my forum.

Forum Link: http://ermanarslan.blogspot.com.tr/p/forum.html

Register and create an issue in the related category.
I will support you from there.