limit systemd services with control group ( slice )

This document (000019590) is provided subject to the disclaimer at the end of this document.

Environment

SUSE Linux Enterprise Server 15
SUSE Linux Enterprise Server 12 
SUSE Linux Enterprise Desktop 12

Situation

Systemd offers a simple solution to create resource limits for a service.
From time to time it may be desirable to control a group of services, to improve control or system stability.

Resolution

Systemd offers a unit type called "slice".
This is a control group, which may apply limits that affect all processes in this slice / control group.


In this example the docker service will be used to create a slice called docker.slice.
The values in this example are for illustration purposes only, and should not be not used in any production environment.
systemctl edit docker.slice

[Unit]
Description=Docker Slice
Before=slices.target

[Slice]
MemoryAccounting=true
MemoryLimit=2048M
CPUAccounting=true
CPUQuota=25%
TasksMax=4096


Edit the docker.service file:
systemctl edit --full docker.service

and add in the [Service] section:
Slice=docker.slice

After changing systemd config files a reload of the daemon is required:
systemctl daemon-reload

Prepare the docker service for start:
systemctl enable docker
systemctl start docker

To check, if the service is in the correct control group run:
systemd-cgls :

...
├─docker.slice
│ └─docker.service
│   ├─1298 /usr/bin/dockerd --add-runtime oci=/usr/sbin/docker-runc
│   └─1383 docker-containerd --config /var/run/docker/containerd/containerd.toml --log-level warn
...

A word of caution:
The limits of the slice take precedence over limits configured in the service file.

Even "systemctl show SERVICE" will still show values 
configured in the service file or in /etc/systemd/system.conf , though no longer being effective anymore.

Cause

There is a need or requirement to limit or more tightly control specific services behavior.

Disclaimer

This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.

  • Document ID:000019590
  • Creation Date: 10-Aug-2022
  • Modified Date:15-Aug-2022
    • SUSE Linux Enterprise Server
    • SUSE Linux Enterprise Server for SAP Applications

< Back to Support Search

For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com

SUSE Support Forums

Get your questions answered by experienced Sys Ops or interact with other SUSE community experts.

Join Our Community

Support Resources

Learn how to get the most from the technical support you receive with your SUSE Subscription, Premium Support, Academic Program, or Partner Program.


SUSE Customer Support Quick Reference Guide SUSE Technical Support Handbook Update Advisories
Support FAQ

Open an Incident

Open an incident with SUSE Technical Support, manage your subscriptions, download patches, or manage user access.

Go to Customer Center