Moving a process to and from swap [closed]

I've got several server-type processes on my linux server that use up 50MB of RAM. They are not constantly being used, and I'd like to be able to run more instances than my RAM capacity allows. I want to be able to remove a process from RAM and move it to the disk's swap. Does the linux kernel provide anything to fine tune swappiness per-process?


The Linux kernel provides via proc filesystem a property which defines how aggressively memory pages (anonymous only !) are swapped out to disk.

The vm.swappiness property is applied globally per system but not per process. Set this value low if you want to avoid swapping as much as possible. If your system process sleeps for a long time you may benefit with an aggressive swapping behavior by increasing this value.

You can change it temporarily from CLI (it will not survive system reboot)

echo 90 > /proc/sys/vm/swappiness

Or persistently with adding this line to /etc/sysctl.conf

vm.swappiness=90

And applying it with

sysctl -p

Or it should be possible to make it more granular with cgroups and memory subsystem if your system is running on recent Linux kernel (since 2.6.24 ?!?). Lets assume you have available a cgroup hieararchy with memory subsystem attached (/cgroups/mem) and a cgroup (/cgroups/mem/your_cgroup) with tasks/processes defined (/cgroups/mem/your_cgroup/tasks). Then, you can change swappiness behaviour for this group of tasks as follows:

cd /cgroups/mem/your_cgroup
echo 90 > memory.swappiness

For more details about memory subsystem, you can read e.g. RedHat Resource Guide.