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 12
SUSE Linux Enterprise Desktop 12
Situation
From time to time it may be desirable to control a group of services, to improve control or system stability.
Resolution
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
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: 16-Mar-2020
- Modified Date:15-Aug-2022
-
- SUSE Linux Enterprise Server
- SUSE Linux Enterprise Server for SAP Applications
For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com