# freebsd-swap status with GPT



## da1 (Sep 7, 2011)

Hi guys,

I was presented with an interesting question today, to check/see if the swap on a mirror ZFS (RooTonZFS with GPT partitions) is actually mirrored. On some old systems we have gmirror with 2 partitions acting as a swap device but with the new systems, we have a GPT zfsonroot instalation. 

So the question is, is there a way to see if the freebsd-swap partition is actually mirrored ?


----------



## SirDice (Sep 7, 2011)

Why on earth is swap mirrored?


----------



## da1 (Sep 7, 2011)

Because if you have a mirror and 1 disk fails and you get a kernel panic until you get to change the failed disk, you will not get a savecore file to debug if you reboot. If your swap is on both disks, you can use the eventual data dumped to it. If it's only on 1 disk (and you have a mirror) and that exact disk fails, you have no swap anymore.


----------



## SirDice (Sep 7, 2011)

That's why you create two swap partitions, one on each drive. Mirroring it is just silly.


----------



## da1 (Sep 7, 2011)

If you create 2 swap partitions on each drive, the system will use them as a stripe (ex: 2x 4G swap partitions on each drive = 8GB of swap space). This is again, bad.


----------



## SirDice (Sep 7, 2011)

da1 said:
			
		

> This is again, bad.


No, it's not. If one drive fails the other would still work and you'd still have swap. It's not like RAID0 where one drive fails, the entire striped set fails.


----------



## da1 (Sep 7, 2011)

True, but case:

2x 4GB swap partition = 8GB swap used by FreeBSD. Imagine running a busy mysql box that uses 5GB swap and you lose the first hdd (the first 4GB of swap); then, you loose your mysql swap.

One way to mirror the swap is by gmirror or ZFS-swap (but this needs a hack).


----------



## SirDice (Sep 7, 2011)

Simple solution, bigger swap partitions. It also improves performance if you spread your swap around.  Like I said, mirroring is just silly.

NB 2x4GB mirrored is only 4GB which wouldn't fit your mysql example.


----------



## da1 (Sep 7, 2011)

Ok, of course one can use a bigger swap partition but if you have only 1, you have a single point of failure. Imagine having, lets say 32GB of swap on 1 disk, and that swap is used at 90%, and your disk dies; so does your swap.


----------



## SirDice (Sep 7, 2011)

If your swap is 90% in use you're doing it wrong.


----------



## da1 (Sep 7, 2011)

It's an example. It can be 20% if you like this number more .


----------



## SirDice (Sep 7, 2011)

da1 said:
			
		

> It's an example. It can be 20% if you like this number more .



That would fit easily on the drive that's still left


----------



## da1 (Sep 7, 2011)

Yes it can but what happens if the drive holding the swap fails ? The system goes on fine, because ZFS manages 2 drives, but you have just lost your (example) 20% swap.


----------



## da1 (Sep 7, 2011)

Mirrored with gmirror.


----------



## oliver@ (Sep 7, 2011)

Having 2 swap partitions across two disks without having them mirrored (so you use a raid-0 swap literally speaken) is "stupid". Then your system will possible crash if one of the disks are failing because who knows if this is exactly the disk which FreeBSD uses right now as swapspace. Also you're system probably won't boot up again with just a broken disk as the 2nd swap space which is mentioned in your fstab is just no longer there.

So - I have the same question actually right now - Do I use gmirrored swap or ZFS-mirrored swap for my new box here.

Right now I think I'll go with gmirror for my actual setup as this seems to be the way it was done for some time now and I don't like to experiment that much and think about ZFS demanding memory to write on your swap partition which itself has to be swaped. I can imagine that in some conditions you'll have race conditions...

My actual (old) setup was gmirror+UFS with no ZFS at all. There I had the whole disk mirrored which is the easiest way to handle disk failures as you just need to remove the disk, insert a new one and just rebuild the array.
Now with using ZFS you'll have to 
a) create a label on the new disk
b) write the bootcode onto the new disk
c) rebuild the gmirror (swap) 
d) rebuild the ZFS mirror
This are a bit more steps.
Having swap on ZFS will reduce this by removing the gmirror step c. 
I'm just not sure how well swap on a mirrored ZFS will work and if this is worth the one step more in case of a recovery when having gmirrored swap in case a disk fails....

You'll also find this note in the FreeBSD Wiki:



> While a ZFS Swap Volume can be used instead of the freebsd-swap partition, crash dumps can't be saved to the ZFS Swap Volume.


----------



## da1 (Sep 7, 2011)

Regarding the note, from the top of my head, I would say that writing a "REQUIRE: zfs" to /etc/rc.d/dumpon should suffice but this is untested.
About the original inquiry, I have created a gmirror for the swap and it works fine (1 out of 2 boxes works fine -> 2nd box).


----------

