Linux – way to force a single process to swap most/all of its memory to disk (NON-ROOT)

linuxswap

We are currently analyzing performance of some of our boxes at work and we find that we have boxes that are swapping a lot and things start crawling when that starts to happen cause we are using spinny disks.

I had a theory that it might actually be faster to start up brand a process and do all the initialization we would normally have to do for that than to wait for the process to have its memory loaded off of disk.

To test this theory out I want to force a process to swap to disk and I want to see how long it takes to respond after it has been swapped out and compare that to a new process start up, is there a way of forcing a process to swap without modifying swappiness settings or running the box out of memory?

I don't have root on these boxes so basically I need an unprivelaged way of doing/hint to the kernel to do this.

Best Answer

Collect response time data of your actual applications, whatever you do. Log user response time, process start times, and whatever other performance metric is important to you.

On Linux, cgroups can have a memory limit beyond which processes in that group page out. A systemd service can set such a limit with the MemoryLimit directive, see the man page or RHEL's resource management guide. Remember that systemd units can be per user, root privilege not required.

Do not spend a lot of time trying to mock up a low memory condition, it is unlikely to perform like production's workload. If you can change the application to lazy starting or loading processes, do that in test then production. And measure the results.