Why a client's btrfs workstation stalled under load, and what the XFS move fixed
Made Right Software builds MVPs and custom software for founders and small business owners, and audits or rescues code that already exists. Fixed price. Delivered in 4 to 10 weeks.
Situation
A client got in touch about a laptop that was fine when it was idle and unusable under load. Builds that should have taken a minute took five. Saving a file could hang for half a minute. They had already replaced the drive and blamed the CPU.
Their machine is a 16-inch ThinkPad with 20 threads, 62 GiB of memory and two 2 TB NVMe drives. Fedora ran on btrfs inside LUKS on the first drive, with 26 subvolumes, zstd compression, an 80 GiB swapfile and a zram device capped at 24 GiB, while the second drive sat there doing nothing. That first disk was 1.51 TiB full out of 1.82 TiB. Of that, 352 GiB was metadata the DUP profile stores twice.
Three weeks of sar history were already on the box, which meant we could measure before changing anything. The measurement was odd. Over a boot that had been up 9.3 days, btrfs had recorded 41,768 transaction commits that held the commit thread for 142,612 seconds between them, which is 17.7 percent of uptime spent committing. The average commit ran 3.4 seconds. The worst one ran for 299.
Then came the Friday afternoon when it fell apart. Over one window, 342 commits took 9,260 seconds, four fifths of wall clock, at 25 to 43 seconds apiece.
One drive was carrying all of that. Its daily mean await sat between 1.5 and 17.8 ms across three weeks. Ten-minute windows reached 45 ms. It ran at 71 °C while the idle drive sat at 39 °C. The firmware had logged 559 thermal throttle events on it. Swap made the picture worse. zram peaked at 22.4 GiB of its 24 GiB cap. The overflow went into a swapfile on the same btrfs. On 6 November that swapfile averaged 24 MB/s in and 35 MB/s out all day. The kernel logged 25 global out-of-memory kills on 11 and 12 November with swap only 49 percent full.
The client had chosen btrfs for reasons that still hold up. Copy-on-write snapshots turned a 30-minute worktree copy into a sub-second one. Compression saved space they needed. The bill came in the commit thread, at 25 seconds a time.
Task
The ask was narrow. They wanted the machine usable under load and every byte kept. A day rebuilding an environment with years of small fixes in it was not on the table.
Two things made that awkward. The machine is the one their work happens on, which left one box and a deadline. The plan also had to survive a botched boot. The way back was the untouched disk.
That left one question for the diagnosis. Of encryption in the IO path, the IO scheduler or the filesystem, which one was taking the time?
Action
We ruled out the easy suspects first. Encryption was not the bottleneck, since AES-XTS ran at 5.6 GiB/s per core where real disk traffic was 100 MB/s. The scheduler was already none. Both drives sat at PCIe 16 GT/s x4. ionice did nothing here either, because there is no scheduler queue left to prioritize.
That left btrfs, specifically the commit thread, the only thing in the stack holding a lock for 25 seconds at a time.
Sizing the copy turned out to be part of the diagnosis. btrfs filesystem usage counted 843 GiB of data and 352 GiB of metadata inside 1.51 TiB of a 1.82 TiB device. A compsize scan to find the uncompressed total managed 3 MB/s while the drive was busy. It took hours and pushed IO pressure to 38 percent on its own.
There is no in-place conversion from btrfs to XFS. The plan was a live copy to the idle drive and a one-shot boot entry to test it. We built a single XFS filesystem with LVM left out, because XFS cannot shrink and a pooled layout would have been permanent. LUKS came out at the client’s request, which removed a partition layer, the crypttab entry and the kernel parameters that go with it.
The copy ran from a read-only mount of the btrfs top level with rsync -aHAXS --numeric-ids, at about 170 GB an hour. It was not smooth. An 85 percent watchdog stopped it three times. We diagnosed the first two stops wrongly before the pattern showed up. One stop came from 578 GB of working trees under a finished merge run. Another came from /tmp, which had grown to 703 GB on the new disk where it had been 85 GB before, mostly self-nesting installer trees that threw 425,556 copy errors. Btrfs had been storing both for free, because copy-on-write shares every unchanged block. /tmp came out of the copy.
The boot work came next. That meant a new fstab, an empty crypttab, tmp.mount masked, an initramfs rebuilt for three kernels and a fresh GRUB configuration, plus an 80 GiB swapfile standing in until swap moves.
The parts that bit us were small and obvious in hindsight. The drive names swapped at the reboot. Every mount and boot parameter had to name a UUID. We had to resume the partial copy from where it stopped, which only works with the same rsync flags in the same order. The reboot itself was not ours to run, because it ends every session on the machine.
That is what the one-shot EFI entry is for. efibootmgr -n boots the new entry once. If that boot fails, the machine comes up on the old disk instead. The last catch-up pass took 4 minutes 18 seconds, moved 3.7 GB and made 161 deletions with no errors. The machine was down for about seven and a half minutes, reboot included.
Result
The commit thread is gone, because XFS has no equivalent of it. The readings after the move agree. Under a write burst the root drive showed r_await of 0.09 ms at 1.6 percent utilization. Load settled at 6 on 20 threads. The CPU time left over was short-lived work instead of blocked IO.
Swap read zero bytes out of 143 GiB available, where the old machine had been pushing 24 MB/s through it every day. SELinux came up enforcing. Docker, Syncthing and mail all started on the first boot.
The copy path is where the change shows up in daily work. This is the operation the tooling runs on every hunt, on a 27 GB tree of 620,919 files.
| Operation | XFS with reflink | Old btrfs fallback |
|---|---|---|
| copy | 19.6 s to 75.2 s | over 30 minutes |
| remove | 10.8 s to 79.6 s | about 38 minutes |
Three runs each, at a load average of 7 to 16. The old figures come from the tooling’s own log during a run at much higher load. Treat the gap as directional. df does not move after two copies, which is how we know the extents stay shared and the copies are real reflinks. btrfs subvolume snapshot fails on XFS in zero seconds. That is how the tooling now decides to fall back.
Space went the other way. The new disk holds 873 GB at 47 percent of 1.8 TB. Btrfs was holding 1.51 TiB of 1.82 TiB. Compression was not buying what that gap suggests. 1.3 TB of it was merge worktrees and /tmp that btrfs had been sharing between copies. Nobody had priced them until the copy did.
The trade has costs we can name. XFS checksums metadata only. A bitrot scrub is off the table. Instant rollback from snapshots is gone. The 18 cached build trees that depended on it had to be rebuilt. Hibernation stays off until swap moves to the second drive. Until then the old disk is the only other copy of the data.
One part of this is inference. The commit work was btrfs-specific, but the drive it ran on was throttling too. We cannot separate how much of the old slowness came from the filesystem and how much from the hardware. What we can measure is the after state. It is quiet.
Lessons Learned
- A snapshot costs almost nothing because the filesystem defers the work. The bill arrives later, as commit stalls under load. Theirs came to 17.7 percent of uptime.
- Copy-on-write hides how much junk you keep. Two finished merge runs and a
/tmpdirectory looked free until a filesystem without sharing had to store them. The copy needed three attempts to find them. - Rule out the easy suspects before you touch the disk. Encryption and the scheduler were both innocent. Either could have absorbed weeks of tuning.
- One disk carrying the system, swap, containers and build output turns every workload into one queue. The idle drive ran 32 degrees cooler and never throttled.
- A reflink copy recovers most of what you lose when snapshots go, at 20 to 75 seconds for a tree of 620,000 files. Know which of the two your tooling depends on before you remove either.
- Plan the fallback before the copy starts. A one-shot EFI entry, a disk you never touched and a seven-minute window turn a failed migration into one more reboot.
If your workstation behaves like this one did, slow saves and stalls that arrive in bursts, we can measure it before anything moves. https://cal.com/maderightsoftware