Questo contenuto non è disponibile nella lingua selezionata.
Chapter 26. Configuring resource management by using cgroups-v2 and systemd
Beyond service supervision, systemd offers robust resource management capabilities. Use it to define policies and tune options to control hardware usage and system performance.
26.1. Prerequisites Copia collegamentoCollegamento copiato negli appunti!
- Basic knowledge of the Linux cgroup subsystem.
26.2. Introduction to resource distribution models Copia collegamentoCollegamento copiato negli appunti!
For resource management, systemd uses the control groups version 2 (cgroups-v2) interface.
By default, RHEL 8 uses cgroups-v1. Therefore, you must enable cgroups-v2 so that systemd can use the cgroups-v2 interface for resource management. For more information about how to enable cgroups-v2, see Mounting cgroups-v2.
To modify the distribution of system resources, you can apply one or more of the following resource distribution models:
- Weights
A resource is distributed by adding up the weights of all sub-groups and giving each sub-group a fraction of the resource based on its weight as compared to the overall sum of all weights.
For example, if you have 10
cgroups, each with Weight of value 100, the sum is 1000 and eachcgroupreceives one tenth of the resource.Weight is usually used to distribute stateless resources. To adjust the weight of a control group, use the CPUWeight= option.
- Limits
A
cgroupcan consume up to the configured amount of a resource, but you can also overcommit resources. Therefore, the sum of sub-group limits can exceed the limit of the parentcgroup.To adjust the limits of a control group, use the MemoryMax= option.
- Protections
You can set up a protected amount of a resource for a
cgroup. If the resource usage is below the protection boundary, the kernel will try not to penalize thiscgroupin favor of othercgroupsthat compete for the same resource. An overcommit is also possible.To adjust the protected resource amounts for a control group, use the MemoryLow= option.
- Allocations
- Exclusive allocations of a specific amount of a finite resource, such as the real-time budget. An overcommit is possible.
26.3. Allocating CPU resources by using systemd Copia collegamentoCollegamento copiato negli appunti!
Enable the CPU cgroup controller to manage CPU resources per service using systemd. This service-aware distribution allocates CPU resources among services. This prevents services with many processes from consuming all resources.
If a specific service requires more CPU resources, you can grant them by changing the CPU time allocation policy for the service.
Procedure
To set a CPU time allocation policy option when using systemd:
Check the assigned values of the CPU time allocation policy option in the service of your choice:
systemctl show --property <CPU time allocation policy option> <service name>
$ systemctl show --property <CPU time allocation policy option> <service name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Set the required value of the CPU time allocation policy option as a root:
systemctl set-property <service name> <CPU time allocation policy option>=<value>
# systemctl set-property <service name> <CPU time allocation policy option>=<value>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
The cgroup properties are applied immediately after they are set. Therefore, the service does not require a restart.
Verification
To verify whether you successfully changed the required value of the CPU time allocation policy option for your service, enter:
systemctl show --property <CPU time allocation policy option> <service name>
$ systemctl show --property <CPU time allocation policy option> <service name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
26.4. CPU time allocation policy options for systemd Copia collegamentoCollegamento copiato negli appunti!
Configure CPU time allocation policy options for systemd services to control CPU resource distribution and priority. The options are CPUWeight= and CPUQuota=.
CPUWeight=Assigns higher priority to a particular service over all other services. You can select a value from the interval 1 - 10,000. The default value is 100.
For example, to give
httpd.servicetwice as much CPU as to all other services, set the value toCPUWeight=200.Note that
CPUWeight=is applied only in cases when available CPU resources are depleted.CPUQuota=Assigns the absolute CPU time quota to a service. The value of this option specifies the maximum percentage of CPU time that a service will receive relative to the total CPU time available, for example
CPUQuota=30%.Note that
CPUQuota=represents the limit value for particular resource distribution models, such as Weights and Limits.For more information about
CPUQuota=, see thesystemd.resource-control(5)man page on your system.
26.5. Allocating memory resources by using systemd Copia collegamentoCollegamento copiato negli appunti!
You can distribute available memory for services by using the memory configuration options. The available configuration options are MemoryMin, MemoryLow, MemoryHigh, MemoryMax, and MemorySwapMax.
Procedure
Check the assigned values of the memory allocation configuration option in the service of your choice.
systemctl show --property <memory allocation configuration option> <service name>
$ systemctl show --property <memory allocation configuration option> <service name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Set the required value of the memory allocation configuration option as a
root.systemctl set-property <service name> <memory allocation configuration option>=<value>
# systemctl set-property <service name> <memory allocation configuration option>=<value>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
The cgroup properties are applied immediately after they are set. Therefore, the service does not require a restart.
Verification
To verify whether you have successfully changed the required value of the memory allocation configuration option for your service, enter:
systemctl show --property <memory allocation configuration option> <service name>
$ systemctl show --property <memory allocation configuration option> <service name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
26.6. Memory allocation configuration options for systemd Copia collegamentoCollegamento copiato negli appunti!
Systemd uses control groups (cgroups) to manage memory resources for processes and services. You can configure how memory is allocated and limited to ensure system stability and optimize performance. Systemd provides the following options to configure system memory allocation.
MemoryMin- Hard memory protection. If the memory usage is below the specified limit, the cgroup memory will not be reclaimed.
MemoryLow- Soft memory protection. If the memory usage is below the specified limit, the cgroup memory can be reclaimed only if no memory is reclaimed from unprotected cgroups.
MemoryHigh- Memory throttle limit. If the memory usage goes above the specified limit, the processes in the cgroup are throttled and put under a heavy reclaim pressure.
MemoryMax-
Absolute limit for the memory usage. You can use the kilo (K), mega (M), giga (G), tera (T) suffixes, for example
MemoryMax=1G. MemorySwapMax- Hard limit on the swap usage.
When you exhaust your memory limit, the Out-of-memory (OOM) killer will stop the running service. To prevent this, lower the OOMScoreAdjust= value to increase the memory tolerance.
26.7. Configuring I/O bandwidth by using systemd Copia collegamentoCollegamento copiato negli appunti!
To improve the performance of a specific service in RHEL 8, you can assign I/O bandwidth resources to that service by using systemd.
To do so, you can use the following I/O configuration options:
- IOWeight
- IODeviceWeight
- IOReadBandwidthMax
- IOWriteBandwidthMax
- IOReadIOPSMax
- IOWriteIOPSMax
Procedure
To set a I/O bandwidth configuration option by using systemd:
Check the assigned values of the I/O bandwidth configuration option in the service of your choice:
systemctl show --property <I/O bandwidth configuration option> <service name>
$ systemctl show --property <I/O bandwidth configuration option> <service name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Set the required value of the I/O bandwidth configuration option as a
root:systemctl set-property <service name> <I/O bandwidth configuration option>=<value>
# systemctl set-property <service name> <I/O bandwidth configuration option>=<value>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
When the cgroup properties are set, they are applied immediately. Therefore, restarting the service is not required.
Verification
To verify whether you successfully changed the required value of the I/O bandwidth configuration option for your service, enter:
systemctl show --property <I/O bandwidth configuration option> <service name>
$ systemctl show --property <I/O bandwidth configuration option> <service name>Copy to Clipboard Copied! Toggle word wrap Toggle overflow
26.8. I/O bandwidth configuration options for systemd Copia collegamentoCollegamento copiato negli appunti!
Systemd can control the I/O bandwidth for services to manage resource prioritization. This ensures that critical services have sufficient I/O access. Systemd provides the following configuration options to manage block layer I/O policies.
IOWeight- Sets the default I/O weight. The weight value is used as a basis for the calculation of how much of the real I/O bandwidth the service receives in relation to the other services.
IODeviceWeightSets the I/O weight for a specific block device.
NoteWeight-based options are supported only if the block device is using the CFQ I/O scheduler. No option is supported if the device uses the Multi-Queue Block I/O queuing mechanism.
For example, IODeviceWeight=/dev/disk/by-id/dm-name-rhel-root 200.
IOReadBandwidthMax,IOWriteBandwidthMaxSets the absolute bandwidth per device or a mount point.
For example,
IOWriteBandwith=/var/log 5M.Notesystemd handles the file-system-to-device translation automatically.
IOReadIOPSMax,IOWriteIOPSMax- Sets the absolute bandwidth in Input/Output Operations Per Second (IOPS).
26.9. Configuring CPUSET controller by using systemd Copia collegamentoCollegamento copiato negli appunti!
With the systemd resource management API, you can configure limits on a set of CPUs and NUMA nodes that a service can use. This limit restricts access to system resources used by the processes. The requested configuration is written in the cpuset.cpus and cpuset.mems files.
However, the requested configuration might not be used, as the parent cgroup limits either cpus or mems. To access the current configuration, the cpuset.cpus.effective and cpuset.mems.effective files are exported to the users.
Procedure
To set
AllowedCPUs:systemctl set-property <service name>.service AllowedCPUs=<value>
# systemctl set-property <service name>.service AllowedCPUs=<value>Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
systemctl set-property <service name>.service AllowedCPUs=0-5
# systemctl set-property <service name>.service AllowedCPUs=0-5Copy to Clipboard Copied! Toggle word wrap Toggle overflow To set
AllowedMemoryNodes:systemctl set-property <service name>.service AllowedMemoryNodes=<value>
# systemctl set-property <service name>.service AllowedMemoryNodes=<value>Copy to Clipboard Copied! Toggle word wrap Toggle overflow For example:
systemctl set-property <service name>.service AllowedMemoryNodes=0
# systemctl set-property <service name>.service AllowedMemoryNodes=0Copy to Clipboard Copied! Toggle word wrap Toggle overflow