How To Improve The Swap Performance On Your Linux Server

August 14, 2008 at 5:48 am (Software)

When you set up a brand new Linux server, do you create a single 128 MB swap partition? If so, did you know that you are severely limiting swap performance? Would you like to increase swap performance by several orders of magnitude, and to create swap partitions larger than 1 GB? It’s possible, requiring no kernel patches or special hardware, just pure geek know-how!

Some of you may not really care about swap. After all, Linux systems are typically very memory efficient, and swap is often barely touched. While often true on desktop systems, servers are another story. Because servers may handle unexpected stresses, such as runaway processes, denial of service attacks, or even the Slashdot effect, they need to have adequate high-speed swap so that they do not grind to a halt and possibly crash when all physical memory (and then some) is exhausted.

Still not convinced that this is a big deal? I’ll show you how easy it is to bring down a server by launching a massive amount of new processes. (Please, if you try this, do it only on a non-production server that you actually administer!) Let’s say you have two customized grep commands in /usr/bin, called bobgrep and jimgrep. Now, let’s assume that bobgrep is simply a shell script that calls the ELF executable jimgrep, as follows:

#!/bin/bash
jimgrep -r $*

Everything looks good so far, but what happens if jimgrep gets accidentally replaced with a symbolic link to bobgrep? Well, in that case, calling bobgrep or jimgrep will cause an infinite loop, causing hundreds of bash processes to be spawned in mere seconds. This actually happened to me once, and believe me, it hurt!

If a server doesn’t have adequate swap, a situation like this can cause the machine to lock up in much less than a minute. How do we fix the problem? One way is to increase the swap size beyond 128 MB. Fortunately for us, there is absolutely no 128 MB limit on swap under Linux 2.2.x+ and later kernels, as there was in the past. The current limits are approximately 2 GB on x86, PowerPC, and MC680×0 systems, 512 MB on MIPS systems, 128 GB on Alpha, and a whopping 3 Terabytes on UltraSparc platforms!

Swap partition size limits under modern Linux kernels

x86		    2 Gigabytes
PowerPC		    2 Gigabytes
Motorola 680x0	    2 Gigabytes
Sparc		    1 Gigabyte
MIPS		    512 Megabytes
Alpha		    128 Gigabytes
UltraSparc	    3 Terabytes

While it’s nice to be able to increase swap partition size to beyond 128 MB, how about increasing performance? Ideally, it would be nice if we could set up swap partitions in a RAID 0 stripe, so that reads and writes are equally distributed between all partitions. If these partitions are on separate drives and/or controllers, this will multiply swap file performance, allowing your servers to handle temporary memory usage “spikes” without getting dramatically bogged down.

Amazingly, all modern Linux kernels, by default (with no special kernel options or patches) allow you to parallelize swap, just like a RAID 0 stripe. By using the pri option in /etc/fstab to set multiple swap partitions to the same priority, we tell Linux to use them in parallel:

Set multiple swap partitions to the same priority

/dev/sda2	none	swap	sw,pri=3	0	0
/dev/sdb2	none	swap	sw,pri=3	0	0
/dev/sdc2	none	swap	sw,pri=3	0	0
/dev/sdd2	none	swap	sw,pri=1	0	0

In the above example, Linux will use swap partitions sda2, sdb2, and sdc2 in parallel. Since these partitions are on different drives, and possibly even different SCSI controllers, read and write throughput will nearly triple. The fourth swap partition, sdd2, will be used only after the first three partitions have been exhausted.

The pri option is really easy to use. The priority must be a number between 0 and 32767, with 32767 being the highest priority. The swap partitions will be used from highest priority to lowest priority, meaning that a partition with a priority of x will only be used only if all partitions with a priority greater than x are already full. If several partitions have the same priority, Linux will automatically parallelize access between them. This allows you to not only parallelize swap, but also prioritize access so that the partitions on the fastest drives (or regions of the drives) are used first. So, you can set up an emergency swap partition on an old, slower drive that will be used only if all high-speed swap is exhausted first.

Permalink Leave a Comment

10 things you can do when Windows XP won’t boot

August 6, 2008 at 1:51 am (Software)

When your computer hardware appears to power up okay, but the Windows XP operating system won’t boot properly, you have to begin a troubleshooting expedition that includes getting into the operating system, determining the problem, and then fixing it. To help you get started on this expedition, here are 10 things you can do when Windows XP won’t boot. Read the rest of this entry »

Permalink Leave a Comment

Manual steps to recover a corrupted registry that prevents Windows XP from starting

August 6, 2008 at 1:48 am (Software)

The procedure that this article describes uses Recovery Console and System Restore. This article also lists all the required steps in specific order to make sure that the process is fully completed. When you finish this procedure, the system returns to a state very close to the state before the problem occurred. If you have ever run NTBackup and completed a system state backup, you do not have to follow the procedures in parts two and three. You can go to part four. Read the rest of this entry »

Permalink Leave a Comment

How To Repair Window XP

August 6, 2008 at 1:39 am (Software)

One day without a obvious reason I had problems booting into windows so I went into the recovery console and the following error message popped up: “To replace the damaged registry hive and restore the backup copy of the hive from the Repair folder: Start your computer to the Recovery Console”

I am not a tech freak and honestly…. I was absolutely LOST! I started the computer in recovery mode, but still had no clue on how to fix the error. I was able to launch my web browser and thought it might be a good idea to look for an online xp repair service. And indeed, I found one offering a free online scan. I performed the online scan, the software found the errors and after paying for the software, my problem was fixed.

Of course… I would have preferred getting it for free, but as my computer got infected by spyware when I downloaded free software I now feel a lot safer downloading paid software… but this is another story.

So if you experience problems with windows xp and want to repair windows xp, I highly recommend checking out XP Repair Pro and take advantage of their free scan.

With XP Repair Pro you can safely clean, repair and optimize your Windows PC with a few simple mouse clicks!

To start a free scan, click below:

Repair Windows XP

Permalink Leave a Comment

Next page »