I would like to turn off swapping for only one process. Swap should work as usual for the other processes.

How I can implement this with cgroups?

1 Answer 1


From the kernel documentation concerning memory.swappiness:

5.3 swappiness

Similar to /proc/sys/vm/swappiness, but affecting a hierarchy of groups only.

Following cgroups' swappiness can't be changed.
- root cgroup (uses /proc/sys/vm/swappiness).
- a cgroup which uses hierarchy and it has other cgroup(s) below it.
- a cgroup which uses hierarchy and not the root of hierarchy.

From Red Hat Customer Portal:


sets the tendency of the kernel to swap out process memory used by tasks in this cgroup instead of reclaiming pages from the page cache. This is the same tendency, calculated the same way, as set in /proc/sys/vm/swappiness for the system as a whole. The default value is 60. Values lower than 60 decrease the kernel's tendency to swap out process memory, values greater than 60 increase the kernel's tendency to swap out process memory, and values greater than 100 permit the kernel to swap out pages that are part of the address space of the processes in this cgroup.

Note that a value of 0 does not prevent process memory being swapped out; swap out might still happen when there is a shortage of system memory because the global virtual memory management logic does not read the cgroup value. To lock pages completely, use mlock() instead of cgroups.

:: You cannot change the swappiness of the following groups:
* the root cgroup, which uses the swappiness set in /proc/sys/vm/swappiness.
* a cgroup that has child groups below it.

EDIT: If you're interested in knowing exactly how to set it, you set it exactly like most other cgroup attributes:

 # cd /mnt/cgroup/<cgroupName>
 # cat memory.swappiness
 # echo "59 " > memory.swappiness
 # cat memory.swappiness

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.