Repository navigation
Loader: add O(1) envelope fast-reject, packed RangeEntry lookup, and synchronized registration in modules - #2673
Conversation
…synchronized registration in modules Replace split RANGE_BASE/RANGE_SIZE/RANGE_COUNT arrays with a packed RangeTable maintaining a monotonic [min_addr, max_inclusive] envelope for O(1) lock-free fast-reject of out-of-range callers (e.g. PC D3D12/driver addresses), synchronize RangeTable insert/remove under MAPPED.write() so unregister_mapped cannot leave zombie slots, warn once outside the lock on MAX_RANGES saturation, and make MappedModule::contains and RangeTable lookup overflow-safe against high base + size wraparound. Part of xcl-dev#1833 Assisted-by: Google Antigravity (Gemini 4 Neon)
luckyteagirl
left a comment
There was a problem hiding this comment.
Could the concurrency test drive overlapping registration and unregistration of the same base? Its writers own disjoint addresses, and each completes register_mapped before its own unregister_mapped, so it cannot exercise the split publication race this patch fixes. On main, a registration can publish RANGE_BASE, a concurrent same-base unregister can clear it before MAPPED.push, and registration can then leave find_mapped_by_base populated while image_base_for_addr returns None. A controlled same-base interleaving with an assertion that both lookups agree after the threads finish would catch that regression. Source-based review at exact head 8660a4593d51dfbf26abf9a41580d3e896ef1bb2; no runtime race test was run. AI-assisted review with Codex.
|
Tested on the Linux/Wine lane, full standard env (AMD rig: Ryzen 9 9900X, 96 GB DDR5, RX 7900 XT 20 GB, Arch kernel 7.2.15, Mesa 26.2.5 RADV, wine-11.0 Proton, rustc 1.94.0; |
|
Test report: passes on NVIDIA. Exact head Tested
Not tested
Claude Code (Claude Opus 5.5) ran the tests and wrote this report. |
… registration in modules (port upstream xcl-dev#2673) Shared modules.rs (lock-free fault/lookup path): MappedModule::contains no longer wraps for images near the top of the address space (checked_sub/is_some_and); the range table gains min_addr/max_inclusive envelope fast-reject (O(1) miss) and packed RangeEntry { base, size } with base-then-size store order published by count (Release); register_mapped inserts under the MAPPED write lock so a concurrent unregister_mapped cannot leave zombie ranges, remove clears by base. Upstream tests verbatim (overflow/envelope boundaries, concurrent register/unregister). Linux-only adaptation: image_range_for_addr (no upstream counterpart, crash-time lock-free (base, size) lookup) now reads through a RangeTable::lookup_range that shares the ported lookup loop, so lookup stays the verbatim base-only path. Failing-first: the overflow test FAILED on the old wrapping contains, green after.
Pack the lock-free module ranges into a single table with a monotonic address envelope, making the common PC/driver-address rejection O(1). Publish registration and removal under the mapped-module write lock and make all containment arithmetic overflow-safe. A controlled same-base test holds registration between range publication and vector publication and proves unregister cannot create a zombie entry. The upstream release microbenchmark reported a 19-23x improvement for out-of-envelope probes against 32 modules. GNU Windows-target cargo check passed here; Windows/MSVC and runtime tests were not run on this host. Adapted from PR xcl-dev#2673. Assisted-by: Google Antigravity (Gemini 4 Neon) Assisted-by: Codex (GPT-5.6-sol)
Pack the lock-free module ranges into a single table with a monotonic address envelope, making the common PC/driver-address rejection O(1). Publish registration and removal under the mapped-module write lock and make all containment arithmetic overflow-safe. A controlled same-base test holds registration between range publication and vector publication and proves unregister cannot create a zombie entry. The upstream release microbenchmark reported a 19-23x improvement for out-of-envelope probes against 32 modules. GNU Windows-target cargo check passed here; Windows/MSVC and runtime tests were not run on this host. Adapted from PR xcl-dev#2673. Assisted-by: Google Antigravity (Gemini 4 Neon) Assisted-by: Codex (GPT-5.6-sol)
Pack the lock-free module ranges into a single table with a monotonic address envelope, making the common PC/driver-address rejection O(1). Publish registration and removal under the mapped-module write lock and make all containment arithmetic overflow-safe. A controlled same-base test holds registration between range publication and vector publication and proves unregister cannot create a zombie entry. The upstream release microbenchmark reported a 19-23x improvement for out-of-envelope probes against 32 modules. GNU Windows-target cargo check passed here; Windows/MSVC and runtime tests were not run on this host. Adapted from PR xcl-dev#2673. Assisted-by: Google Antigravity (Gemini 4 Neon) Assisted-by: Codex (GPT-5.6-sol)
Pack the lock-free module ranges into a single table with a monotonic address envelope, making the common PC/driver-address rejection O(1). Publish registration and removal under the mapped-module write lock and make all containment arithmetic overflow-safe. A controlled same-base test holds registration between range publication and vector publication and proves unregister cannot create a zombie entry. The upstream release microbenchmark reported a 19-23x improvement for out-of-envelope probes against 32 modules. GNU Windows-target cargo check passed here; Windows/MSVC and runtime tests were not run on this host. Adapted from PR xcl-dev#2673. Assisted-by: Google Antigravity (Gemini 4 Neon) Assisted-by: Codex (GPT-5.6-sol) Assisted-by: Codex (GPT-5.6-sol)
What is in it
Improves lock-free module address lookup performance, fixes high-address overflow bugs, and eliminates a registration/unregistration race in
crates/xcl/src/modules.rs:RangeEntrytable (RangeTable): Replaced splitRANGE_BASE/RANGE_SIZE/RANGE_COUNTstatics with a self-containedRangeTablepacking#[repr(C)] struct RangeEntry { base: AtomicUsize, size: AtomicUsize }per slot and maintaining a monotonic[min_addr, max_inclusive]envelope. Out-of-envelope probes (such as PC D3D12/driver callers in0x7ff...during guarded COM calls or VEH dispatch) reject in O(1) without scanning all registered slots, and in-envelope scans only loadsizewhenb != 0 && addr >= b.register_mappedandunregister_mappednow mutateRANGESstrictly while holdingMAPPED.write(), preventing concurrentunregister_mappedcalls from missing an in-flightregister_mappedslot and leaving zombie entries. WhenMAX_RANGES(512) is reached,RangeTable::insertclampscountand signals a one-timexlog_warn!logged strictly after droppingMAPPED.write().addr < self.base + self.sizeinMappedModule::containswithaddr.checked_sub(self.base).is_some_and(|off| off < self.size), and replacedaddr < b + sinRangeTable::lookupwithaddr - b < s(afteraddr >= b) andbase.saturating_add(size - 1)formax_inclusive, avoiding debug overflow panics and release wraparound nearusize::MAX.describe_address,MAIN, and existing tests untouched.Part of #1833
Tested
origin/main(b49be183,cargo test -p xcl --lib "modules::tests::" -- --test-threads=1 --nocapture):2 passed; 1 failed; 0 ignored—contains_handles_base_plus_size_overflowpanicked atmodules.rs:34:37(attempt to add with overflow).XCL_ADAPTER=warp,XCL_WARP=1,cargo test -p xcl --lib "modules::tests::" -- --test-threads=1 --nocapture):4 passed; 0 failed; 0 ignored; 0 skipped(0.00s, zero compiler warnings inmodules.rs).XCL_ADAPTER=warp,XCL_WARP=1,cargo test --release -p xcl --lib "modules::tests::" -- --test-threads=1 --nocapture):4 passed; 0 failed; 0 ignored; 0 skipped(0.00s).0x7FF9_1234_5678lookups against 32 registered modules on an isolatedRangeTable):14.11 ns->0.73 ns(19.3xfaster, WARP run) /16.02 ns->0.71 ns(22.6xfaster, RTX run).cargo clippy --all-targets):0new warnings incrates/xcl/src/modules.rs(only 1 pre-existingunusual_byte_groupingslint on untouched test literal0x1000_0000_4).cargo test --release -p xcl --lib "modules::tests::" -- --test-threads=1 --nocapture):4 passed; 0 failed; 0 ignored; 0 skipped(0.01s).Regression run
Full release workspace on RTX 4060 (
cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture):37test binaries,1437 passed; 0 failed; 47 ignored,29pre-existing environment-gatedSKIPPEDlines:21skipped:no wave64(RTX 4060 is wave32)3skipped: wave32per-lane form: refusedby driver (f16 arithmetic,f16 packed,f32 conversions)3skipped: no D3D12 debug layer (d3d12SDKLayers.dllunavailable on host: debug-layerdred: false/trueanduploads_start_from_each_subresources_state)1skipped:pso_measurement_compiles_an_exact_synthetic_record(cannot disable driver cache on Windows)1skipped:heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows)Paired 60 s RTX 4060 smoke capture (
scripts/smoke.ps1):Base (
origin/mainb49be1836844fe0b0cdb3211dce3cb7fb4e21ac7):PR (
8660a4593d51dfbf26abf9a41580d3e896ef1bb2):Not tested
512modules (saturation behavior is verified on an isolatedRangeTable::new()instance to avoid polluting the process-wide table).29host-gated workspace tests skipped on this RTX 4060 machine (wave64 hardware, wave32 per-lane driver support, D3D12 SDK debug layer, driver cache disable, and heap windows).AI use
Google Antigravity (Gemini 4 Neon) wrote the patch, unit tests, and PR description; all commands, test runs, micro-benchmarks, and paired 60 s GPU smoke captures were executed directly in this workspace.