Skip to content

chore: concurrency scenarios testing - #970

Open
citizen-stig wants to merge 9 commits into
thrumdev:masterfrom
citizen-stig:nikolai/concurrency-scenarios
Open

citizen-stig wants to merge 9 commits into
thrumdev:masterfrom
citizen-stig:nikolai/concurrency-scenarios

Conversation

@citizen-stig

@citizen-stig citizen-stig commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Small multi-threaded scenarios for the session/commit/rollback/overlay paths, runnable natively, under shuttle (controlled scheduling, PCT/random, replayable schedules, deadlock detection) and under FFS. They found three deadlocks on master, fixed in #971.

What's added

nomt/tests/concurrency_scenarios.rs: 7 scenarios, all #[ignore]d natively so cargo test is unchanged. A native run is wrapped in a 60 s deadline so a deadlock fails instead of hanging; CS_NO_DEADLINE=1 leaves hang detection to the explorer. Under --cfg shuttle each scenario runs in shuttle::Runner (SHUTTLE_ITERS, SHUTTLE_SCHED=pct|random).

scenario checks
witness_concurrent_workers witness ops point at the right path proof with 4 commit workers
rollback_three_sessions three live sessions with rollback; the newest can finish
warm_up_two_sessions two live sessions with warm-up and one commit worker
overlay_commit_vs_child_session committing an overlay while another thread opens a session on its child
commit_vs_readers readers see whole commits (no torn snapshots), proofs verify against the session root
rollback_vs_readers same while rollback(1) runs
nested_session_vs_commit a thread holding a session opens another while a commit is queued

Hooks in nomt (no effect unless the cfg is set):

  • cfg(nomt_sync_io) selects the existing blocking pread/pwrite I/O backend (io/unix.rs) on Linux, so I/O completions are thread events an explorer can order instead of kernel-side io_uring state.
  • cfg(shuttle) spawns the fsyncer threads through shuttle, and makes the page pool bypass its thread-local freelist. All shuttle threads share one OS thread, and the freelist RefCell is borrowed across the global freelist lock, which is a scheduling point under shuttle.
  • shuttle as a cfg(shuttle) target dependency. Cargo.lock grows by shuttle's dependencies; no existing pin changes.

shuttle-shims/ (excluded from the workspace): shuttle-backed stand-ins for crossbeam-channel, parking_lot and threadpool, covering only the API NOMT uses. run.sh patches them in with cargo --config 'patch.crates-io...', so NOMT's dependency list stays untouched, then restores Cargo.lock.

  • crossbeam-channel: bounded/unbounded/rendezvous channels, Select::{recv, ready}, and select! with recv arms only. Which ready channel is chosen comes from shuttle's RNG, so that choice is explored too.
  • parking_lot: locks from shuttle-parking_lot-impl (with arc_lock/send_guard), plus a Condvar it lacks.
  • threadpool: workers are shuttle threads that exit when the last pool handle drops, so every iteration ends cleanly.

Results on master before #971

scenario native (300 runs) shuttle FFS
rollback_three_sessions hangs every time deadlock —
warm_up_two_sessions hangs every time deadlock —
nested_session_vs_commit 0/300 fail deadlock (PCT, within 5000 iterations; random did not find it in 5000) —
commit_vs_readers 0/300 fail deadlock (same lock cycle, via Nomt::read) deadlock on ~50% of schedules
others pass pass, 300 PCT + 300 random pass

All three are fixed in #971, now merged. This branch makes task::spawn_thread_task (added by #971) spawn through shuttle like the fsyncer does, and makes the per-thread live-session counter #971 added use shuttle's thread_local!, because all shuttle threads share one OS thread. The shuttle results above were not re-run after merging master.

Running

shuttle-shims/run.sh                      # all scenarios, PCT, 100 iterations each
SHUTTLE_ITERS=5000 shuttle-shims/run.sh nested_session_vs_commit
SHUTTLE_CAPTURE_BACKTRACE=1 shuttle-shims/run.sh <name>   # per-task backtraces on deadlock
cargo test -p nomt --release --test concurrency_scenarios -- --ignored

FFS needs no build changes; see shuttle-shims/README.md for the command.

