Difference between revisions of "Resource Limits"

From Linux-VServer

Jump to: navigation, search
(Determining the Page Size)
 
(7 intermediate revisions by 6 users not shown)
Line 1: Line 1:
 +
'''NOTE: This page describes Linux <tt>rlimit</tt> support (an SVr4/BSD4.3/POSIX.1-2001 standard).  vServers can also be managed using the Linux Control Group (<tt>cgroup</tt>) system, for information on Control Group based resource management, see [[util-vserver:Cgroups|util-vserver - Cgroups]].'''
 +
 
Most properties related to system resources, might it be the memory consumption, the number of processes or file-handles, qualify for imposing limits on them.
 
Most properties related to system resources, might it be the memory consumption, the number of processes or file-handles, qualify for imposing limits on them.
  
Line 9: Line 11:
 
__FORCETOC__
 
__FORCETOC__
  
== List of resource limits ==
+
== List of Resource Limits ==
  
 
Below is a list of resource limits used for contexts and processes within. The tables contain the following information:
 
Below is a list of resource limits used for contexts and processes within. The tables contain the following information:
Line 21: Line 23:
 
; Description : Description of capability/flag effects
 
; Description : Description of capability/flag effects
  
=== Special resource limit codes ===
+
=== Special Resource Limit Codes ===
  
 
The tag column may contain one or more of the following tags:
 
The tag column may contain one or more of the following tags:
Line 34: Line 36:
 
| E
 
| E
 
| Limit will be enforced
 
| Limit will be enforced
|-
 
| N
 
| The limit cannot be set with vlimit using its name. Use its number instead.
 
 
|}
 
|}
  
Line 66: Line 65:
 
|
 
|
 
| KiB
 
| KiB
| Maximum filesize
+
| Maximum file size
 
|-
 
|-
 
| 2
 
| 2
Line 74: Line 73:
 
|
 
|
 
| KiB
 
| KiB
| max data size
+
| Maximum size of the data segment
 
|-
 
|-
 
| 3
 
| 3
Line 82: Line 81:
 
|
 
|
 
| KiB
 
| KiB
| max stack size
+
| Maximum stack size
 
|-
 
|-
 
| 4
 
| 4
Line 90: Line 89:
 
|
 
|
 
| KiB
 
| KiB
| max core file size
+
| Maximum core file size
 
|-
 
|-
 
| 5
 
| 5
Line 98: Line 97:
 
| AE
 
| AE
 
| page
 
| page
| max resident set size
+
| Maximum resident set size
 
|-
 
|-
 
| 6
 
| 6
Line 106: Line 105:
 
| AE
 
| AE
 
| 1
 
| 1
| max number of processes
+
| Maximum number of processes
 
|-
 
|-
 
| 7
 
| 7
Line 114: Line 113:
 
| AE
 
| AE
 
| 1
 
| 1
| max number of open files
+
| Maximum number of open files
 
|-
 
|-
 
| 8
 
| 8
Line 122: Line 121:
 
| AE
 
| AE
 
| page
 
| page
| max locked-in-memory address space
+
| Maximum locked-in-memory address space
 
|-
 
|-
 
| 9
 
| 9
Line 130: Line 129:
 
| AE
 
| AE
 
| page
 
| page
| address space limit
+
| Maximum address space size
 
|-
 
|-
 
| 10
 
| 10
Line 138: Line 137:
 
| AE
 
| AE
 
| 1
 
| 1
| maximum file locks held
+
| Maximum file locks held
 
|-
 
|-
 
| 11
 
| 11
Line 146: Line 145:
 
|
 
|
 
| 1
 
| 1
| max number of pending signals
+
| Maximum number of pending signals
 
|-
 
|-
 
| 12
 
| 12
Line 152: Line 151:
 
| MSGQ
 
| MSGQ
 
| -q
 
| -q
| AEN
+
| AE
 
| Byte
 
| Byte
| maximum bytes in POSIX mqueues
+
| Maximum bytes in POSIX mqueues
 
|-
 
|-
 
| 13
 
| 13
Line 162: Line 161:
 
|
 
|
 
| 1
 
| 1
| max nice prio allowed to raise to
+
| Maximum nice prio allowed to raise to
 
|-
 
|-
 
| 14
 
| 14
Line 170: Line 169:
 
|
 
|
 
| 1
 
| 1
| maximum realtime priority
+
| Maximum realtime priority
 
