Can I set a swap in zvol?

It's not recommended.

zvol is in ZFS pool, just NOT a ZFS native filesystem (dataset).
This means that features of the pool is applied to zvol, too.

It allows fragile filesystems to be backed by the reliability features of ZFS pools (i.e., checksum, if configured, zraid, ...), with the cost of additional memories to handle the features.

This can cause things worse (at worst, crash) on so-called "thrashing" state.

Same (at least alike) can be said with swap files on UFS (or any other filesystems). So dedicated "physical" swap partition is strongly recommended.

Looking into info on Internet, Solaris after making ZFS its default documents to use zvol for swaps. Not read the relevant source codes, but it would be because ZFS is the only filesystem to be configured, and would keep sufficient (a fair amount of) physical memories to handle ZFS features even on thrashing states, but it should mean that there are unallocatable-to-userland and unusable-for-other-purpose kernel memories, making thrashing state to come earlier.
 
so us
It's not recommended.

zvol is in ZFS pool, just NOT a ZFS native filesystem (dataset).
This means that features of the pool is applied to zvol, too.

It allows fragile filesystems to be backed by the reliability features of ZFS pools (i.e., checksum, if configured, zraid, ...), with the cost of additional memories to handle the features.

This can cause things worse (at worst, crash) on so-called "thrashing" state.

Same (at least alike) can be said with swap files on UFS (or any other filesystems). So dedicated "physical" swap partition is strongly recommended.

Looking into info on Internet, Solaris after making ZFS its default documents to use zvol for swaps. Not read the relevant source codes, but it would be because ZFS is the only filesystem to be configured, and would keep sufficient (a fair amount of) physical memories to handle ZFS features even on thrashing states, but it should mean that there are unallocatable-to-userland and unusable-for-other-purpose kernel memories, making thrashing state to come earlier.
so use the default freebsd-swap partition is better?
 
The ZVOL based swap-areas in Solaris is handy as it allows you to Re-size the swap areas if requiered

Add ZVOL swap on second HDD
Delete ZVOL swap on first HDD & recreate it with desired SIZE.
No messing about with backing up ZROOT filesystem and deleting HDD root partition to increase swap Parttion and finally restoreing ZROOT.
 
The ZVOL based swap-areas in Solaris is handy as it allows you to Re-size the swap areas if requiered

Add ZVOL swap on second HDD
Delete ZVOL swap on first HDD & recreate it with desired SIZE.
No messing about with backing up ZROOT filesystem and deleting HDD root partition to increase swap Parttion and finally restoreing ZROOT.
It would be because Solaris was re-designed to allow it stably (with the cost of not so small memory consumption) use swap on zvol when it made ZFS the default filesystem.

Yes, it would be "technically" possible on FreeBSD, too, if FreeBSD project decides to completely ignore small embedded use-cases.
In my humble opinion, it would require large rework on virtual memory subsystem, especially pager and swapper.
 
I never had any stability problems with zfs-swap created like this:

zfs create -V 8G -o org.freebsd:swap=on \
-o checksum=off \
-o compression=off \
-o dedup=off \
-o sync=disabled \
-o primarycache=metadata \
-o secondarycache=none \
-o logbias=throughput \
zpool/swap
 
I never had any stability problems with zfs-swap created like this:

zfs create -V 8G -o org.freebsd:swap=on \
-o checksum=off \
-o compression=off \
-o dedup=off \
-o sync=disabled \
-o primarycache=metadata \
-o secondarycache=none \
-o logbias=throughput \
zpool/swap
Does this have any performance improvement?
 
Does this have any performance improvement?

I also want to upgrade the RAM for my laptop, but memory prices have gotten more expensive recently.

Err..no. Big no. Hell no.

The reason to use swap is so the kernel can swap out the inactive memory pages, which will enable it to have more available pages and hand them out faster. (simplified, in a nutshell)

So, even if you have a terabyte of ram, having just a small swap (2g) helps with the system performance.

Swap is under no circumstances a replacement of RAM and you don't want any working memory sets being swapped in and out on the desktop machine. That is death.

If anyone remembers old Windows machines from 90s that were loaded with startup items, tray icons, where you couldn't move the mouse without HDD chunking sound and red LED aggressively blinking from the case, and program load took 30 seconds - that is where your working memory goes above the RAM and into the swap.
 
The ZVOL based swap-areas in Solaris is handy as it allows you to Re-size the swap areas if requiered

Add ZVOL swap on second HDD
Delete ZVOL swap on first HDD & recreate it with desired SIZE.
No messing about with backing up ZROOT filesystem and deleting HDD root partition to increase swap Parttion and finally restoreing ZROOT.

Is that second paragraph still about Solaris or is it a FreeBSD suggestion? Either way what's the point of the second pool?
 
Is that second paragraph still about Solaris or is it a FreeBSD suggestion? Either way what's the point of the second pool?
I think he's talking about "how to expand swap space using zvol vs swap partitions". Partitions, need mucking around in gpart and doing things, which may have danger associated with it.
Swap on a zvol is add a new zpool, create the zvol on it, swapon new thing, swapoff on old.
Mucking around at a higher level than partitions so marginally less danger.

My understanding (simplistic) of zvol is it's basically a "block device created as a child of a zpool" and is basically (mostly) outside of ZFS, kind of like taking an SSD and creating a partition of 85%, reserving 15% for "future use".
 
huh. we'd had both recommended against for the same reason. if zvols are safe that's cool.

As I said, it is IIRC. But I think the buffer cache on the plain file is the problem, and that wouldn'r apply to the zvol.

Of course given a choice a partition is better, unless you want to survive disk changes.
 
we had a problem once swapping to separate devices; one of them fell off the bus and we got a core dump with a hole in it, so our new setup swaps to a gmirror.
 
I think he's talking about "how to expand swap space using zvol vs swap partitions". Partitions, need mucking around in gpart and doing things, which may have danger associated with it.
Swap on a zvol is add a new zpool, create the zvol on it, swapon new thing, swapoff on old.
Mucking around at a higher level than partitions so marginally less danger.
He referred to deleting a zvol swap from the first drive and creating a new zvol swap on the second drive.
 
  • Like
Reactions: mer
He referred to deleting a zvol swap from the first drive and creating a new zvol swap on the second drive.
If you are in multi-user mode , some things may use the swap ,,, so it should not be removed completely .
To increase the size of the ZVOL containing swap on the RootPool the ZVOL needs to be recreated.
having a secondary SWAP area online is just a safety consideration.
ofcourse , if this is done in single-user mode it can be done without a secondary swap in the system .
 
Back
Top