1

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?

| improve this question | | | | |
  • 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. – Journeyman Geek Aug 8 '13 at 3:35
  • Dedicated. Will look into zram – Daniel S Aug 8 '13 at 5: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 8 '13 at 6:59
  • Can 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 6:54
4

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.

| improve this answer | | | | |
0

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.

| improve this answer | | | | |

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