1

I've been using the service unit bellow to start a couple of process that happens to have a high CPU and disk bandwidth usage when running.

Since the processes I want to limit don't have a way to indicate how much resources they should take, I've been using CGroups to control how much they should take of the available resources.

The problem is that if CGroups fails the systems becomes unresponsive and needs to be restarted, so I'd like to have a way to stop the processes in that case.

The service unit for CGroups should restart the service on failure, but for some reason it didn't, maybe because the system became unresponsive.

I don't have the logs either, because the system was shutdown due to high resources usage, and I don't have access to that information until an admin remove the suspension.

Service unit to be limited

[Unit]
Description=HIGH RESOURCES USAGE daemon                                
After=cgroups.service network.target

[Service]
User=myuser
Group=myuser

ExecStart=/usr/bin/xxxxxxxx
ExecStop=/usr/bin/killall -w -s 2 /usr/bin/xxxxxxxx
WorkingDirectory=/home/myuser

[Install]
WantedBy=multi-user.target

CGroups service unit

[Unit]
Description=Load cgroup configs
After=remote-fs.target

[Service]
Type=forking
ExecStartPre=/bin/echo "Processing /etc/cgconfig.conf..."
ExecStartPre=/usr/sbin/cgconfigparser -l /etc/cgconfig.conf
ExecStartPre=/bin/echo "Processing /etc/cgrules.conf..."
ExecStart=/usr/sbin/cgrulesengd --logfile=/var/log/cgrulesengd.log
Restart=on-failure
RestartSec=5

[Install]
WantedBy=multi-user.target

cgconfig.conf

group app_limit {
    cpu {
        cpu.cfs_quota_us = 200000
        cpu.cfs_period_us = 1000000
    }
    blkio {
        blkio.throttle.read_iops_device = "253:0 35";
        blkio.throttle.write_iops_device = "253:0 35";
        blkio.throttle.write_bps_device = "253:0 262144000";
    }
}

cgrules.conf

myuser  cpu,blkio   app_limit/
rraallvv
  • 123
  • 6

1 Answers1

2

It seems that you're trying to use old stuff to manage cgroups, when systemd already have everything embedded to do the job. cgconfig is deprecated, and must not be used where systemd is running.

You should have a look at https://www.freedesktop.org/software/systemd/man/systemd.resource-control.html

And also https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/resource_management_guide/sec-Modifying_Control_Groups#sec-Modifying_Unit_Files

To summarize, you should be able to do what you want just by adding the accurate ressource control keywords in your [Service] section, and removing your cgroup service unit.

Chaoxiang N
  • 1,283
  • 5
  • 11
  • I [tried](https://www.reddit.com/r/CentOS/comments/9sc7je/unknown_lvalue_ioreadiopsmaxiowriteiopsmax_in/) using `CPUQuota`, `MemoryLimit`, and both `IOReadIOPSMax` and `IOWriteIOPSMax`, but only `CPUQuota` and `MemoryLimit` works. With the two IOPS directives I get the error `Unknown lvalue 'IOReadIOPSMax/IOWriteIOPSMax' in section 'Service'` – rraallvv Nov 20 '18 at 19:16
  • I'm running kernel `4.15.0-38-generic` and systemd `229-4ubuntu21.8` – rraallvv Nov 20 '18 at 19:18
  • By the way, I'd prefer not having to recompile the kernel. Is there a kernel with `IOReadIOPSMax` and `IOWriteIOPSMax` enable for Ubuntu 16.04? – rraallvv Nov 20 '18 at 20:02