[PR #3509] [Engine] arena: attach a complete shared arena instead of re-copying (STRATA_ARENA_REUSE=1, opt-in) #4661

Open
opened 2026-11-07 15:38:09 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/3509
Author: @Jerry-Lee661
Created: 10/20/2026
Status: 🔄 Open

Base: main ← Head: arena-reuse


📝 Commits (1)

  • 1bd6178 arena: attach a complete shared arena instead of re-copying (STRATA_ARENA_REUSE=1, opt-in)

📊 Changes

3 files changed (+38 additions, -5 deletions)

View changed files

📝 include/strata/core/pinned.hpp (+6 -0)
📝 src/core/expert_source.cpp (+15 -1)
📝 src/core/pinned.cu (+17 -4)

📄 Description

Problem

With --shared-expert-arena, every engine start re-copies the whole expert arena into the shared file even when a previous start already wrote it completely. On our machine (2x RX 7900 XTX gfx1100, ROCm 10.1, E5-2673 v3, 128 GB DDR3, Qwen3.8-Flash-Next IQ3_S pack, 46.84 GiB arena on /dev/shm) that copy takes 75-100 s per start and dominates every restart and form switch. The existing pack-hash check in pinned.cu already proves the existing file belongs to this pack; nothing reuses its contents.

Change

STRATA_ARENA_REUSE=1 (off by default):

  • reserve() reports whether the shared arena file already existed and whether the header's completion flag (reserved[0]) is set;
  • after a full copy, mark_shared_complete() sets the flag (MAP_SHARED, so it lands in the file);
  • when the file exists, is complete, and the pack hash matches (the existing check rejects a mismatched pack), ArenaExpertSource::open() attaches the mapped pages and skips the copy, and the load note says it attached;
  • a fresh, torn (flag unset) or hash-mismatched file behaves exactly as before. Only the experts.bin pack path reuses; the GGUF / --mmap-experts paths are excluded.

Validation

  • passed (compile, current main cbfd5b92): ninja CMakeFiles/strata_engine.dir/src/core/expert_source.cpp.o CMakeFiles/strata_core.dir/src/core/pinned.cu.o, HIP/gfx1100 (ROCm 10.1), 0 errors.
  • passed (runtime, v0.1.45 477ac13c + this patch, the machine above): first start copies the arena (75 s) and writes the flag; the second start attaches: engine log expert arena attached from /dev/shm/strata-shared-arena.bin (STRATA_ARENA_REUSE: no copy) and loaded 46.84 GiB at 0.00 GiB/s, total start 45 s, zero pack reads; the arena content sha256 is identical before and after the attach; greedy outputs identical.
  • not run: CUDA and SYCL compilation (no CUDA/SYCL machine here), runtime on current main, cross-form attach (solo/dual topologies on one arena). Per CONTRIBUTING I keep this PR as a draft: could someone build the CUDA backend on this revision, or point me at a build recipe?

Limits and compatibility

  • Opt-in; the default path is untouched (the only default-path change is two extra out-params in reserve()).
  • The completion flag assumes the shared arena file outlives the process (tmpfs or disk). On a disk-backed file a power loss between the data writeback and the flag writeback could leave a complete-flagged file with stale data; the pack-hash check still guards pack identity. Our use keeps the arena on /dev/shm.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/3509 **Author:** [@Jerry-Lee661](https://github.com/Jerry-Lee661) **Created:** 10/20/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `arena-reuse` --- ### 📝 Commits (1) - [`1bd6178`](https://github.com/Niko1221/Strata/commit/1bd6178148e75726ac7ee253975d93349e14c663) arena: attach a complete shared arena instead of re-copying (STRATA_ARENA_REUSE=1, opt-in) ### 📊 Changes **3 files changed** (+38 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/core/pinned.hpp` (+6 -0) 📝 `src/core/expert_source.cpp` (+15 -1) 📝 `src/core/pinned.cu` (+17 -4) </details> ### 📄 Description ## Problem With `--shared-expert-arena`, every engine start re-copies the whole expert arena into the shared file even when a previous start already wrote it completely. On our machine (2x RX 7900 XTX gfx1100, ROCm 10.1, E5-2673 v3, 128 GB DDR3, Qwen3.8-Flash-Next IQ3_S pack, 46.84 GiB arena on /dev/shm) that copy takes 75-100 s per start and dominates every restart and form switch. The existing pack-hash check in pinned.cu already proves the existing file belongs to this pack; nothing reuses its contents. ## Change `STRATA_ARENA_REUSE=1` (off by default): - `reserve()` reports whether the shared arena file already existed and whether the header's completion flag (`reserved[0]`) is set; - after a full copy, `mark_shared_complete()` sets the flag (MAP_SHARED, so it lands in the file); - when the file exists, is complete, and the pack hash matches (the existing check rejects a mismatched pack), `ArenaExpertSource::open()` attaches the mapped pages and skips the copy, and the load note says it attached; - a fresh, torn (flag unset) or hash-mismatched file behaves exactly as before. Only the `experts.bin` pack path reuses; the GGUF / `--mmap-experts` paths are excluded. ## Validation - **passed** (compile, current main `cbfd5b92`): `ninja CMakeFiles/strata_engine.dir/src/core/expert_source.cpp.o CMakeFiles/strata_core.dir/src/core/pinned.cu.o`, HIP/gfx1100 (ROCm 10.1), 0 errors. - **passed** (runtime, v0.1.45 `477ac13c` + this patch, the machine above): first start copies the arena (75 s) and writes the flag; the second start attaches: engine log `expert arena attached from /dev/shm/strata-shared-arena.bin (STRATA_ARENA_REUSE: no copy)` and `loaded 46.84 GiB at 0.00 GiB/s`, total start 45 s, zero pack reads; the arena content sha256 is identical before and after the attach; greedy outputs identical. - **not run**: CUDA and SYCL compilation (no CUDA/SYCL machine here), runtime on current main, cross-form attach (solo/dual topologies on one arena). Per CONTRIBUTING I keep this PR as a draft: could someone build the CUDA backend on this revision, or point me at a build recipe? ## Limits and compatibility - Opt-in; the default path is untouched (the only default-path change is two extra out-params in `reserve()`). - The completion flag assumes the shared arena file outlives the process (tmpfs or disk). On a disk-backed file a power loss between the data writeback and the flag writeback could leave a complete-flagged file with stale data; the pack-hash check still guards pack identity. Our use keeps the arena on /dev/shm. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4661
No description provided.