zfsonlinux / pkg-zfs

Native ZFS packaging for Debian and Ubuntu
https://launchpad.net/~zfs-native/+archive/daily
308 stars 55 forks source link

zvol for swap and sync=? #229

Open HRio opened 5 years ago

HRio commented 5 years ago

Looking in: https://github.com/zfsonlinux/pkg-zfs/wiki/HOWTO-use-a-zvol-as-a-swap-device I see

zfs create -V 4G -b $(getconf PAGESIZE) -o compression=zle \
      -o logbias=throughput -o sync=always \
      -o primarycache=metadata -o secondarycache=none \
      -o com.sun:auto-snapshot=false rpool/swap

why sync=always? if the system crashes all RAM will be lost. hence writing swap synchronously seems a bit too much.

sync=always
  For the ultra-cautious, every file system transaction is
  written and flushed to stable storage by a system call return.
  This obviously has a big performance penalty.

FreeBSD docs for reference: https://wiki.freebsd.org/RootOnZFS#ZFS_Swap_Volume

zfs create -V 2G -o org.freebsd:swap=on -o checksum=off -o compression=off -o dedup=off -o sync=disabled -o primarycache=none zroot/swap

Why should it be sync=always when using zfs on linux, or is it a typo?

Temtaime commented 4 years ago

Ping. Any response?

HRio commented 4 years ago

sync-always will just add latency, whats the need for it? I feel it will only add to the problems when we are in a state where we need to swap

RSully commented 4 years ago

My guess: I assume the reasoning here is that if we are under a condition of extreme memory pressure (e.g. swapping is required) then it doesn't make sense to use more memory to buffer these writes which would compound the problem

HRio commented 4 years ago

sync=always means that the data first i written to the ZIL and then after that to the final media. Its in memory also when the write to the ZIL is done. Its not free'd from the memory until both the zil write and the write to final storage is fully ready. I.e. sync always in this case only ads to the time before we can free the memory

yennor commented 2 years ago

Actually I've also just stumpled over that. I've wanted to checkout what are recommended settings for swap devices, and noticed, that everybody recommends sync=always (but their commands look al the same, so I guess they've all copied from the same place). Could anybody with more insight tell if there is any reason why sync=always should be used than sync=disabled (Which seems to be the logical choice for me)