feat: tiered zfs pools and a shared steam library #127

Open
jan-leila wants to merge 1 commit from tiered-storage into main
Owner

twilight and emergent keep everything on a single hard drive, with an NVMe that was only a read cache (L2ARC). Every write and every cache miss waited on the hard drive, and twilight's is shingled (ST8000DM004): in one hour of uptime processes spent 17 minutes stalled on IO, with writes regularly waiting seconds. This shows up as hitching in games.

What changes

  • Pool roles: storage.zfs.pool gains special and log device lists beside cache, and a per-device size, so one disk can be split between roles.
  • Tiering: a pool with special devices sets special_small_blocks=128K on its root dataset, so every dataset lives on the special vdev by default. A dataset opts out to the regular vdevs with specialSmallBlocks = "0".
  • twilight and emergent: the NVMe becomes special vdev + 16G log + read cache (256G on twilight, 128G on emergent).
  • Shared Steam library: programs.steam.sharedLibrary.enable adds a dataset mounted at /games/steam, owned by a steam group holding every user with Steam enabled, group-writable and excluded from snapshots. Proton prefixes are not shared, because Wine refuses to run from a prefix another user owns: inside Steam's sandbox each user's own ~/.local/share/Steam/steamapps/compatdata is mounted over the library's.
  • defiant and the other hosts are unchanged.

Before merging

  • The NVMe becomes pool-critical. Losing it now loses the pool. zpool remove can evacuate the special vdev back onto the hard drive later.
  • Bulk data needs its own dataset. New data spills onto the hard drive once the special vdev is about 75% full, so whatever will fill the hard drive should get a dataset with specialSmallBlocks = "0" before then.
  • Not yet tested on real hardware. Both hosts build, but the pool commands have not been run, emergent's pool was not inspected (commands are written from its config), and no Proton game has been launched through the new sandbox mount. sharedLibrary.enable = false reverts the Steam side.

Migration: twilight

Disks are only partitioned at install time, so the layout this describes has to be made by hand. The pool stays online throughout. sgdisk is in the gptfdisk package.

# 0. check the hard drive is healthy before leaning on it
sudo smartctl -a /dev/sda

# 1. take the NVMe out of the pool (it only holds cache copies)
sudo zpool remove rpool nvme-nvme.1e4b-323530343533313135323030313437-53504343204d2e32205043496520535344-00000001-part1

# 2. repartition it with the labels the config expects
NVME=/dev/disk/by-id/nvme-SPCC_M.2_PCIe_SSD_250453115200147
H=3abe5e8a2b9d578d7f8a133514d
sudo zpool labelclear -f ${NVME}-part1
sudo sgdisk --zap-all $NVME
sudo sgdisk -n1:0:+16G -c1:disk-$H-log -n2:0:+256G -c2:disk-$H-l2c -n3:0:0 -c3:disk-$H-spc $NVME
sudo udevadm settle && ls -l /dev/disk/by-partlabel/

# 3. add it back in its three roles
sudo zpool add -o ashift=12 rpool special /dev/disk/by-partlabel/disk-$H-spc
sudo zpool add -o ashift=12 rpool log     /dev/disk/by-partlabel/disk-$H-log
sudo zpool add             rpool cache   /dev/disk/by-partlabel/disk-$H-l2c

# 4. send all new data to the NVMe
sudo zfs set special_small_blocks=128K rpool

# 5. create the Steam dataset (the rebuild refuses to switch without it)
sudo zfs create -o mountpoint=/games/steam -o atime=off -o acltype=posixacl \
  -o com.sun:auto-snapshot=false rpool/persist/local/steam

# 6. apply the config, then log out and in to pick up the steam group
./rebuild.sh --mode=switch

Data written before the change stays on the hard drive until it is rewritten:

  1. In Steam, add /games/steam under Settings > Storage and move the installed games to it. The move rewrites them onto the NVMe.
  2. Rewrite the rest. This reads everything back off the hard drive, so it takes a while:
sudo zfs rewrite -r /persist/local /persist/replicate
sudo mount -o remount,rw /nix/store
sudo zfs rewrite -r /nix
sudo mount -o remount,ro /nix/store

Existing snapshots keep the old copies on the hard drive until they expire. zpool list -v shows how much sits on each device.

Migration: emergent

Check first that the pool matches what the config says (a single hard drive plus the Intel NVMe as cache, ashift 12, ZFS 2.4 for zfs rewrite):

zpool status; zpool get ashift rpool; zfs version

Then follow the twilight steps with these differences:

  • Step 1: use the cache device name exactly as zpool status prints it.
  • Step 2: NVME=/dev/disk/by-id/nvme-INTEL_SSDPEKNW010T9_BTNR03440DTZ1P0B, H=decca03cc77f0eadbbfd278c985, and +128G for the l2c partition.
  • Step 5: the dataset is rpool/local/steam (emergent is still on the legacy layout).
  • Rewrite: run sudo zfs rewrite -rx <mountpoint> for each mountpoint in zfs list -o name,mountpoint, with the same remount for /nix/store.
