Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

When I search around for example RAID1 installations, it seems that admins tend to place their swap partition under RAID1.

To me, it is more intuitive to have two disks, each with a large partition for use by RAID1 and the system partition and with a smaller partition for swap, outside of the RAID array.

  1. What is the worst-case-scenario if I lost a disk and effectively half of my swap space while the system is running?

  2. Should I expect to see a performance increase or decrease while mirroring a swap volume vs having two separate swap volumes outside of RAID?

  3. If swap should be mirrored, does it make more sense to give swap its own RAID1 array, or does it make more sense to partition one big RAID1 array with LVM?

(Note/4. I'm not sure if mdX can be partitioned without LVM, but the debian installer leads me to believe that it cannot)

share|improve this question
1  
On a system where performance is a concern generally one would hope that you have enough memory that swap is not really used, and so the underlying storage shouldn't matter all that much. –  Zoredache Oct 28 '10 at 16:51
    
[This answer][1] on another thread explains it quite well. [1]: askubuntu.com/a/246002/196011 –  Pavel Tankov Apr 24 at 14:27

2 Answers 2

up vote 13 down vote accepted
  1. If you are using RAID1 you won't lose half your swap, only one of the two mirrors. The worst case here is you'll lose any performance benefit you might otherwise have gained. If you have two separate swap areas on the individual drives the kernel will use both in a fashion similar to RAID0 (if they have the same priority set) or JBOD (if priorities differ, using the top priority area until full then the next) so if one of the drives dies your system is likely to fall over as soon as any access to the swap area(s) is needed. This is why swap spaces usually live on the RAID1 volumes - it is simply safer and that is more important than performance usually.

  2. Two separate swap areas would get used similar to RAID0 so you would expect to see a performance increase generally, though it depends on the other load your drives are under at the time. With modern kernels the RAID1 driver can try to guess which drive is best to read each block from so you might get a bit of the read performance boost, though obviously for writing to swap you won't as both mirrors must be updated. On most modern setups the performance of swap is not as important as its safety - RAM is relatively cheap these days so unless you are butting against the limit of how much RAM your motherboard can take you should aim to have enough RAM so that swap space is used as little as possible anyway.

  3. It will make little difference if you are using the same pair of disks. A common reason for having swap on a separate array is when using RAID5/6 for the main array (which is not true in your case) to avoid and paging out to the swap areas being hit by the RAID5/6 write performance issue. You can probably tune performance by trying to ensure that the swap areas are close to the busiest part of the disks (so if you have a 1Tb array with a 250Gb logical volume used for your most busy active database files, putting youw swap volume next to that) to reduce head movements while swapping - but really such tweaks are not time well spent as by the time you are swapping heavily the %-or-two benefit won't be enough to make the difference between performing OK and not.

  4. I believe you can partition software RAID volumes as far as the kernel is concerned, but that doesn't mean the installer understands such arrangements. In examples not using LVM I've always seen the drives divided into partitions and having a separate RAID array for each partition, rather than one large RAID volume which is partitioned. I recommend the LVM method unless you have specific reason to avoid it as it is more flexible and (in my experience) no less reliable than other arrangements.

share|improve this answer
    
Great insight. I appreciate it, thanks! –  andyortlieb Oct 28 '10 at 20:25
1  
Shorter version of above: If you have RAID1 to ensure your server stays up if a drive fails, put swap on the RAID1. If you have it to speed up recovery time / avoid data loss if a drive fails, don't bother. As always, RAID0 = NRead, NWrite, RAID1 = N*Read performance improvement for N disks.. –  Slartibartfast Oct 29 '10 at 2:17
    
Does RAID1 not introduce a performance decrease for writing? –  andyortlieb Oct 29 '10 at 13:05
1  
There may be a slight drop in write performance with RAID1 depending on your controller/software, but I doubt it is significant. If the controller blocks until both drives say they've written the block then there might be slightly more per-block latency (as it'll go as the speed of the slowest drive to respond), though if the drives or controller buffer writes in any way any such differences vanishes. –  David Spillett Oct 29 '10 at 18:57
1  
@warren: generally speaking you would not want swap on RAID5 due to the write performance issue that can affect R5 (every block written potentially involves a read first so that the parity block can be correctly calculated) especially for lots of slow writes. –  David Spillett May 1 '11 at 20:25

You can have the benefit of RAID0 fast access (although reads only) and security of RAID1 on Linux if you use RAID10. Linux MD driver can create RAID10 volumes on any number of drives, from 2 up. To get the speed benefit you need to specify the layout of array as "far" (-p f2), this way the read performance is similar to RAID0 while the write performace is only slightly slower than RAID1.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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