mem_exclusive
Determines if userspace tasks in this cpuset can only get
their memory from the memory assigned to this cpuset.
tasks
Contains the process ids of all tasks running in this
cpuset.
notify_on_release
If this is set to 1, /sbin/cpuset_release_agent
will be called when the last process leaves this cpuset.
Note, that it is up to the administrator to create a script
or binary that matches the local needs.
memory_pressure
Provides the means to determine how often a cpuset is
running short of memory. Only calculated if memo-
ry_pressure_enabled is enabled in the top cpuset.
memory_spread_page and memory_spread_slab
Determines if le system buffers and I/O buffers are
uniformly spread across the cpuset.
In addition to these entries, the top cpuset also contains
the entry memory_pressure_enabled, which must be
set to 1 if you want to make use of the memory_pressure
entries in the different cpusets.
In order to make use of cpusets, you need detailed hardware
information for several reasons: on big machines, memory
that is local to a CPU will be much faster than memory that
is only available on a different node. If you want to create
cpusets from several nodes, you should try to combine CPUs
that are close together. Otherwise, task switches and
memory access may slow down your system noticeably.
To nd out which node a CPU belongs to, use the /sys
le system. The kernel provides information about available
CPUs to a specic node by creating links in /sys/
devices/system/node/nodeX/.
If several CPUs are to be combined to a cpuset, check the
distance of the CPUs from each other with the command
numactl --hardware. This command is available after
installing the package numactl.
The actual conguration and manipulation of cpusets is
done by modifying the le system below /dev/cpuset.
Tasks are performed in the following way:
Create a Cpuset
To create a cpuset with the name exampleset, just run
mkdir /dev/cpuset/exampleset to create the
respective directory. The newly created set will contain
several entries that reect the current status of the set.
Remove a Cpuset
To remove a cpuset, you only need to remove the cpuset
directory. For example, use rmdir
/dev/cpuset/exampleset to remove the previously
generated cpuset named exampleset. In contrast to
normal le systems, this works even if there are still entries in the directory.
Note that you will get an error like rmdir: example-
set: Device or resource busy, if there are still
tasks active in that set. To remove these tasks from the
set, just move them to another set.
Add CPUs to a Cpuset
To add CPUs to a set, you may either specify a comma
separated list of CPU numbers, or give a range of CPUs.
For example, to add CPUs with the numbers 2,3 and 7
to exampleset, you can use one of the following
commands: /bin/echo 2,3,7 >
/dev/cpuset/exampleset/cpus or /bin/echo
2-3,7 > /dev/cpuset/exampleset/cpus.
Add Memory to a Cpuset
You cannot move tasks to a cpuset without giving the
cpuset access to some system memory. To do so, echo
a node number into /dev/cpuset/exampleset/
mems. If possible, use a node that is close to the used
CPUs in this set.
Moving Tasks to Cpusets
A cpuset is just a useless structure, unless it handles some
tasks. To add a task to /dev/cpuset/exampleset/,
simply echo the task number into /dev/cpuset/
exampleset/. The following script moves all user space
processes to /dev/cpuset/exampleset/ and leaves
all kernel threads untouched:
cd /dev/cpuset/exampleset; \
for pid in $(cat ../tasks); do \
test -e /proc/$pid/exe && \
echo $pid > tasks; done
Note, that for a clean solution, you would have to stop
all processes, move them to the new cpuset, and let them
continue afterward. Otherwise, the process may nish
before the for loop nishes, or other processes may start
during moving.
This loop liberates all CPUs not contained in the exampleset from all processes. Check the result with the
command cat /dev/cpuset/tasks, which then
should not have any entries.
Of course, you can move all tasks from a special cpuset
to the top level set, if you intend to remove this special
cpuset.
Automatically Remove Unused Cpusets
In case a cpuset is not used any longer by any process,
you might want to clean up such unused cpusets automatically. To initialize the removal, you can use the no-
tify_on_release ag. If this is set to 1, the kernel
will run /sbin/cpuset_release_agent when the
last process exits. To remove an unused script, you may,
2