|}
 
|}
  
Line 188: Line 187:
 
| NSOCK
 
| NSOCK
 
| SOCK
 
| SOCK
| AEN
+
| AE
 
| 1
 
| 1
| max number of open sockets
+
| Maximum number of open sockets
 
|-
 
|-
 
| 17
 
| 17
 
| OPENFD
 
| OPENFD
 
| OFD
 
| OFD
| AEN
+
| AE
 
| 1
 
| 1
| max number of open filedescriptors
+
| Maximum number of open file descriptors
 
|-
 
|-
 
| 18
 
| 18
 
| ANON
 
| ANON
 
| ANON
 
| ANON
| AEN
+
| A
 
| page
 
| page
| anonymous memory limit
+
| Maximum anonymous memory size
 
|-
 
|-
 
| 19
 
| 19
 
| SHMEM
 
| SHMEM
 
| SHM
 
| SHM
| AEN
+
| AE
 
| page
 
| page
| shared memory limit
+
| Maximum shared memory size
 
|-
 
|-
 
| 20
 
| 20
 
| SEMARY
 
| SEMARY
 
| SEMA
 
| SEMA
| AN
+
| A
 
| 1
 
| 1
| max number of semaphore arrays
+
| Maximum number of semaphore arrays
 
|-
 
|-
 
| 21
 
| 21
 
| NSEMS
 
| NSEMS
 
| SEMS
 
| SEMS
| AN
+
| A
 
| 1
 
| 1
| max number of semaphores
+
| Maximum number of semaphores
 
|-
 
|-
 
| 22
 
| 22
 
| DENTRY
 
| DENTRY
 
| DENT
 
| DENT
| AEN
+
| AE
 
| 1
 
| 1
| max number of dentry structs
+
| Maximum number of dentry structs
 
|}
 
|}
  
== Determinig the Page Size ==
+
== Determining the Page Size ==
  
 
You can use the following program to determine the page size for your architecture (if it supports the getpagesize() function)
 
You can use the following program to determine the page size for your architecture (if it supports the getpagesize() function)
Line 269: Line 268:
 
4096
 
4096
 
</pre>
 
</pre>
 +
 +
Most Linux operating systems also just support a simple native command
 +
 +
<pre>
 +
getconf PAGESIZE
 +
</pre>
 +
 +
Here are some typical page sizes ...
 +
 +
{| class="wikitable_list"
 +
! arch
 +
! pagesize
 +
|-
 +
| arm, extensa, s390, sh64, x86, x86_64, v850
 +
| 4k
 +
|-
 +
| alpha, cris
 +
| 8k
 +
|-
 +
| m68k, sparc
 +
| 4k, 8k
 +
|-
 +
| powerpc
 +
| 4k, 64k
 +
|-
 +
| parisc
 +
| 4k, 16k, 64k
 +
|-
 +
| ia64, mips
 +
| 4k, 8k, 16k, 64k
 +
|}
  
 
== Configure Resource Limits in util-vserver ==
 
== Configure Resource Limits in util-vserver ==
Line 288: Line 318:
 
10000
 
10000
 
</pre>
 
</pre>
 +
 +
[[Category:Documentation]]

Latest revision as of 15:06, 16 April 2013

NOTE: This page describes Linux rlimit support (an SVr4/BSD4.3/POSIX.1-2001 standard). vServers can also be managed using the Linux Control Group (cgroup) system, for information on Control Group based resource management, see util-vserver - Cgroups.

Most properties related to system resources, might it be the memory consumption, the number of processes or file-handles, qualify for imposing limits on them.

The Linux kernel provides the getrlimit and setrlimit system calls to get and set resource limits per process. Each resource has an associated soft and hard limit. The soft limit is the value that the kernel enforces for the corresponding resource. The hard limit acts as a ceiling for the soft limit: an unprivileged process may only set its soft limit to a value in the range from 0 up to the hard limit, and (irreversibly) lower its hard limit. A privileged process (one with the CAP_SYS_RESOURCE capability) may make arbitrary changes to either limit value.

The Linux-VServer kernel extends this system to provide resource limits for whole contexts, not just single processes. Additionally a few new limit types missing in the vanilla kernel were introduced.

Additionally the context limit system keeps track of observed maxima and resource limit hits, to provide some feedback for the administrator. See Context Accounting for details.


Contents

[edit] List of Resource Limits

