Every few months someone tells me their database on ZFS is slow, and the pool is one big dataset with every property at its default. recordsize is the property that bites. It is also the property people “fix” by running zfs set and then wonder why nothing changed.
What it actually is
recordsize is the maximum block size ZFS uses for a file’s data. The default is 128K. A file smaller than that gets a single block sized to fit, rounded up to the sector size. A file larger than that is stored in blocks of recordsize.
The cost shows up on partial writes. Change 8K in the middle of a file stored in 128K blocks and ZFS has to read the whole 128K record, modify it, and write a new 128K block somewhere else, because it is copy-on-write and never overwrites in place. That is write amplification, and it is the reason a small-page database hurts on a default dataset.
Look before you touch
zfs get -r -o name,property,value,source recordsize,compression,compressratio tank
The source column tells you whether a value is default, local, or inherited. Half the time the surprise is that a child dataset inherited something nobody chose.
Pick it per dataset
Set it when you create the dataset, because that is the only point where it costs nothing:
zfs create -o recordsize=16K tank/db
zfs create -o recordsize=1M tank/media
Rough guidance, not scripture:
- Databases doing page-sized random I/O: match the page size or a small multiple. PostgreSQL uses 8K pages and InnoDB defaults to 16K pages, so people commonly land on 8K to 16K. Read your database’s own documentation for its page size before you copy my numbers.
- Large sequential files such as media, backups and archives: bigger is fine. 1M is allowed by default and cuts metadata overhead. Anything above 1M needs a module tunable and a recent OpenZFS, so check your release before you go looking for it.
- General purpose home directories and mixed trees: leave the 128K default alone. It is a decent compromise and you will not win this one by cleverness.
The tradeoff runs both ways. Small records mean more blocks, more metadata, and worse compression, since each block compresses on its own with less data to find patterns in. A tiny recordsize on a dataset full of big files costs you space and speed for no gain.
It only applies to new writes
This is the part that burns people. zfs set recordsize=16K tank/db changes the property for blocks written from now on. Files already on disk keep the block size they were written with. You can confirm the property changed and watch the performance not move.
To actually rewrite old data, you have to write it again:
zfs create -o recordsize=16K tank/db-new
rsync -aHAX /tank/db/ /tank/db-new/
Stop the database first, naturally, and verify the copy before you swap names. A file that has grown past one block has its block size fixed, so even rewriting part of it in place will not reshape the rest. Copying to a fresh dataset is the reliable method. I would not trust a zfs send | zfs recv to do this for you, since a send stream carries the blocks across rather than reshaping them.
Compression changes the math
Keep compression=lz4 on almost everything. It is cheap and often makes I/O faster because less data hits the disk. Check what you are getting:
zfs get compressratio tank/db tank/media
Already-compressed media will sit near 1.00x and that is fine. Text and logs often compress well. The compressed size of a record is what lands on disk, so a 128K record that compresses to 40K occupies 40K, rounded up to the sector size.
Verify with the pool, not with a hunch
Measure request sizes against the workload instead of guessing. zpool iostat -r prints request size histograms on OpenZFS; check zpool-iostat(8) on your release for the exact options. If your database issues 8K reads and the pool is serving 128K records, you have your confirmation. Pair it with latency histograms from zpool iostat and you can see both the size and the time cost.
Where this ends up
I used to set one property on the whole pool and call it tuned. Then a Postgres box made a fool of me for a week. Now the dataset layout is the first design decision, because the properties you can set at creation are the ones you cannot cheaply fix later. If you ever have to move a dataset wholesale, send and recv covers the mechanics, and zfs diff will tell you what changed during the copy. More in the ZFS and storage hub.
