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
- Maximum number of processes for the domain (user, group)
- Limits the maximum number of processes (user processes) allowed for one user
- Limits the core file size
- Limits the maximum size when a core file is created
- Maximum data size
- Limits the maximum size of the process data segment
- Maximum file size
- Limits the maximum size of files that can be created by the shell
- Maximum locked-in-memory address space
- Limits the maximum amount of virtual memory allowed for the shell
- Maximum resident memory size
- Limits the maximum size that can be resident in memory (resident set size)
- Maximum stack size
- Limits the maximum stack size
- Maximum CPU time
- Limits the maximum allowed CPU time per second
- Address space limit
- Sets the pipe size in 512-byte blocks
- Maximum number of logins for this user
- Maximum number of logins on the system
- Priority at which user processes run
- Maximum number of file locks the user can hold
- Maximum number of pending signals
- Maximum memory used by POSIX message queues
- Maximum nice priority that can be raised to [-20 ~ 19]
- Maximum real-time priority
- 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 : 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:
- Service Daemon
- Global
File paths:
- System -
/etc/systemd/system.conf - User -
/etc/systemd/user.conf
Options
| Directive | ulimit equivalent | Unit |
| | | Seconds |
| | | Bytes |
| | | Bytes |
| | | Bytes |
| | | Bytes |
| | | Bytes |
| | | Number of File Descriptors |
| | | Bytes |
| | | Number of Processes |
| | | Bytes |
| | | Number of Locks |
| | | Number of Queued Signals |
| | | Bytes |
| | | Nice Level |
| | | Realtime Priority |
| | | Microseconds |
See also
Favorite site
- [Recommended] Core dump settings 1
- Linux ulimit :: Las notepad
- (Linux) ulimit explanation and configuration
References
-
Core_dump_setting_-_Open_Source_Technology_Blog.pdf ↩