3.7.7 Controlling Access to System Resources

You can use the systemctl command to control a cgroup's access to system resources, for example:

# systemctl set-property httpd.service CPUShares=512 MemoryLimit=1G

CPUShare controls access to CPU resources. As the default value is 1024, a value of 512 halves the access that the processes in the cgroup have to CPU time. Similarly, MemoryLimit controls the maximum amount of memory that the cgroup can use.


You do not need to specify the .service extension to the name of a service.

If you specify the --runtime option, the setting does not persist across system reboots.

# systemctl --runtime set-property httpd CPUShares=512 MemoryLimit=1G

Alternatively, you can change the resource settings for a service under the [Service] heading in the service's configuration file in /usr/lib/systemd/system. After editing the file, make systemd reload its configuration files and then restart the service:

# systemctl daemon-reload
# systemctl restart service

You can run general commands within scopes and use systemctl to control the access that these transient cgroups have to system resources. To run a command within in a scope, use the systemd-run command:

# systemd-run --scope --unit=group_name [--slice=slice_name] command

If you do not want to create the group under the default system slice, you can specify another slice or the name of a new slice.


If you do not specify the --scope option, the control group is a created as a service rather than as a scope.

For example, run a command named mymonitor in mymon.scope under myslice.slice:

# systemd-run --scope --unit=mymon --slice=myslice mymonitor
Running as unit mymon.scope.

You can then use systemctl to control the access that a scope has to system resources in the same way as for a service. However, unlike a service, you must specify the .scope extension, for example:

# systemctl --runtime set-property mymon.scope CPUShares=256

For more information see the systemctl(1), systemd-cgls(1), and systemd.resource-control(5) manual pages.