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

26.2. Introduction to resource distribution models

For resource management, systemd uses the control groups version 2 (cgroups-v2) interface.

Note

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 each cgroup receives 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 cgroup can 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 parent cgroup.

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 this cgroup in favor of other cgroups that 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

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:

  1. 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>
    Copy to Clipboard Toggle word wrap
  2. 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>
    Copy to Clipboard Toggle word wrap

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>
    Copy to Clipboard Toggle word wrap

26.4. CPU time allocation policy options for systemd

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.service twice as much CPU as to all other services, set the value to CPUWeight=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 the systemd.resource-control(5) man page on your system.

26.5. Allocating memory resources by using systemd

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

  1. 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>
    Copy to Clipboard Toggle word wrap
  2. Set the required value of the memory allocation configuration option as a root.

    # systemctl set-property <service name> <memory allocation configuration option>=<value>
    Copy to Clipboard Toggle word wrap
Note

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>
    Copy to Clipboard Toggle word wrap

26.6. Memory allocation configuration options for systemd

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.
Note

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

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:

  1. 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>
    Copy to Clipboard Toggle word wrap
  2. 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>
    Copy to Clipboard Toggle word wrap

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>
    Copy to Clipboard Toggle word wrap

26.8. I/O bandwidth configuration options for systemd

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.
IODeviceWeight

Sets the I/O weight for a specific block device.

Note

Weight-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, IOWriteBandwidthMax

Sets the absolute bandwidth per device or a mount point.

For example, IOWriteBandwith=/var/log 5M.

Note

systemd 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

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>
    Copy to Clipboard Toggle word wrap

    For example:

    # systemctl set-property <service name>.service AllowedCPUs=0-5
    Copy to Clipboard Toggle word wrap
  • To set AllowedMemoryNodes:

    # systemctl set-property <service name>.service AllowedMemoryNodes=<value>
    Copy to Clipboard Toggle word wrap

    For example:

    # systemctl set-property <service name>.service AllowedMemoryNodes=0
    Copy to Clipboard Toggle word wrap
Torna in cima
Red Hat logoGithubredditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi. Esplora i nostri ultimi aggiornamenti.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita il Blog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

Theme

© 2026 Red Hat