Skip to content

Put read_path_at / read_path_whole StrBufs in regions (main's strbuf gate) - #409

Merged
284km merged 1 commit into
mainfrom
fix-read-path-strbuf-region
Nov 30, 2026
Merged

284km merged 1 commit into
mainfrom
fix-read-path-strbuf-region

Conversation

@284km

@284km 284km commented Nov 30, 2026

Copy link
Copy Markdown
Owner

The failure

Since #373 merged, main's build-linux and corpus jobs stop at the source gate, and run_corpus.sh stops there locally before running any program:

strbuf region: a StrBuf outside every region block is the default region's, which nothing gives back:
  mr.c: mu_read_path_at makes a StrBuf in the default region
  mr.c: mu_read_path_whole makes a StrBuf in the default region

(the source half of the check names m_state.mere:4832 (read_path_whole) and m_state.mere:4855 (read_path_at)).

Cause

#373 added read_path_whole and read_path_at in m_state.mere, each building its result in a StrBuf made outside every region block. It was branched before #393 added tools/strbuf_region_check.py, so each PR passed on its own and main failed once both were in.

The change

Each function's read loop now runs in a region of its own, following #393's pattern (READ_PATH_WHOLE_B, READ_PATH_AT_B); the region hands out only the text. Nothing is added to ALLOWED.

  • The open, the seek and their error answers stay outside the region and are unchanged: read_path_at still answers (errno or 13, "") when the open fails and (-1, "") when the seek is refused, after closing the descriptor; read_path_whole still falls back to read_file when the open fails.
  • The read loop and fd_close run inside the region in the same order as before; the emitted C copies the string out of the region before it is released. read_path_at's pair is made outside the region from the copied text.
  • tcp_arena's first call may now happen inside a region; map_set copies the stored value into the map's own region, so the scratch pointer outlives the block.

Local results (macOS arm64, Mere at the CI MERE_REF 9dec2ff6, tools/build.sh -O2)

  • python3 tools/strbuf_region_check.py: passes, with the mr.c half ("mr.c: 3 functions with one in the default region, all allowed").
  • sh run_corpus.sh --both: 1039/1039 corpus programs match ruby, with the hash index ON and OFF (all source gates included).
  • sh tools/iseq/vm_corpus.sh -j 3: 1039 programs, 1039 on the VM, 0 fell back, 0 FAIL.
  • corpus 838 (paths without a size are read to their end): identical to ruby 4.0.10 on the evaluator and the VM, each also with MERE_RUBY_GC_STRESS=20.
  • Error paths (File.read with a length on an unreadable file, a missing file, a length of 0, an offset past the end, /dev/urandom with offset 2**40, /dev/zero, a pipe through /dev/fd/N with and without a length and with an offset (ESPIPE)): identical to ruby on both engines and to main's build.
  • RSS (KB) after a warm-up and then after each of four more rounds, each round followed by GC.start:
loop main 5b815b6 this branch
File.read(path, 4, 0) 50,000 a round 75296 → 78768 → 81408 → 83632 → 86064 75152 → 76256 → 76528 → 76496 → 76544
File.read("/dev/urandom", 16) 50,000 a round 75552 → 78672 → 81248 → 83472 → 85968 75360 → 76304 → 76592 → 76464 → 76608
File.read("/dev/urandom", 1 << 20) 50 a round 79264 → 158752 → 210592 → 261888 → 313104 77168 → 106800 → 106816 → 106944 → 106960
60 KB pipe via File.read("/dev/fd/N") 500 a round 78576 → 132224 → 165136 → 198416 → 231856 77152 → 98784 → 99488 → 100624 → 102048

The pipe row still rises by about 1 MB a round on this branch, but the same loop without File.read (IO.pipe, w.write, r.read) rises the same way on both builds (90016 → 93872 on main, 89952 → 94048 here), so that growth is not in these two functions.

🤖 Generated with Claude Code

#373 added read_path_whole and read_path_at, each building its result in a
StrBuf made outside every region block. It was branched before #393 added
tools/strbuf_region_check.py, so after both merged the gate failed on main
(build-linux, corpus, and run_corpus.sh locally):

  m_state.mere:4832 (read_path_whole)
  m_state.mere:4855 (read_path_at)

Each read loop now runs in a region of its own (READ_PATH_WHOLE_B,
READ_PATH_AT_B), which hands out only the text. The open, the seek and
their error answers stay outside the region and are unchanged, and the
descriptor is closed inside it as before. A File.read of 1 MiB from
/dev/urandom, or of a pipe through /dev/fd/N, no longer keeps a buffer of
that size for the rest of the run.
@284km
284km merged commit 9d1c0f3 into main Nov 30, 2026
11 of 20 checks passed

@284km 284km left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post-merge review of exact head e78e9658668673379d9e1ad5d9d7f4478a0e3b0a against the base fetched at review start 5b815b660e9ea2ca28382da1ab15efa1db9c1a70: no actionable findings. The PR was merged externally during validation; resulting main 9d1c0f32cad65ca8df45da2466beb27dcd35e015 has the exact tested head tree (fb2fed33). I did not initiate the merge.

The region boundaries preserve the existing open/seek/close/error order. Generated C copies each returned string into the enclosing region before releasing the temporary region, and constructs the bounded-read pair afterward. I also checked that the shared tcp_arena backing storage survives and that its cached boxed offset is copied into the map's region.

Independent validation on Darwin arm64:

  • Fresh ordinary O2 builds of base and head, using a freshly built pinned compiler 9dec2ff687a08433247dbdb7729bc19c8522e538 and mgz 661a01d8; clean reference Ruby 4.0.10 selected through tools/ref_ruby.sh.
  • Corpus 838 plus an additional probe for chunk boundaries, retained binary strings after repeated reads/GC, devices, empty/missing/unreadable paths, and pipe reads/refused seeks: all 32 exit/stdout/stderr comparisons match Ruby across both trees, evaluator/strict VM, Hash index ON/OFF, and normal GC/GC20.
  • StrBuf source and emitted-C gate passes on head; base reproduces both recorded helper violations. GC roots, dead/duplicate definitions, name lengths, method writes, record hygiene, bracket depth, and diff checks pass.
  • Separate 1-round / 5-round processes measured with /usr/bin/time -l, maximum RSS in KiB:
Workload per round Base, 1 / 5 rounds Head, 1 / 5 rounds
50 reads of 1 MiB from /dev/urandom 164576 / 370256 124000 / 124416
500 reads of 60 KB pipes 136448 / 275248 109664 / 137520

All eight resource runs returned the expected bytes/sizes. Pipe growth remains; these local measurements do not establish elimination of every memory issue or Linux resource acceptance. RSS measurement required an approved sandbox exception because the sandbox blocked time's sysctl; that restriction was not a runtime failure.

The previous main CI's 25 jobs were inspected: 22 succeeded, two failed at this StrBuf gate, one was skipped. Post-merge main CI 46342657606 remains incomplete: the harness and plan passed, Linux is running, and macOS/reference jobs are queued, with downstream coverage unfinished. The original PR core run was cancelled after the merge. I did not rerun the full corpus or whole upstream suites, and do not claim hosted acceptance or clearance of the recorded merge holds. Other open PRs are drafts; no further merge was attempted.

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.

1 participant