Find it

Tuesday, July 14, 2009

ZFS and Swap space

Hi there...

Few days back I came across a situation where, I have been told to create the swap device on ZFS filesystem. Basically, being new to ZFS - I was not at all knowing about "how-to do this" hence after some research on internet about it found some good stuffs hence thought of sharing same for you all -

NOTE - To set up a swap area, create a ZFS volume of a specific size and then enable swap on that device. Do not swap to a file on a ZFS file system. A ZFS swap file configuration is not supported.

ZFS volumes are identified as devices in the /dev/zvol/{dsk,rdsk}/path directory.

E.g. - /dev/zvol/dsk/swap-zfs

So here I wanted to add 32 GB of swap space -

# zfs create -V 32g -b 8K zfsnode1-zpool/swap
# zfs set refreservation=32g zfsnode1-zpool/swap
# swap -a /dev/zvol/dsk/zfsnode1-zpool/swap
# swap -l

>>> /etc/vfstab <<<
/dev/zvol/dsk/zfsnode1-zpool/swap    -       -       swap    -       no      -
NOTE: Setting the reservation is important, particularly if you plan on making the change permanent, eg by adding the new zvol as a swap entry in /etc/vfstab. ZFS does not reserve the space for swapping otherwise, so the swap system may think there is space which isn't actually there if you don't do this.

NOTE: The -b option sets the volblocksize to improve swap performance by aligning the volume I/O units on disk to the size of the host architecture memory page size (4 KB on x86 systems and 8KB on SPARC, as reported by the pagesize command.)

It is also possible to grow the existing swap volume. To do so, set a new size and refreservation for the existing volume like this:

# swap -d /dev/zvol/dsk/rpool/swap
# zfs set volsize=2g rpool/swap
# zfs set refreservation=2g rpool/swap
# swap -a /dev/zvol/dsk/rpool/swap

That's it! Hope this helps...

2 comments:

  1. If the zvol is to be a swap device, I think the dataset
    property "volblocksize" must be set accordingly too:

    SPARC# zfs create -V 2G -b 8k rpool/swap
    x86# zfs create -V 2G -b 4k rpool/swap

    Nonetheless, I found very interesting things on your
    blog! Thank you.

    --
    julien.
    http://blog.thilelli.net/

    ReplyDelete
  2. Julien, Thanks for visiting the blog. I do appreciate your valuable comments & I'm hoping you will keep randomly visiting my blog.

    Have a good one!
    Nilesh

    ReplyDelete