2

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.

mdpc
  • 11,698
  • 28
  • 51
  • 65
csteifel
  • 273
  • 1
  • 6
  • 11
  • this sounds odd. You could be configuring your applications to have limits that avoid them arriving at the out of memory/swapped out scenario. To kill off a swapped out process cleanly it needs to be restored which is a bit harder with a brand new process consuming more ram. – danblack Nov 03 '18 at 01:30
  • @danblack That does not sound likely. There shouldn't be any need for the kernel to read back pages from swap when you have killed the process. It just need to clean up a few data structures and mark those pages of swap free, which all amounts to a few updates in kernel memory. – kasperd Nov 05 '18 at 13:06

2 Answers2

1

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.

John Mahowald
  • 30,009
  • 1
  • 17
  • 32
0

Assumming this is Linux, you might want to set the swappiness variable to its MAX value. This basically tells the memory management to swap out everything possible that is not currently in use. This value guides how much (and how often) your Linux kernel will copy RAM contents to swap

To permanently set:

 1.  Edit `/etc/sysconfig.conf`

 2.  add the following line to the file
      `vm.swappiness=100`

 3.  Reboot

Or to temporarily set till the next reboot:

 1. Enter the command
    `sudo sysctl vm.swappiness=100`

This will allow you to test your assumptions on your mix of jobs.

viv
  • 103
  • 3
mdpc
  • 11,698
  • 28
  • 51
  • 65
  • This is linux but I already said that I don't have root so this wont work – csteifel Nov 03 '18 at 00:39
  • Hmmm...the assumption is that posters in this group are administrators w/ `root` access. – mdpc Nov 13 '18 at 21:57
  • Tried `sysctl vm.swappiness=100; cat file > /dev/null`, but does not help. File is still written to "available" RAM instead of the swap file. – mgutt Oct 13 '20 at 11:37