Table of Contents

cpusets

Cpusets is a Linux kernel facility and a subset of cgroups-v1, that provides a mechanism to assign a set of CPUs and NUMA memory nodes (if NUMA is available) to a set of tasks. This means in effect, that the tasks are constrained to the assigned cpusets. For a detailed documentation of cpusets, please refer to the CPUSETS kernel doc.

Enable cpusets

The following kernel configuration Parameter are required to enable cpusets:

Sysfs interface

To handle the cpusets in userspace, the functionality is available in sysfs: “/sys/fs/cgroup/cpuset/”. Each cpuset is represented by a directory in the cgroup file system containing (on top of the standard cgroup files) the following files describing that cpuset:

In addition, the root cpuset only has the following file:

Realtime Example

The following bash commands show exemplary how cpusets can be used for realtime processes on a 4 CPU machine. To simplify the use of cpusets the Python tool cset can be used.

 $ mkdir /dev/cpuset/rt0
 $ echo 0 > /dev/cpuset/rt0/cpus
 $ echo 0 > /dev/cpuset/rt0/mems
 $ echo 1 > /dev/cpuset/rt0/cpu_exclusive
 $ echo $RT_PROC_PID > /dev/cpuset/rt0/tasks
 $ mkdir /dev/cpuset/system
 $ echo 1-3 > /dev/cpuset/system/cpus
 $ echo 0 > /dev/cpuset/system/mems
 $ echo 1 > /dev/cpuset/system/cpu_exclusive
 $ for pid in $(cat /dev/cpuset/tasks); do /bin/echo $pid > /dev/cpuset/system/tasks; done 

References