Skip to content
Search

Ulimit

lastmod 2024-05-27created 2016-06-083 edits

Limits system resource usage for processes

Used because, when running a web service such as Apache with many concurrent users, the number of running Apache processes and the number of files those processes handle also increase, so the system needs a way to adjust the corresponding settings

There are two kinds of process resource limits: soft and hard

The ulimit command affects the performance and functions of the kernel, so use it with care

The configuration method differs between sysvinit environments and systemd environments

Limits

  • soft - the limit applied by default when a new program is created
  • hard - the maximum to which the soft limit can be raised

Setting list

  • nofile
    • Maximum number of files the domain (user, group) can open
    • Limits the maximum number of file descriptors (FD) that can be opened
  • nproc
    • Maximum number of processes for the domain (user, group)
    • Limits the maximum number of processes (user processes) allowed for one user
  • core
    • Limits the core file size
    • Limits the maximum size when a core file is created
  • data
    • Maximum data size
    • Limits the maximum size of the process data segment
  • fsize
    • Maximum file size
    • Limits the maximum size of files that can be created by the shell
  • memlock
    • Maximum locked-in-memory address space
    • Limits the maximum amount of virtual memory allowed for the shell
  • rss
    • Maximum resident memory size
    • Limits the maximum size that can be resident in memory (resident set size)
  • stack
    • Maximum stack size
    • Limits the maximum stack size
  • cpu
    • Maximum CPU time
    • Limits the maximum allowed CPU time per second
  • as
    • Address space limit
    • Sets the pipe size in 512-byte blocks
  • maxlogins
    • Maximum number of logins for this user
  • maxsyslogins
    • Maximum number of logins on the system
  • priority
    • Priority at which user processes run
  • locks
    • Maximum number of file locks the user can hold
  • sigpending
    • Maximum number of pending signals
  • msgqueue
    • Maximum memory used by POSIX message queues
  • nice
    • Maximum nice priority that can be raised to [-20 ~ 19]
  • rtprio
    • Maximum real-time priority
  • chroot
    • Change root to directory (Debian-specific)

Options

  • -a - Print all limit values
  • -b - Limit the maximum socket buffer size
  • -d - Limit the maximum size of a process's data segment
  • -e - Maximum scheduling priority
  • -f - Limit the maximum size of files created by the shell
  • -i - Limit the maximum number of pending signals
  • -l - Limit the maximum size that can be locked in memory
  • -s - Limit the maximum stack size
  • -t - Limit CPU usage time per second
  • -m - Limit the maximum size that can be resident in memory
  • -c - Limit the maximum size when a core file is created
  • -u - Limit the maximum number of processes available to a given user
  • -v - Limit the maximum size of virtual memory the shell can use
  • -p - Set the pipe size in 512-byte blocks
  • -q - Limit the maximum number of bytes in POSIX message queues
  • -r - Maximum real-time scheduling priority
  • -n - Limit the number of FDs that can be opened (errors such as too many open file can be solved by changing this value)
  • -x - Limit the maximum number of file locks
  • -S - Set the soft limit for the given resource
  • -H - Set the hard limit for the given resource
  • -T - Limit the maximum number of threads

Checking values

  • core file size - maximum size of a core file (-c option)
  • data seg size - maximum size of a process's data segment (-d option)
  • scheduling priority - maximum size of files created by the shell (-e option)
  • file size - maximum file size (-f option)
  • pending signals - pending signal limit (-i option)
  • max locked memory - maximum size that can be locked in memory (-l option)
  • max memory size - maximum resident set size (maximum memory size, -m option)
  • open files - maximum number of open file descriptors per process (maximum number of files that can be opened, -n option)
  • pipe size - pipe size in 512-byte blocks (-p option)
  • POSIX message queues - maximum number of bytes in POSIX message queues (-q option)
  • real-time priority - maximum real-time scheduling priority (-r option)
  • stack size - maximum stack size (-s option)
  • cpu time - total accumulated CPU time [seconds] (-t option)
  • max user processes - maximum number of processes available to a single user (-u option)
  • virtual memory - maximum amount of virtual memory available to the shell (-v option)
  • file locks - maximum number of file locks (-x option)

Configuration

Edit the /etc/security/limit.conf file:

<Domain> <Type> <Item> <Value>
  • Domain : the target to limit (*, user name, group name) - prefix with @ to apply to a group
  • Type : whether to limit strictly or with some leeway (Soft, Hard)
  • Item : the item to limit; there are many, such as core, data, seg, file size (stack, nproc, nofile, etc.)
  • Value : the value to set as the limit

ulimit settings in systemd

systemd completely ignores /etc/security/limits*. Therefore, limits in systemd must be configured differently from the traditional method.

Order of precedence:

  1. Service Daemon
  2. Global

File paths:

  • System - /etc/systemd/system.conf
  • User - /etc/systemd/user.conf

Options

Directive

ulimit equivalent

Unit

LimitCPU=

ulimit -t

Seconds

LimitFSIZE=

ulimit -f

Bytes

LimitDATA=

ulimit -d

Bytes

LimitSTACK=

ulimit -s

Bytes

LimitCORE=

ulimit -c

Bytes

LimitRSS=

ulimit -m

Bytes

LimitNOFILE=

ulimit -n

Number of File Descriptors

LimitAS=

ulimit -v

Bytes

LimitNPROC=

ulimit -u

Number of Processes

LimitMEMLOCK=

ulimit -l

Bytes

LimitLOCKS=

ulimit -x

Number of Locks

LimitSIGPENDING=

ulimit -i

Number of Queued Signals

LimitMSGQUEUE=

ulimit -q

Bytes

LimitNICE=

ulimit -e

Nice Level

LimitRTPRIO=

ulimit -r

Realtime Priority

LimitRTTIME=

No equivalent

Microseconds

See also

Favorite site

References


  1. Core_dump_setting_-_Open_Source_Technology_Blog.pdf ↩

author Zer0 sitemap