Ask Your Question
0

resource management for systemd services

asked 2013-03-21 04:33:13 -0500

Andrewz gravatar image

updated 2014-07-18 13:41:04 -0500

mether gravatar image

Hello all

First of all, sorry for the long post, but it seems my karma is insufficient for publishing links or adding attachments. :(

I have a question about systemd and cgroups. I was able to successfully apply and use resource limits for various systemd services by using the control group options for systemd.exec, but I have trouble applying resource limitations to a group of systemd services.

I am using systemd-35 and libcgroup-0.37.1. Unfortunately this version of systemd is missing systemd-cgtop and does not provide a service for creating external cgroups (like cgconfig.service). The service can be created easily and does the job, but here is my dilemma:

I need to split the CPU time into two groups: one group for all system services would get a max of 2/3 of the CPU time, while the other group (for my HMI app for eg) would get the rest.

I've created the cgconfig.service and made sure it starts early in the boot process. Here is the service's contents:

[Unit]
Description=Create custom cgroups
DefaultDependencies=no
Conflicts=shutdown.target
Before=basic.target shutdown.target

[Service]
RemainAfterExit=yes
ExecStart=/sbin/cgconfigparser -l /etc/cgconfig.conf
ExecStop=/sbin/cgclear -l /etc/cgconfig.conf -e

[Install]
WantedBy=sysinit.target

My cgconfig file, looks like this:

group group1 {
        cpu {
                cpu.shares = 717;
        }
}
group group2 { 
        cpu {
                cpu.shares = 307;
        }
        memory {
                memory.limit_in_bytes = 512M;
                memory.oom_control  = 1;
        }
}
namespace {
        cpu = system;
        memory = system;
}

Next, I have added: ControlGroup=/system/groupX/<service_name>.service cpu,cpuacct:/system/groupX to the [Service] section of all group1 and group2 services accordingly.

Using these settings I was able to group the services in their appropriate groups inside the systemd controller and I can see the two groups with their limits created inside the cpu controller, but the limit does not seem to actually apply to the services started in that group. I would have expected that the services started in the systemd:/system/group1 control group, inherit the limits of their parent (/system/group). But this does not happen, instead in cpu:/system/ I have a cgroup for "group1" and also cgroups for each systemd service started. Needless to say that cpu.shares for the cpu:/system/group1 group and cpu:/system/connman.service (for example) do not match, even if the connman service is listed as a process in the systemd:/system/group1. Here is a log listing the connman related cgroup settings:

-bash-3.2# cat /lib/systemd/system/connmand.service | tail
[Service]
Type=dbus
BusName=net.connman
ExecStart=/usr/sbin/connmand -n

ControlGroup=/system/group1/connmand.service cpu,cpuacct:/system/group1

-bash-3.2# cat /sys/fs/cgroup/systemd/system/group1/connmand.service/cgroup.procs
70

-bash-3.2# cat /sys/fs/cgroup/cpu/system/group1/cgroup.procs
70
254
2342
2363
11906

-bash-3.2# cat /sys/fs/cgroup/cpu/system/group1/cpu.shares
717

-bash-3.2# cat /sys/fs/cgroup/cpu/system/connmand.service/cgroup.procs

-bash-3.2# cat /sys/fs/cgroup/cpu/system/connmand.service ...
(more)
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2014-07-17 16:16:53 -0500

zbyszek gravatar image

systemd-35 is rather old. In recent versions, you'd simply create a slice:

# /etc/systemd/system/group1.slice
[Unit]
CpuShares=717

and

# /etc/systemd/system/group2.slice
[Unit]
CpuShares=307
MemoryLimit=512M

and then place services in those slices by using

[Unit]
Slice=group2.slice

etc.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2013-03-21 04:33:13 -0500

Seen: 1,301 times

Last updated: Jul 17 '14