52

Can anyone explain in layman's terms what the difference between soft and hard limit is?

Should I set my soft and hard limit to be the same? Or should soft be significantly lower? Does the system benefit either way?

codeforester
  • 115
  • 1
  • 1
  • 5
kidcapital
  • 777
  • 2
  • 7
  • 10

3 Answers3

46

The hard limit is the ceiling for the soft limit. The soft limit is what is actually enforced for a session or process. This allows the administrator (or user) to set the hard limit to the maximum usage they wish to allow. Other users and processes can then use the soft limit to self-limit their resource usage to even lower levels if they so desire.

esengineer
  • 148
  • 7
Kamil Kisiel
  • 11,946
  • 7
  • 46
  • 68
  • 5
    Hard limits are enforced "here and now", i.e. process can never access a resource if it would cause violation of a hard limit. A process can exceed soft limit for a period of time. Soft limit can be raised by a non-root user up to the hard limit. – Paweł Brodacki May 01 '11 at 11:41
  • 2
    The behaviour upon exceeding the soft limit depends on which limit it is. The man page for setrlimit(2) describes the result: http://linux.die.net/man/2/setrlimit . – Kamil Kisiel May 03 '11 at 13:59
  • I stand corrected – Paweł Brodacki May 04 '11 at 11:51
  • You said "The soft limit is what is actually enforced for a session or process". Isn't it the HARD limit that is actually enforced? – Brian Jul 16 '13 at 19:12
  • The soft limit is what is enforced and the user can raise it to up to a maximum of the hard limit. – Kamil Kisiel Jul 16 '13 at 20:36
5

Users who violate a soft limit quota get an e-mail indicating that they have a few days' grace period before the penalties kick in. Users who cross the hard limit threshold get no such grace period. The penalty differs depending on the particular quota, but usually nearly every command will fail such that the user will want to come into compliance quickly.

sfried
  • 127
  • 7
4

User resource limits dictate the amount of resources that can be used for a particular session. The resources that can be controled are:

maximum size of core files
maximum size of a process's data segment
maximum size of files created
maximum size that may be locked into memory
maximum size of resident memory
maximum number of file descriptors open at one time
maximum size of the stack
maximum amount of cpu time used
maximum number of processes allowed
maximum size of virtual memory available

It is important to note that these settings are per-session. This means that they are only effective for the time that the user is logged in (and for any processes that they run during that period). They are not global settings. In other words, they are only active for the duration of the session and the settings are not cumulative. For example, if you set the maximum number of processes to 11, the user may only have 11 processes running per session. They are not limited to 11 total processes on the machine as they may initiate another session. Each of the settings are per process settings during the session, with the exception of the maximum number of processes.

There are two types of limits that can be set for each property listed above, a hard and soft limit.

A hard limit cannot be changed by the user once it is set. Hard limits can only be changed by root user. A soft limit, however, can be changed by the user but cannot exceed the hard limit i.e. It can have minimum 0 value and maximum value as equal to 'hard limit'.

for more info

Drt
  • 394
  • 2
  • 5
  • 18