Repository navigation
Description
Problem
A template worker's cold start reads its snapshot's memory file (4 GiB for a 4 GiB guest) from
$SBX_SRV (/srv/sbx). install-host.sh leaves that device at the kernel's default read-ahead of
128 KiB. On a network block volume whose largest request is 128 KiB (max_hw_sectors_kb), that keeps
too few reads in flight to reach the volume's throughput.
Measured on one KVM host with a network block volume rated 750 MiB/s and 3,000 IOPS, page cache
dropped before each run:
| What | read_ahead_kb 128 |
512 | 1024 |
|---|---|---|---|
| One reader of the memory files | 227 MiB/s | 730 MiB/s | ~850 MiB/s |
| Four readers | 435 MiB/s | ~779 MiB/s | |
| 8 cold worker starts posted at once, 4 at a time | all active at 100.7 s | all active at 62.2 s | |
| Their read rate | ~420 MiB/s | 736-742 MiB/s |
The bytes read per start were the same, 4.0 GiB, at both settings. Every read stayed 128 KiB, at
about 5,900-6,900 reads/s at 512 and above (about 5,950 in the cold starts): what binds is reads in
flight, not IOPS. At 512 the starts run at the volume's
limit.
Proposal
install-host.sh sets the read-ahead of the block device holding $SBX_SRV on every worker install,
and keeps it set across reboots:
- A new setting
SBX_READ_AHEAD_KB(default 512).0leaves the device alone (and removes what an
earlier install set up, writing the earlier value back). Anything other than a whole number from 0
to 16384 is refused before the host is touched. - The device is found by path, never by a recorded name (a disk's kernel name can change across
reboots):findmnt'sMAJ:MINfor$SBX_SRV, then/sys/dev/block/MAJ:MIN. A disk, dm/LVM, md or
loop device is set through its ownqueue/read_ahead_kb; a partition through its parent disk's. - A sysfs write does not survive a reboot, so the install adds a small script
(/usr/local/libexec/sbx-read-ahead.sh, which does the lookup above at every run) and a oneshot
sbx-read-ahead.service(RequiresMountsFor=$SBX_SRV,Before=sbx.slice,
WantedBy=multi-user.target; the worker template gainsAfter=sbx-read-ahead.service), enables it
and runs the script once. - The device's value before the first install is kept in
/etc/sbx/read-ahead.orig(a re-run keeps
the first one). The last worker's--uninstallwrites it back, then disables and removes the unit,
the script and that file. All three are recorded in/etc/sbx/manifestunder their own kind. - Never a failed install: a
$SBX_SRVon no block device (tmpfs, overlay, btrfs's anonymous device), a
device without a queue, a host withoutfindmnt, or a value the device does not take (re-read after
the write) is a warning; the old value stays. The boot run exits 0 in those cases too, with the
warning in its journal.
What the PR will contain
One PR, about 315 added lines with tests.
deploy/sbx/sbx-read-ahead.sh(new):resolve PATHandset PATH KB, withSBX_SYSFSas a test
seam.deploy/sbx/install-host.sh: the setting and its check, the install after the shared units and
before the worker starts, the restore and removal with the last worker (and with
SBX_READ_AHEAD_KB=0).deploy/sbx/[email protected]:After=sbx-read-ahead.service.deploy/sbx/tests/install-host.test.sh(bash 5 and 3.2), with a mockedfindmntand a fake sysfs:
a bad value is refused before systemd; the default 512 goes into the unit and onto a partition's
parent disk; a dm device is set through its own queue; a re-run keeps the first recorded value; the
last uninstall restores it and removes the unit;0installs no unit; an unresolvable path and a
refused value warn and the install succeeds.deploy/sbx/README.md(the setting) and a RUNBOOK section: why, the figures above with their
conditions, how to check it, how to turn it off.
Depends on
Nothing.
How to verify
bash deploy/sbx/tests/install-host.test.sh- On a KVM host, after a worker install:
systemctl is-enabled sbx-read-ahead.service, and
cat /sys/block/<dev>/queue/read_ahead_kbfor the devicefindmnt -no SOURCE --target /srv/sbx
names (its disk, for a partition) reads 512, also after a reboot. - After the last
--uninstall: the value is the one in effect before the first install, and
sbx-read-ahead.serviceis gone.
Limits / out of scope
- It is device-wide: everything else on that volume (another Moca tier, other sandboxes, the host's
own files if$SBX_SRVis on the root disk) reads ahead as much. - 512 suits a throughput-bound network volume; local NVMe may want less. The setting is the knob; no
value is chosen per device. - It changes the size of the reads, not the bytes a cold start reads.
- A value set by hand on the device after the install is overwritten at the next boot, and the last
uninstall restores the value recorded at the first install, not that hand-set one.
Assisted-By: Claude Code
Activity
feat(sbx): install-host.sh sets the snapshot device's read-ahead (SBX…
fix(sbx): removing read-ahead stops its unit, then reloads systemd
feat(sbx): install-host.sh sets the snapshot device's read-ahead (SBX…