Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
22
rated 0 times [  22] [ 0]  / answers: 1 / hits: 23186  / 2 Years ago, wed, june 15, 2022, 9:12:03

I have a box with a small RAID-1 array being used for swap space. I only did this since I was setting up mirrors for every other partition in the system.



Today I read this question and it prompted me to wonder: "is having swap on RAID-1 ideal / advisable ?".


More From » 12.04

 Answers
6

You should (probably) not take your swap off the RAID 1.


It's sometimes less important have swap on a RAID 1, but it's fine, usually helpful, and often necessary. Rarely is there any reason to deliberately put your swap elsewhere, if you're already using a RAID 1.


Swap on RAID 1 May Perform Better


SWAP on RAID 1 can be expected to perform better than a single swap partition outside the RAID, but not as well as two swaps set to the same priority.


Writing to a RAID 1 is sometimes slower than writing to a single disk, since all data must be written to both disks. Often it's not really slower--usually the slowdown will be negligible. If you have a RAID 1 of two disks on the same IDE controller, it will be slower. But when accessing one disk doesn't slow down accesses to the other disk, writing to the RAID 1 will not be significantly slower.


Reading from a RAID 1 is almost always faster than reading from a single disk, since when one disk is occupied by a read, more data can be read from the other disk. Reading from a RAID 1 made up of two drives is often almost twice as fast as reading from a single drive.


I'm not aware of any tests to compare two separate swap partitions to a single swap partition on a RAID 1 (or any other RAID). There's no reason to think a single swap partition would perform as well or better than a swap on a RAID 1. The situation is more complicated if you have two swaps on separate disks:



  • If the swaps are given different priorities in /etc/fstab, separate pages are swapped to them; the same page is not swapped to both at once. I'd expect two swaps to be faster for accessing unrelated swapped data simultaneously, but slower for accessing a single page.



  • If the swaps are given the same priority in /etc/fstab, data (even from a single page) will be striped. This is similar to RAID 0 and will most likely perform even better than putting the swap on a RAID 1.


    Theoretically if you have a hardware RAID 1, software striping could be less efficient, but unless you have unusual applications where reading from swap is overwhelmingly more common than writing to it, I would expect a non-RAID software striped swap to outperform a swap partition on a RAID 1.


    (Since the kernel can stripe swapped data between multiple swap partitions, there's no reason to set up a software RAID 0 just for swap.)




See this section of the Wikipdia article "Standard RAID levels", for more information about RAID 1 performance.


Thanks to gertvdijk for providing critically important information about striped swaps.


You Might Really Need Your Swap on the RAID 1


Whether or not you need your swap on a RAID 1 depends on why you need a RAID 1 in the first place. The data in swap is typically highly volatile and losing it usually doesn't represent a significant loss of assets. However.:



  1. One benefit of RAID (except RAID 0) is that if a drive fails your computer keeps running (just somewhat slower). If you have programs running that have swapped pages to disk (which virtually always is the case if swap is enabled), the drive containing a swap partition (whether or not it's the only swap partition) fails, and it doesn't have a redundant backup, your system will immediately stop working right (and will likely be entirely unusable until rebooted, depending on how the swap was being used). If you're using the machine as a production server or for any other important task, downtime will result.


    If you can tolerate total swap failure from a single commonly encountered adverse event (one drive failing), you should ask yourself why you're using RAID 1 at all. You might have a good answer...and you might not. RAID (except RAID 0) safeguards against disk failure, but RAID is not a backup solution. If you change or delete a file on a RAID, or malware infects a system on a RAID, the changes are made immediately everywhere--the RAID will not enable you to recover from that.


    If what you need is a backup rather than redundancy, and you don't already have a highly reliable, easily accessible backup, then you should take one of the drives out of RAID completely and use it for backups. (Of course, sometimes it is also necessary to have an off-site backup.)



  2. If you hibernate your computer (i.e., suspend-to-disk), the contents of RAM are copied to the swap partition. So you can actually lose data by losing your swap partition, if your machine is hibernated when disk failure occurs.




[#33089] Friday, June 17, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
feeous

Total Points: 102
Total Questions: 122
Total Answers: 119

Location: Netherlands
Member since Thu, Jul 1, 2021
3 Years ago
feeous questions
Sat, Jul 23, 22, 23:21, 2 Years ago
Mon, Jul 5, 21, 19:59, 3 Years ago
Mon, Aug 16, 21, 11:42, 3 Years ago
Sun, Mar 19, 23, 21:03, 1 Year ago
;