In my quest for the most efficient server environment that I can create I have spent a good portion of my life drilling down to the lowest levels of the linux kernel. This helps to me better understand how to make use of and in some cases limit cpu and I/O usage to make the server perform well. One very important aspect of server performance is virtual memory.
Virtual memory is memory is that stored on a disk of some sort that acts as main system memory. So if your machine has 16 gigs of memory, and you have 16 gigs of swap space (virtual memory), then your server can operate as if it has 32 gigs of main system memory. Virtual memory/swap space has been used for decades as a way for machines to accomplish more than what they were originally built to handle, and for the most part its worked well. The problem is that it is SLOW. A traditional spindle/platter based disk has access times (Think flipping through a phone book to look up a name) that is anywhere from 700x to 2500x slower than normal system memory. Thats a problem if you have a server that uses swap a lot.
There is a lot more to the swap debate than what I mention above, and there are many articles written that could explain its benefits and detriments much better than I ever could. I am writing about swap today to outline some changes that I think would greatly benefit how swap works in a multiuser environment (Shared hosting).
Since swap capabilities have generally not changed in 25 years it would be nice if someone could take a 2nd look at the feature set and update with features to benefit todays users. Here are a few of my proposals.
1) Ability to swap based on a specific uid or gid (user id, or group id). On a shared user platform some users dominate the memory usage. While you can control memory usage for a certain user you can’t control the swappiness of certain users. It would be great for “greedy” memory users to still be able to use swap, but have those specific users also endure the speed penalties that increased memory usage requires. This would be GREAT to have!
2) Ability to swap by pid/tid (Process ID, and thread ID) – Some programs lend themselves to swapping while other don’t. If I could specify certain apps to swap more aggressively than others I could fine tune the system to work better. I know better than the kernel the performance I need from each application. Let me use that knowledge to tweak virtual memory usage by pid/tid.
3) Ability to NOT swap by pid/tid – Just as I stated above that I need to be able to increase the swappiness of certain applications, I also need the ability to exclude certain apps from swapping unless it is absolutely necessary. MySQL is a good example of this. I don’t want it swapping at all. Not even a little bit. I sure wish I could turn it off for this app!
4) Time based reporting for swap usage. Everyone knows that swap usage is slow, but HOW SLOW? What is the average time in milliseconds to swap out and swap in memory for the app you are using? How many milliseconds per page in the last 1,5,15,30 seconds etc. How overloaded or underloaded is the swap device? Are the seeks killing the swap device? Time to switch to an SSD for swap? How many pages are being swapped out or in for a specific app or uid.
5) Swap priorities for devices based on performance. You can specify multiple swap partitions/files if you like currently. However you have to set the priority for those devices when swap is activated. Swap out and swap in functions should be able to be set based on response time of swap devices. If a single swap device is getting crushed, but you have multiple devices why not use the other one to mitigate the slowness of the first swap device. This is NOT as simple as round robin type load balancing of swap devices. It needs to be intelligent and use devices based on response time in milliseconds. It should also be able to split pages for specific apps across multiple swap devices (If you desire) so that swap in is faster (Similar to raid 5 setup).
Swap algorithms are too simple for a time that is long gone in todays computing environment. Get rid of all the global settings, and give us some fine tuned options to make swap perform at the level we need it to be. If there are any coding Santa Clauses out there please put an updated virtual memory manager in my virtual stocking!
If you think I am wrong on these swap issues please send your replies to “email@example.com”
Matt Heaton / President Bluehost.com