From faf4f1c1688ba4a9c0ecdaf5d03c2eb2ae02bf33 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Thu, 19 Nov 2026 13:36:36 -0300 Subject: [PATCH 1/3] machine: rootfstype=ext4 on the command line when a root is named Without it the root mount walks the registered block filesystems, and ext4's init registers ext3 and ext2 (EXT4_USE_FOR_EXT2) ahead of ext4: two refused mounts, each a superblock read after a block size change, before the one that works. The root is the image's ext4, or an overlay of it. Co-Authored-By: Claude Opus 5.5 --- machine/cmdline.go | 11 +++++++++++ machine/machine_test.go | 3 ++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/machine/cmdline.go b/machine/cmdline.go index 70ca5d1..c5cc728 100644 --- a/machine/cmdline.go +++ b/machine/cmdline.go @@ -75,6 +75,17 @@ func (c Cmdline) String() string { mode = "ro" } parts = append(parts, "root="+c.Root, mode) + + // The root is an ext4 (image/build.sh), and saying so is one mount instead of + // three. Without rootfstype the kernel tries every block filesystem in the order + // it registered them (init/do_mounts.c), and ext4's init registers ext3 and, + // with EXT4_USE_FOR_EXT2, ext2 ahead of ext4 itself: the root mount reads the + // superblock as an ext3, is refused for its features, reads it again as an + // ext2, and only then mounts it, each attempt a superblock read over virtio + // after a block size change. A disk handed in with --disk is an overlay of the + // same image, so it is the same filesystem; a root that is not one says so with + // its own rootfstype= in Extra, which comes later and is the one the kernel keeps. + parts = append(parts, "rootfstype=ext4") } // Scan PCI bus 0 and stop. diff --git a/machine/machine_test.go b/machine/machine_test.go index 84355d8..daabd0e 100644 --- a/machine/machine_test.go +++ b/machine/machine_test.go @@ -654,7 +654,8 @@ func TestCmdline(t *testing.T) { }, { name: "root", c: withRoot, - want: []string{"root=/dev/vda rw"}, + // Named, or the root mount tries ext3 and ext2 on the superblock first. + want: []string{"root=/dev/vda rw rootfstype=ext4"}, }, { name: "no console", c: noConsole, From 07e5b56417d95cc21770f32f34cabadb822f1295 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Thu, 19 Nov 2026 13:45:25 -0300 Subject: [PATCH 2/3] image: no orphan_file, inode tables zeroed at build orphan_file costs every mount, read-only included, ~73 sequential single-block reads in ext4_init_orphan_info, each a virtio round trip inside the root mount; it only scales concurrent unlinks of open files. Crash correctness is the classic orphan list's, as before 1.47. lazy_itable_init=0 marks every group ITABLE_ZEROED: mke2fs -d left them all unmarked, and each overlay's first read-write mount had ext4lazyinit write 16 MiB of zeroes into it within the first second of the boot. Measured with one --init /bin/sh boot (laptop): 16.06 MiB of zero clusters in the overlay before, none after. The image is 256 KiB smaller. Both are read back from the finished filesystem: no orphan_file in dumpe2fs's features, and ITABLE_ZEROED on as many groups as the header says there are. Co-Authored-By: Claude Opus 5.5 --- image/build.sh | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/image/build.sh b/image/build.sh index b036776..ad724e3 100755 --- a/image/build.sh +++ b/image/build.sh @@ -177,10 +177,28 @@ done < "$SHARE/packages.txt" # costs the image almost nothing, since mke2fs does not zero it — an empty 974 MiB filesystem # converts to 1540 KiB of qcow2 with it and 1220 KiB without — and an overlay at most 64 MiB, # once the guest has cycled through it (all measured 2026-09-14). +# +# No orphan_file, which mke2fs.conf turns on for ext4 since 1.47.0. Every mount, read-only +# included, loads the orphan file into memory one block at a time (ext4_init_orphan_info, +# fs/ext4/orphan.c in 7.3): about 73 sequential single-block reads with no readahead, each a +# virtio round trip, inside the root mount the whole boot waits for. What the feature buys is +# scale for a filesystem unlinking many open files at once from many CPUs, where the classic +# orphan list in the superblock serialises on one lock; a workspace is not that. Crash +# correctness is the same either way - an inode unlinked while open is recorded in the classic +# list and the journal, and released at the next mount, as on every ext4 before 1.47. +# +# lazy_itable_init=0: the inode tables are zeroed here and every group is marked so +# (ITABLE_ZEROED). Without it - mke2fs -d left every group unmarked - the first read-write mount +# of each overlay set ext4lazyinit to zero every inode table, in the first second of the boot, +# while the machine is reaching its first login: 16.06 MiB of zero clusters in the overlay after +# one boot, and none with the tables zeroed here (`--init /bin/sh`, laptop, 2026-11-19). The +# thread itself still starts, to prefetch block bitmaps, which only reads. Zeros cost the image +# nothing, because qemu-img does not allocate a cluster of them: with both changes it came out +# 256 KiB smaller than the build before it. mkbase() { rm -f /work/base.raw - "$bin/mkfs.ext4" -q -F -L "" -U clear -J size=64 -m 0 -b 4096 -E root_owner=0:0 \ - -d "$tree" /work/base.raw "${1}k" + "$bin/mkfs.ext4" -q -F -L "" -U clear -J size=64 -m 0 -b 4096 -O ^orphan_file \ + -E root_owner=0:0,lazy_itable_init=0 -d "$tree" /work/base.raw "${1}k" } # The size is given in KiB with its unit spelled. A bare number is KiB only until -b is on the # command line, after which mke2fs reads it as a count of blocks: adding -b 4096 made this image @@ -222,6 +240,19 @@ grep -q '^Filesystem features:.* has_journal' <<<"$header" || { echo "ERROR: the grep -q '^Filesystem features:.* needs_recovery' <<<"$header" && { echo "ERROR: the filesystem's journal needs recovery" >&2; exit 1; } grep -q '^Total journal size: *64M$' <<<"$header" || { echo "ERROR: the journal is not 64M: $(grep '^Total journal size' <<<"$header")" >&2; exit 1; } grep -q '^Filesystem state: *clean$' <<<"$header" || { echo "ERROR: the filesystem is not clean" >&2; exit 1; } +# The two choices mkbase makes against mke2fs.conf's defaults, read back: an e2fsprogs bump whose +# mke2fs ignored one would build a filesystem that mounts and boots, only slower. +grep -q '^Filesystem features:.* orphan_file' <<<"$header" && { + echo "ERROR: the filesystem has orphan_file; every mount reads it block by block" >&2; exit 1; } +# Every group, from the group descriptors: dumpe2fs prints one "Group N:" line each, with +# ITABLE_ZEROED among its flags when the mark is there. The count is compared with the header's +# group count rather than only looking for a group without it, so that output dumpe2fs did not +# print, or printed differently, fails rather than passes. +groups=$("$bin/dumpe2fs" /work/base.raw 2>/dev/null | grep '^Group [0-9]*:') +want=$(awk -F: '/^Block count:/ { b = $2 } /^Blocks per group:/ { g = $2 } END { printf "%d\n", (b + g - 1) / g }' <<<"$header") +zeroed=$(grep -c 'ITABLE_ZEROED' <<<"$groups" || true) +test "$want" -gt 0 && test "$zeroed" = "$want" || { + echo "ERROR: $zeroed of $want groups have zeroed inode tables; each overlay would run ext4lazyinit" >&2; exit 1; } # debugfs is asked and its *output* is read, not its exit status: `debugfs -R` exits 0 # whether or not the request succeeded, printing "File not found by ext2_lookup" to stderr From 0b3640519d3258f746530e4217a2902bec8900c5 Mon Sep 17 00:00:00 2001 From: Manuel de Brito Fontes Date: Thu, 19 Nov 2026 13:51:29 -0300 Subject: [PATCH 3/3] docs: the root mount's storage path, and what it measured on a laptop Co-Authored-By: Claude Opus 5.5 --- docs/log.md | 7 +++++++ image/README.md | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/log.md b/docs/log.md index a3ae515..4f8544b 100644 --- a/docs/log.md +++ b/docs/log.md @@ -382,6 +382,13 @@ Masking `modprobe@drm`, which logind is ordered after, added nothing (327/345). - the first dispatch: 0.87. The gap is unit loading, not the transaction that 11-13's single debug-logged boot named. 96 of the units a boot lists are inactive, loaded because another unit names them in `After=`/`Wants=`: `initrd-*`, `plymouth-*`, `modprobe@*`, hibernate, cryptsetup's targets, `firewalld` and `auditd` named by docker. Masking does not spare a load (a masked unit is still looked up and loaded as masked), which is why masking 11 units moved nothing (§4). + +**11-19 · image/machine · the root mount's storage path (branch `ext4-mount`, not yet on the fleet).** The kernel gap `security_initcall_late_sync` → `EXT4-fs (vda): mounted` was 6.8 ms nested and 5.0 metal (`boot:initcalls`). Three changes, from reading Linux 7.3 and the image: +- the image without `orphan_file`, a mke2fs.conf default since 1.47.0: every mount, read-only included, reads it one block at a time (`ext4_init_orphan_info`, ~73 single-block reads with no readahead). Crash correctness is the classic orphan list's; +- `lazy_itable_init=0`: `mke2fs -d` left no group `ITABLE_ZEROED`, so each overlay's first read-write mount had `ext4lazyinit` zero every inode table in the first second of the boot. After one `--init /bin/sh` boot the overlay held 16.06 MiB of zero clusters, and none with the tables zeroed at build. The thread still starts, to prefetch block bitmaps (it does not with `no_prefetch_block_bitmaps`). The image is 256 KiB smaller; +- `rootfstype=ext4`: without it the root mount tries ext3, then ext2 (`EXT4_USE_FOR_EXT2`), on the superblock before ext4. + +Laptop lead only, on a host at load ~30: the gap's p50 over three alternated rounds of `TestKernelInitcalls` (8-10 boots each) was 8.8/2.8/4.3 ms with the release, 4.1/3.2/2.9 with `rootfstype` alone, and under 2.4 (below the rows printed)/1.3/1.2 with all three. Not decided until `boot:ssh-first` and `boot:restore-first` run interleaved on the bench fleet. --- ## 3. Rework cycles diff --git a/image/README.md b/image/README.md index e7b2656..54e5fa0 100644 --- a/image/README.md +++ b/image/README.md @@ -105,8 +105,8 @@ true and useless. It is `spin-machine boot` with no `--disk`: this QEMU and this kernel over `rootfs.qcow2` under a throwaway overlay (QEMU's `-snapshot`), with the serial console on stdio. -It boots with no initrd at all: `root=/dev/vda rw init=/sbin/init`, which the kernel can -serve because virtio-blk and ext4 are built in and `build.sh` writes a partitionless +It boots with no initrd at all: `root=/dev/vda rw rootfstype=ext4 init=/sbin/init`, which the +kernel can serve because virtio-blk and ext4 are built in and `build.sh` writes a partitionless filesystem. There is no debug initramfs: one that mounted the API filesystems, found the root disk and exec'd would be a second init, doing what the init a consumer brings already does. What removes the need for one is `systemd-udevd` being on.