twilight and emergent keep everything on a single hard drive, with an NVMe that was only a read cache (L2ARC). Every write and every cache miss waited on the hard drive, and twilight's is shingled (ST8000DM004): in one hour of uptime processes spent 17 minutes stalled on IO, with writes regularly waiting seconds. This shows up as hitching in games. ## What changes - **Pool roles**: `storage.zfs.pool` gains `special` and `log` device lists beside `cache`, and a per-device `size`, so one disk can be split between roles. - **Tiering**: a pool with special devices sets `special_small_blocks=128K` on its root dataset, so every dataset lives on the special vdev by default. A dataset opts out to the regular vdevs with `specialSmallBlocks = "0"`. - **twilight and emergent**: the NVMe becomes special vdev + 16G log + read cache (256G on twilight, 128G on emergent). - **Shared Steam library**: `programs.steam.sharedLibrary.enable` adds a dataset mounted at `/games/steam`, owned by a `steam` group holding every user with Steam enabled, group-writable and excluded from snapshots. Proton prefixes are not shared, because Wine refuses to run from a prefix another user owns: inside Steam's sandbox each user's own `~/.local/share/Steam/steamapps/compatdata` is mounted over the library's. - defiant and the other hosts are unchanged. ## Before merging - **The NVMe becomes pool-critical.** Losing it now loses the pool. `zpool remove` can evacuate the special vdev back onto the hard drive later. - **Bulk data needs its own dataset.** New data spills onto the hard drive once the special vdev is about 75% full, so whatever will fill the hard drive should get a dataset with `specialSmallBlocks = "0"` before then. - **Not yet tested on real hardware.** Both hosts build, but the pool commands have not been run, emergent's pool was not inspected (commands are written from its config), and no Proton game has been launched through the new sandbox mount. `sharedLibrary.enable = false` reverts the Steam side. ## Migration: twilight Disks are only partitioned at install time, so the layout this describes has to be made by hand. The pool stays online throughout. `sgdisk` is in the `gptfdisk` package. ```bash # 0. check the hard drive is healthy before leaning on it sudo smartctl -a /dev/sda # 1. take the NVMe out of the pool (it only holds cache copies) sudo zpool remove rpool nvme-nvme.1e4b-323530343533313135323030313437-53504343204d2e32205043496520535344-00000001-part1 # 2. repartition it with the labels the config expects NVME=/dev/disk/by-id/nvme-SPCC_M.2_PCIe_SSD_250453115200147 H=3abe5e8a2b9d578d7f8a133514d sudo zpool labelclear -f ${NVME}-part1 sudo sgdisk --zap-all $NVME sudo sgdisk -n1:0:+16G -c1:disk-$H-log -n2:0:+256G -c2:disk-$H-l2c -n3:0:0 -c3:disk-$H-spc $NVME sudo udevadm settle && ls -l /dev/disk/by-partlabel/ # 3. add it back in its three roles sudo zpool add -o ashift=12 rpool special /dev/disk/by-partlabel/disk-$H-spc sudo zpool add -o ashift=12 rpool log /dev/disk/by-partlabel/disk-$H-log sudo zpool add rpool cache /dev/disk/by-partlabel/disk-$H-l2c # 4. send all new data to the NVMe sudo zfs set special_small_blocks=128K rpool # 5. create the Steam dataset (the rebuild refuses to switch without it) sudo zfs create -o mountpoint=/games/steam -o atime=off -o acltype=posixacl \ -o com.sun:auto-snapshot=false rpool/persist/local/steam # 6. apply the config, then log out and in to pick up the steam group ./rebuild.sh --mode=switch ``` Data written before the change stays on the hard drive until it is rewritten: 1. In Steam, add `/games/steam` under Settings > Storage and move the installed games to it. The move rewrites them onto the NVMe. 2. Rewrite the rest. This reads everything back off the hard drive, so it takes a while: ```bash sudo zfs rewrite -r /persist/local /persist/replicate sudo mount -o remount,rw /nix/store sudo zfs rewrite -r /nix sudo mount -o remount,ro /nix/store ``` Existing snapshots keep the old copies on the hard drive until they expire. `zpool list -v` shows how much sits on each device. ## Migration: emergent Check first that the pool matches what the config says (a single hard drive plus the Intel NVMe as cache, ashift 12, ZFS 2.4 for `zfs rewrite`): ```bash zpool status; zpool get ashift rpool; zfs version ``` Then follow the twilight steps with these differences: - **Step 1**: use the cache device name exactly as `zpool status` prints it. - **Step 2**: `NVME=/dev/disk/by-id/nvme-INTEL_SSDPEKNW010T9_BTNR03440DTZ1P0B`, `H=decca03cc77f0eadbbfd278c985`, and `+128G` for the `l2c` partition. - **Step 5**: the dataset is `rpool/local/steam` (emergent is still on the legacy layout). - **Rewrite**: run `sudo zfs rewrite -rx <mountpoint>` for each mountpoint in `zfs list -o name,mountpoint`, with the same remount for `/nix/store`.
feat: tiered zfs pools and a shared steam library
All checks were successful
build PR #127: checks passed
5276edf7e4
twilight and emergent keep everything on a single hard drive with an nvme
that was only a read cache, so every write and cache miss waited on the
hard drive (seconds at a time on twilight's shingled one).

- storage.zfs.pool gains special and log devices and a per device size,
  so one disk can be split between roles
- a pool with special devices stores every dataset there by default;
  datasets opt out to the vdevs with specialSmallBlocks = "0"
- twilight and emergent use their nvme as special vdev, log and cache
- programs.steam.sharedLibrary adds a group writable dataset at
  /games/steam for every steam user of a machine, with per user proton
  prefixes mounted over the shared ones inside steam's sandbox
All checks were successful
build PR #127: checks passed
Required
This pull request has changes conflicting with the target branch.
  • docs/modules/storage/README.md
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin tiered-storage:tiered-storage
git switch tiered-storage
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jan-leila/nix-config!127
No description provided.