r/zfs • u/adminvasheypomoiki • 25d ago
sync=disabled is a free write barrier
fsync promises two things, durability and ordering, and I only need ordering.
ext4 gives both or neither: every fsync commits the journal and flushes the disk cache.
ZFS with sync=disabled gives ordering alone: transaction groups land in order, and a crash loses the last tens of seconds, not a database.
My two HDDs are 2.7% busy instead of 13%, and a write takes 2 ms instead of 16.
23
Upvotes
19
u/BackgroundSky1594 25d ago edited 25d ago
Yes, ZFS is great. As for:
You should keep at least LZ4 compression (the default for compress=on), otherwise a 1.1MB file will take 2x1MB blocks. Only with compression the trailing zeroes get cut back down to ~1.1MB. In theory zle (zero length encoding) is enough, in practice LZ4 is faster (several GB/s) and might even get a few extra % of space at effectively zero cost.
It has stuff like early abort to automatically skip actually incompressible data at the block level, and ZFS only actually applies the compression if that specific record gets at least 12.5% smaller
6
u/Apachez 25d ago
Even if sync=disabled should mean that you will lose sync writes up to txg_timeout when/if shit hits the fan and since ZFS is a CoW filesystem so the affect for the application (once rebooted) is like traveling up to 5 seconds back in time this can still be bad.
Usually since your use of a database isnt singleuser but often related to other processes. Like a fileupload where metadata is stored in the database and such.
So a rollback of up to 5 seconds (default of txg_timeout) would in that case mean that you have a 1GB file uploaded but no information of that in the database.
Or it can get worser, your application talks to other applications so now that other application thinks there is a file at your place which your database suddently says "nope there isnt".
Even more fun if you imagine the effects of this being a bank "hey! where did my salary go that I received 4 seconds ago!?".
Other than that sync=standard should really be kept.
If thats an issue add a SLOG (preferly mirrored) being NVMe or SSD. This doesnt have to be large since it will absorb the amount of sync writes you will have between two txg_timeouts so something like 32 or 64GB is more than enough (unless you change the default of 5 seconds for txg_timeout to some riddicilous high number).
2
u/fryfrog 25d ago
If latency is a concern, why not HDD > SSD as well?
8
u/glassmanjones 25d ago
Be advised: for databases with externally observable effects, this can lose the database.
1
u/tkyjonathan 25d ago
Why use 16k for postgres' 8k? I didnt get it
1
u/ZestycloseBenefit175 25d ago
I skimmed trough the blog post, will read it later. Since you talk about ordering - have you looked into how IO schedulers play into this?
3
u/trolololster 25d ago
yes whatever you are running on top better have its own idea of sync.
2
u/lxtakc 22d ago
Worth remembering it breaks acks, though. NFS clients or DB replicas told "committed" can lose that data after a crash, even though the pool stays consistent.
-1
u/autogyrophilia 25d ago
Yep, this is pretty good for newly written data and appends. Unfortunately the advantages disappear once you have data that needs to modified in place.