Below is a list of resource limits used for contexts and processes within. The tables contain the following information:

ID 
Resource limit ID
Name 
Human readable identifier used in userspace utilities
procfs 
Name used in /proc/virtual/*/limit
ulimit 
command line switch for the ulimit utility
Unit 
Aprropriate unit for the limit
Tag 
Special resource limit code to denote if resources are accounted, enforced (see below)
Description 
Description of capability/flag effects

[edit] Special Resource Limit Codes

The tag column may contain one or more of the following tags:

Tag Description
A Limit will be accounted
E Limit will be enforced

[edit] Linux Resource Limits

Below is a list of resource limits available in vanilla Linux (>=2.6.18).

ID Name procfs ulimit Tag Unit Description
0 CPU -- -t ms CPU time in ms
1 FSIZE -- -f KiB Maximum file size
2 DATA -- -d KiB Maximum size of the data segment
3 STACK -- -s KiB Maximum stack size
4 CORE -- -c KiB Maximum core file size
5 RSS RSS -m AE page Maximum resident set size
6 NPROC PROC -u AE 1 Maximum number of processes
7 NOFILE FILES -n AE 1 Maximum number of open files
8 MEMLOCK VML -l AE page Maximum locked-in-memory address space
9 AS VM -v AE page Maximum address space size
10 LOCKS LOCKS -x AE 1 Maximum file locks held
11 SIGPENDING -- -i 1 Maximum number of pending signals
12 MSGQUEUE MSGQ -q AE Byte Maximum bytes in POSIX mqueues
13 NICE -- 1 Maximum nice prio allowed to raise to
14 RTPRIO -- -r 1 Maximum realtime priority

[edit] Linux-VServer Resource Limits

Below is a list of additional resource limits available in the Linux-VServer kernel.

ID Name procfs Tag Unit Description
16 NSOCK SOCK AE 1 Maximum number of open sockets
17 OPENFD OFD AE 1 Maximum number of open file descriptors
18 ANON ANON A page Maximum anonymous memory size
19 SHMEM SHM AE page Maximum shared memory size
20 SEMARY SEMA A 1 Maximum number of semaphore arrays
21 NSEMS SEMS A 1 Maximum number of semaphores
22 DENTRY DENT AE 1 Maximum number of dentry structs

[edit] Determining the Page Size

You can use the following program to determine the page size for your architecture (if it supports the getpagesize() function)

#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
        int page_size = getpagesize();
        printf("The page size is %d\n", page_size);
        exit(0);
}

Here's how to compile and run it (assuming you save it as pagesize.c):

# gcc pagesize.c -o pagesize
# ./pagesize 
The page size is 4096

Note: Whether getpagesize() is present as a Linux system call depends on the architecture. If it is, it returns the kernel symbol PAGE_SIZE, which is architecture and machine model dependent. Generally, one uses binaries that are architecture but not machine model dependent, in order to have a single binary distribution per architecture. This means that a user program should not find PAGE_SIZE at compile time from a header file, but use an actual system call, at least for those architectures (like sun4) where this dependency exists. Here libc4, libc5, glibc 2.0 fail because their getpagesize() returns a statically derived value, and does not use a system call. Things are OK in glibc 2.1.

If you prefer, you can get the pagesize using python, just start a python console and write:

>>> import resource
>>> resource.getpagesize()
4096

Most Linux operating systems also just support a simple native command

getconf PAGESIZE

Here are some typical page sizes ...

arch pagesize
arm, extensa, s390, sh64, x86, x86_64, v850 4k
alpha, cris 8k
m68k, sparc 4k, 8k
powerpc 4k, 64k
parisc 4k, 16k, 64k
ia64, mips 4k, 8k, 16k, 64k

[edit] Configure Resource Limits in util-vserver

For example, if the adress space size (AS) and the resident set size (RSS) should be limited, the appropriate config files should be the following. You might have to create parent directories first.

# ls -al /etc/vservers/myguest/rlimits
total 28
drwxr-xr-x  2 root root 4096 2005-08-24 12:37 .
drwxr-xr-x  5 root root 4096 2005-08-24 00:22 ..
-rw-r--r--  1 root root    6 2005-08-24 12:43 as
-rw-r--r--  1 root root    6 2005-08-24 12:37 rss

# cat /etc/vservers/myguest/rlimits/as
90000

# cat /etc/vservers/myguest/rlimits/rss
10000
Personal tools