SUMMARY: Adding ZFS swap

From: Rob McMahon <Rob.McMahon_at_warwick.ac.uk>
Date: Wed Jan 26 2011 - 05:33:46 EST
Thanks for the replies.

Hendrick Visage suggested:

Add extra swap (mkfile /swapfile etc.) to handle swap size.
Delete rpool/swap from swap
expand rpool/swap
add rpool swap back
delete /swapfile etc.
At least the method I (as a conservative) would've followed.

A good plan, but it does require space somewhere for three times the 
current swap (1x in the new swap, plus 2x in the expanded swap).  Safer, 
though.  The new swap are can't be just /swapfile on a ZFS partition, I 
don't think, you'd need to do `zfs create -V 32G rpool/newswap ; swap -a 
/dev/zvol/dsk/rpool/newswap'.

Rick Smith pointed me at

http://www.solarisinternals.com/wiki/index.php/ZFS_Troubleshooting_Guide#ZFS_Swap_and_Dump_Devices

which is the definitive information:

"If you need to add swap space but removing an existing swap device is 
difficult on a busy system, add another swap volume. For example:

# zfs create -V 2G rpool/swap1
# swap -a /dev/zvol/dsk/rpool/swap1
# swap -l
swapfile             dev  swaplo blocks   free
/dev/zvol/dsk/rpool/swap 256,1      16 2097136 2097136
/dev/zvol/dsk/rpool/swap1 256,5      16 4194288 4194288

Add an entry for the second swap volume to the /etc/vfstab file."


Also safer than the fixing in place scheme.

Ian Collins confirmed what I thought, though, that the new offset should 
be swaplow+swaplen.  He says he's never set the reservation, but I did 
anyway.  In retrospect, I should have checked after the `set volsize', I 
have a feeling it's done for you.  So here's what I've done, successfully.

 > swap -l
swapfile             dev  swaplo blocks   free
/dev/zvol/dsk/rpool/swap 256,1      16 67108848 25095728
 > calc 67108848+16 # blocks + swaplo
67108864
 > zfs set volsize=64G rpool/swap
 > zfs set refreserv=64G rpool/swap
 > env NOINUSE_CHECK=1 swap -a /dev/zvol/dsk/rpool/swap 67108864 # 
blocks + swaplo from swap -l
 > swap -l
swapfile             dev  swaplo blocks   free
/dev/zvol/dsk/rpool/swap 256,1      16 67108848 25095728
/dev/zvol/dsk/rpool/swap 256,1  67108864 67108864 67108864
 > swap -s
total: 33592920k bytes allocated + 246624k reserved = 33839544k used, 
47414296k available
 >

(Mathematicians seem to like to allocate a lot of memory :-)

Thanks,

Rob

Original message:
> Greetings,
>
> I need to increase the size of my ZFS swap partition, rpool/swap.  I
> can't reboot, and I can't delete and replace the current swap space
> because it's 50% used.  I could add another volume, but looking around
> the web, there are many comments on how to expand the existing one.  I
> wanted to check one thing.  The cookbook method is:
>
> # swap -l
> swapfile dev swaplo bloques libre
> /dev/zvol/dsk/rpool/swap 256,2 16 *2097136* 2097136
> # zfs set volsize=2G rpool/swap
> # env NOINUSE_CHECK=1 swap -a /dev/zvol/dsk/rpool/swap $((8+*2097136*))
> # swap -l
> swapfile dev swaplo bloques libre
> /dev/zvol/dsk/rpool/swap 256,2 16 2097136 2097136
> /dev/zvol/dsk/rpool/swap 256,2 2097152 2097152 2097152
> #
>
> Is it just me, or is that $((8+...)) just wrong, and should be
> $((16+...)) (swaplo) ?  This value of 8 is repeated in a few blogs where
> swaplo==16.  Has this just been blindly copied from a system where
> swaplo was 8, like this example (also grabbed from the web).
>
> cjg@brompton:~$ swap -l
> swapfile dev swaplo blocks free
> /dev/zvol/dsk/rpool/swap 182,1 8 4126712 4111472
> cjg@brompton:~$ pfexec zfs set volsize=4G rpool/swap
> cjg@brompton:~$ pfexec zfs set reservation=4G rpool/swap
> cjg@brompton:~$ pfexec env NOINUSE_CHECK=1 swap -a
> /dev/zvol/dsk/rpool/swap $((8+4126712))
> cjg@brompton:~$ swap -l
> swapfile dev swaplo blocks free
> /dev/zvol/dsk/rpool/swap 182,1 8 4126712 4111472
> /dev/zvol/dsk/rpool/swap 182,1 4126720 4261888 4261888
> cjg@brompton:~$
>
> Do I need to set the reservation ?  At the moment the volume has
>
>   >  zfs get all rpool/swap | fgrep reserv
> rpool/swap  reservation           none                   default
> rpool/swap  refreservation        32G                    local
>   >
>
> I just want to check before I break anything ...
>
> Thanks,
>
> Rob
>


-- 
E-Mail:	Rob.McMahon@warwick.ac.uk		PHONE:  +44 24 7652 3037
Rob McMahon, IT Services, Warwick University, Coventry, CV4 7AL, England
_______________________________________________
sunmanagers mailing list
sunmanagers@sunmanagers.org
http://www.sunmanagers.org/mailman/listinfo/sunmanagers
Received on Wed Jan 26 05:34:11 2011

This archive was generated by hypermail 2.1.8 : Thu Mar 03 2016 - 06:44:17 EST