Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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:

memory.swappiness

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
 60
 # echo "59 " > memory.swappiness
 # cat memory.swappiness
 59
share|improve this answer
    
What about just for files inside /tmp mounted as tmpfs? unix.stackexchange.com/q/146490/56970 –  CMCDragonkai Jul 25 at 6:24

What you want is to pin à process in memory. Look for that, real time workloads do this.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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