Skip to content

probe: ROOT CAUSE — multi-BRANCH anomaly is ext4 writeback throttle (#146)#151

Merged
WaylandYang merged 1 commit into
mainfrom
probe/118-root-cause-ext4
May 23, 2026
Merged

probe: ROOT CAUSE — multi-BRANCH anomaly is ext4 writeback throttle (#146)#151
WaylandYang merged 1 commit into
mainfrom
probe/118-root-cause-ext4

Conversation

@WaylandYang
Copy link
Copy Markdown
Contributor

Summary

Round 5 of #146. Two findings together identify the root cause.

(a) Hybrid CPU sampling finds ext4 in FC's stacks

Re-ran perf with explicit hybrid event sampling (`-e cpu_core/cycles/P -e cpu_atom/cycles/P`) — fixes the Alder Lake E-core blindness from round 4 (#150). 13 FC samples in a 20 s window with 4 slow BRANCHes:

Category Samples %
FC user-space snapshot code 6 46 %
ext4 write / writeback / block-alloc 6 46 %
KVM 1 8 %

ext4 stacks include:

  • `io_schedule ← wbt_wait ← submit_bio ← ext4_bio_write_folio ← ext4_do_writepages`
  • `down_write ← ext4_da_map_blocks ← ext4_da_write_begin ← vfs_write`
  • `crc32c_x86_3way ← ext4_block_bitmap_csum_set ← ext4_mb_mark_diskspace_used ← ext4_mb_new_blocks`

= ext4 delayed allocation + writeback throttle (`wbt_wait`) + multi-block allocator + block-bitmap checksumming.

(b) tmpfs control: anomaly vanishes

Second daemon, `--snapshot-root /dev/shm/forkd-snapshots`, same 10-BRANCH sweep:

Storage BRANCH 1 (cold) 2 3 4 5 6 7-10
ext4 SSD ~350 ~250 1300 1400 1500 2700 1.5-2.7 s
tmpfs 728 196 138 114 168 138 111-259

Pause stays in the 110-260 ms band for all 10 BRANCHes on tmpfs. No slow regime. 100 % of the anomaly is in the fs layer.

Five-round synthesis

Pass PR Hypothesis Verdict
1 strace -c #128 user-space CPU bottleneck wrong
2 bpftrace + /proc/stack #140 94 % off-CPU + futex waiters side obs
3 futex args.uaddr #143 passive waiters, not contention confirmed
4 perf -a -g (P-only) #150 in-kernel sleep dominates right direction, sampling blind
5 perf hybrid + tmpfs this PR ext4 wbt + mballoc + bitmap CRC ROOT CAUSE

Fix path

`#118`'s original Phase 2/3 scope can finally be re-evaluated against real data. Options in order of leverage:

  1. `fallocate` the memory.bin to full size before FC writes — ext4 stops running mballoc per write range. ~30 LOC Rust in the daemon's BRANCH path. No FC change needed.
  2. `O_DIRECT` writes — bypass page cache + wbt entirely. Upstream FC patch.
  3. `io_uring` async writes — original Phase 2 scope, now with hard evidence behind it.
  4. memfd-backed memory — v0.4 candidate; eliminates the on-disk write for BRANCH chain head entirely.

Recommended first step: fallocate. If pause stays flat → ship as forkd v0.3.4 patch + close #146.

Files

  • `bench/pause-window/probe-perf-hybrid.sh` — the probe that found the ext4 stacks
  • `bench/pause-window/PROBE-multi-branch-anomaly.md` — "ROOT CAUSE FOUND" section, fix path

Closes investigation phase of #146.

🤖 Generated with Claude Code

Round 5 of #146. Two complementary findings:

1. perf with explicit hybrid sampling (-e cpu_core/cycles/P -e
   cpu_atom/cycles/P) — fixes the Alder Lake E-core blindness from
   round 4. Got 13 FC samples in a 20s window with 4 slow BRANCHes,
   46% of which are in ext4 kernel paths:
     io_schedule ← wbt_wait ← submit_bio ← ext4_bio_write_folio
       ← ext4_do_writepages
     down_write ← ext4_da_map_blocks ← ext4_da_write_begin
       ← vfs_write
     crc32c_x86_3way ← ext4_block_bitmap_csum_set
       ← ext4_mb_mark_diskspace_used ← ext4_mb_new_blocks
   = ext4 delayed allocation + writeback throttle (wbt) + multi-block
   allocator + block-bitmap checksumming.

2. tmpfs control — second daemon with --snapshot-root /dev/shm/...
   Ran 10 consecutive diff BRANCHes:
     BRANCH  1 (cold): pause_ms=728
     BRANCH  2-10:     pause_ms 111-259, flat
   No slow regime. Anomaly is 100% filesystem-layer.

Synthesis of all 5 probe rounds:
  Pass 1 strace -c    → user-space CPU             (wrong)
  Pass 2 bpftrace      → 94% off-CPU + futex        (side obs)
  Pass 3 futex args    → passive waiters            (confirmed)
  Pass 4 perf -a -g    → kernel sleep dominates     (right direction, blind)
  Pass 5 perf hybrid + tmpfs → ext4 wbt + mballoc   (ROOT CAUSE)

Fix path is now clear and small:
  1. fallocate memory.bin to full size before FC writes (~30 LOC Rust)
  2. O_DIRECT in FC's snapshot writer (upstream FC PR)
  3. io_uring (Phase 2 original case, now justified)
  4. memfd-backed memory.bin (v0.4)

Recommended first step: fallocate. If pause stays flat → ship as
forkd v0.3.4 + close #146.

Ships:
  - bench/pause-window/probe-perf-hybrid.sh
  - PROBE-multi-branch-anomaly.md "ROOT CAUSE FOUND" section
  - probe-offcpu.sh referenced (already shipped in #150)

Refs #146.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@WaylandYang WaylandYang merged commit 6d08436 into main May 23, 2026
2 checks passed
@WaylandYang WaylandYang deleted the probe/118-root-cause-ext4 branch May 23, 2026 06:13
WaylandYang added a commit that referenced this pull request May 23, 2026
…balloc (#152)

5 rounds of probe (#128, #140, #143, #150, #151) traced the multi-BRANCH
pause_ms anomaly to ext4 delayed allocation + writeback throttle
+ multi-block allocator + block-bitmap CRC compounding per BRANCH.
tmpfs control confirmed: anomaly is 100% in the fs layer.

Fix: posix_fallocate the destination memory.bin to source full size
right after we create snap_dir, before either the diff-mode background
copy OR FC's snapshot/create write. ext4 reserves the extents up-front;
subsequent writes don't run mballoc or update block bitmap.

Best-effort — on tmpfs / unsupported FS the syscall returns ENOSYS, we
log at WARN and continue (no behavior change). On ext4 (the actual
problem case), this should flatten pause_ms across the BRANCH chain.

Adds libc 0.2 as a cfg(unix) dep for posix_fallocate.

Refs #146.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BRANCH 3+ pause_ms jumps 5× on same source (snapshot-worker single-thread loop)

1 participant