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?
-
Is this a virtual machine of some sort or a dedicated server? There's a few things that might work in the latter like [zram](http://en.wikipedia.org/wiki/ZRam). – Journeyman Geek Aug 08 '13 at 03:35
-
Dedicated. Will look into zram – Daniel S Aug 08 '13 at 05:30
-
I dunno, this seems a bit tacky, especially given the small RAM footprint involved. Tune swappiness for now. Since it's sounds like a hosted server, you may not have the flexibility of some other solutions... – ewwhite Aug 08 '13 at 06:59
-
1Can someone reopen this question? I'd like to add complete answer to it. Dealing with low memory and swap management kinda perfectly fits into system administration. – Michal Sokolowski Nov 30 '15 at 06:54
2 Answers
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.
![](../../users/profiles/182140.webp)
- 5,757
- 17
- 22
You are not smarter than the kernel's VM subsystem. Just let the processes be, and if they're really going unused, they'll get swapped out without you needing to do anything.
![](../../users/profiles/20815.webp)
- 108,414
- 18
- 172
- 242
-
3"Don't do a thing" is not an answer to "How do I do a thing" unless there's some thoroughly explained "why nots" or alternatives. See [_Answer the Question_ in "Answering"](http://stackoverflow.com/help/how-to-answer) – willscripted Oct 21 '15 at 11:20
-