That's an 8 year old bug against Linux, not FreeBSD.
While that is probably textually correct, given the reported problems, it has been mentioned, by several OpenZFS developers, that a solution would require some fundamental changes/code reworks to alleviate the problem. IIUC, it is nowhere suggested that this is actually a problem limited to Linux[1]; it has been suggested that FreeBSD might very well be vulnerable in the same manner,
Prakash Surya on Sep 17, 2018:
I'm not an expert in this area of the code, but I think that swap on ZVOL is inherently unreliable due to writes to the swap ZVOL having to go through the normal TXG sync and ZIO write paths, which can require lots of memory allocations by design (and these memory allocations can stall due to a low memory situation). I believe this to be true for swap on ZVOL for illumos, as well as Linux, and presumably FreeBSD too (although I have no experience using it on FreeBSD, so I could be wrong).
[...]
I'll note his reservations about his familiarity with the particular ZFS code sections affected by this problem, but I see no rebuttals or denials following.
If FreeBSD does not suffer from this "ZVOL as swap" problem in any way, then,
zfs-create(8):
Code:
ZFS for Swap
Swapping to a ZFS volume is prone to deadlock and not recommended. See
OpenZFS FAQ[2].
would be incorrect, or at least not based on any concrete (FreeBSD) data.
IF that is indeed incorrect, then, IMHO,
zfs-create(8) should reflect that and it should be amended.
With respect to using either
sync=disabled or
sync=always, in addition the the "ZVOL as swap" problem, the advice of the OpenZFS FAQ is diametrically opposed to -outdated-
FreeBSD ZFS Wiki - 2.2. ZFS Swap Volume. My hunch is that
sync=always on Linux reduces the possibility of a deadlock somewhat; note however, where ZFS writes would normally be accumulated and saved together (asynchronous writes), using
sync=always is devastating for throughput.
IIUC, especially when using a ZVOL as swap the deadlock issue can arise when there is extreme memory pressure where the ZFS ARC needs to give up part of its occupied RAM as-fast-as-possible to free it. Ensuring matching of the ZVOL's blocksize to the OS of by means of
[3] and not using compression play a part in latency minimization; under extreme memory pressure compression (even though not CPU intensive on modern CPU's for the default ZFS compression) requires some additional RAM that adds to that extreme memory pressure which we're trying to avoid. When the IO for your zpool is already saturised, placing your swap on the same disk doesn't help much in lowering latency for your swap data that need to be written out to disk as quickly as possible.
Awaiting a final solution to
Swap deadlock in 0.7.9 #7734, I'd look at deploying ZFS DIRECT IO that bypasses the ARC:
To use ZFS
Direct IO, you'll need at least
OpenZFS - ZFS 2.4.0. For FreeBSD that means using the 15 branch,
FreeBSD 15.0-RELEASE Release Notes contains
ZFS 2.4.0 - rc4
___
[1] Given the structure of OpenZFS code development,
OpenZFS - "Code flow", it is, in my view, more likely than not that all other OS-es (illumos included) are vulnerable to this problem.
[2]
Using a zvol for a swap device on Linux
[3] When not matched, this can easily lead to write amplification, see for example
Tuning OpenZFS by Allan Jude and Michael Lucas.