Limitations

  • Shuttle only switches threads at operations it controls. std atomics (e.g. the overlay status) aren't swapped, so interleavings around them aren't explored. Neither shuttle nor FFS models weak memory; that is still loom's job (rw_pass_cell).
  • FFS found the commit_vs_readers deadlock but could not replay any NOMT failure from its saved schedule, even with nomt_sync_io. Confirm FFS findings under shuttle.
  • Neither shuttle nor the scenarios run in CI.
  • The parking_lot shim is versioned 0.12.3. With a lockfile at parking_lot 0.12.5 (as after Remove redundant dependencies and use crossbeam-channel directly #962) cargo skips the patch ("patch ... was not used in the crate graph"), the real Condvar blocks a shuttle thread, and run.sh hangs. The shim version must match the locked parking_lot.

Testing

  • cargo test -p nomt --release passes with the hooks (the scenarios are ignored).
  • shuttle-shims/run.sh builds and runs from a clean checkout. Results are in the table above.

@citizen-stig
citizen-stig marked this pull request as ready for review November 2, 2026 11:17
@citizen-stig
citizen-stig force-pushed the nikolai/concurrency-scenarios branch from 625dffc to 0a81303 Compare November 23, 2026 08:23
citizen-stig and others added 8 commits November 25, 2026 09:13
Small multi-threaded scenarios in nomt/tests/concurrency_scenarios.rs, meant
to run one at a time under FFS or shuttle (they are #[ignore]d natively):
witness assembly with concurrent workers, coexisting sessions with rollback
and with warm-up, overlay commit vs a child session, commit vs readers,
rollback vs readers, and nested sessions vs a commit. Three of them
deadlock on master.

Hooks for the explorers:
- cfg(nomt_sync_io) selects the blocking pread/pwrite I/O backend on
  Linux, so I/O completions are ordinary thread events rather than
  kernel-side io_uring state.
- cfg(shuttle) spawns fsyncer threads through shuttle and bypasses the
  page pool's thread-local freelist, which would otherwise stay borrowed
  across a scheduling point (all shuttle threads share one OS thread).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
shuttle-shims/ holds shuttle-backed stand-ins for the three crates, covering
only the API NOMT uses (channels incl. Select/select!, parking_lot locks plus
a Condvar, which shuttle-parking_lot lacks, and a thread pool whose workers
exit when the pool is dropped). run.sh patches them in with
`cargo --config patch.crates-io...` and runs the concurrency scenarios under
shuttle, restoring Cargo.lock afterwards. The directory is excluded from the
workspace.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
benchtop locks nomt's dependencies separately, so it needs the shuttle
target dependency too. shuttle requires rand >= 0.8.6 and, through
corosensei, libc >= 0.2.159; libc is pinned to 0.2.186 to match the
workspace lock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Under cfg(shuttle) the THREAD_SESSIONS counter must be per shuttle thread and
spawn_thread_task must spawn shuttle threads. Previously carried by the merge
of master; restored after rebasing onto master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Master's Cargo.lock pins parking_lot 0.12.5; with the shim at 0.12.3 cargo
ignores the patch and the scenarios run on real parking_lot, which blocks
shuttle's single OS thread.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
NOMT's session access lock takes recursive reads (read_recursive,
read_arc_recursive), and shuttle-parking_lot-impl's RawRwLock does not
implement RawRwLockRecursive, so the shuttle build did not compile.

Define the RwLock in the shim on a strictly fair BatchSemaphore: new
readers queue behind a waiting writer, as in parking_lot, and a recursive
read overtakes the queue through `upgrade`. Also drop Condvar API NOMT
does not use.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
witness_concurrent_workers created a fresh test/cs_witness_N directory on
every shuttle iteration and never removed it (about 16 MB each). Keep it
in a temp dir instead. Also fix stale docs: the witness fix is on master
as e07687d, and the shims live in shuttle-shims/.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Drop shim API NOMT does not use, and the channel shim's rendezvous
  path: bounded(0) only makes a placeholder sender. Wake selectors only
  when a message arrives or the last sender leaves.
- Fold nomt_sync_io into cfg(shuttle), which is the only build using it.
- Share one ThreadBuilder alias between task.rs and fsyncer.rs.
- Use cfg!(shuttle) in the page pool instead of a cfg block plus
  allow(unreachable_code).
- Move shuttle into workspace dependencies; simplify run.sh and its
  .gitignore.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@citizen-stig
citizen-stig force-pushed the nikolai/concurrency-scenarios branch from 0a81303 to 46c344e Compare November 25, 2026 08:31
- Add a thread_local shim keyed by shuttle task, so the page pool runs
  its real thread-local freelist under shuttle instead of bypassing it.
  page_pool.rs is back to master's version.
- Collect the swaps that can't be patched (std's thread builder and
  thread_local!) in nomt/src/rt.rs; task.rs, fsyncer.rs and lib.rs
  import from it and carry no cfgs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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