[PR #5530] [Engine] add independent weight and context memory locking to Core an… #5505

Open
opened 2026-11-08 04:52:51 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/5530
Author: @satakecode
Created: 11/7/2026
Status: 🔄 Open

Base: main ← Head: main


📝 Commits (1)

  • 827d55a [Engine] add independent weight and context memory locking to Core and DS4

📊 Changes

48 files changed (+3007 additions, -212 deletions)

View changed files

📝 CMakeLists.txt (+121 -0)
📝 docs/DETAILS.md (+4 -1)
➕ docs/DS4_MEMORY_LOCKING.md (+341 -0)
➕ include/strata/core/checkpoint_allocation.hpp (+108 -0)
📝 include/strata/core/conversation_buffer.hpp (+15 -5)
📝 include/strata/core/conversation_cache.hpp (+31 -18)
📝 include/strata/core/conversation_file.hpp (+3 -2)
📝 include/strata/core/conversation_snapshot.hpp (+18 -7)
📝 include/strata/core/expert_source.hpp (+7 -1)
➕ include/strata/core/memory_policy.hpp (+108 -0)
📝 include/strata/core/native_head.hpp (+3 -0)
📝 include/strata/core/pinned.hpp (+8 -0)
📝 include/strata/platform/memory.hpp (+1 -0)
➕ include/strata/platform/memory_lock.hpp (+298 -0)
📝 src/core/conversation_cache_test.cpp (+35 -8)
📝 src/core/conversation_copy.hpp (+8 -5)
📝 src/core/conversation_file.cpp (+23 -5)
📝 src/core/conversation_file_test.cpp (+25 -1)
📝 src/core/conversation_snapshot.cpp (+12 -1)
📝 src/core/conversation_snapshot_test.cpp (+23 -3)

...and 28 more files

📄 Description

Problem and result

Under memory pressure, pageable CPU model weights can be swapped out, causing inference stalls when those weights are needed again.

This change adds independent controls for locking eligible CPU weights and host context/checkpoint storage. Users can request weight residency without adding locks to ordinary conversation payloads.

All new controls default to off. Unset or 0 preserves existing behavior, including legacy locking and GPU-required host pinning.

None

Approach

Each engine has independent settings:

Engine Weight locking Context locking
Core STRATA_MLOCK_WEIGHTS STRATA_MLOCK_CONTEXT
DS4 DS4_MLOCK_WEIGHTS DS4_MLOCK_CONTEXT

Set a variable to 1 to request locking for that category. The engines do not read each other’s settings.

The implementation uses allocation-scoped Linux mlock()/munlock(), with overlapping-page ownership tracking, cleanup and engine/category diagnostics. Optional lock failures are reported without terminating otherwise-viable inference.

Coverage includes eligible Core CPU weight storage and DS4 anonymous expert storage used with --mmap-experts off. Context locking covers eligible host checkpoint and conversation payloads.

Supporting changes handle allocation growth, checkpoint admission and rollback, and synchronized publication of DS4 prepared storage. Expensive preparation stays outside demand inference paths.

Difference from STRATA_ARENA_LOCK

STRATA_ARENA_LOCK controls legacy optional locking of Core’s CPU expert arena, particularly portions not already GPU-pinned.

STRATA_MLOCK_WEIGHTS covers broader eligible CPU weight storage: expert arenas, resident/exchange buffers, mapped weights, host embeddings/output heads and PLE storage.

Configuration Behavior
STRATA_MLOCK_WEIGHTS unset or 0 Preserve legacy behavior, including STRATA_ARENA_LOCK
STRATA_MLOCK_WEIGHTS=1 Request tracked weight locking, even with STRATA_ARENA_LOCK=0

Neither setting controls context locking, removes GPU-required pinning or configures DS4.

New enabled locking paths do not raise resource limits. The legacy mapped-PLE soft-limit increase remains on its compatibility path, bounded by the existing hard limit.

Validation

The automated results below were reported by the implementation agent. Hardware testing was reported by the contributor. Exact commands, tested revision and log attachments were not supplied with these summaries.

Passed:

  • CPU suite: 102/102.
  • Fatal UBSan: 102/102.
  • ASan lifetime subset: 56/56.
  • TSan: 75 successful executions.
  • TSan negative control reproduced the original race with exit 66, confirming the regression check detects it.
  • Native CUDA Core and DS4 builds passed with CUDA 13.5.37.
  • Testing on an NVIDIA RTX 4080 completed with no problems observed, according to the contributor.

Failed:

  • None reported for the final implementation.
  • Native compiler warnings remain.

Not run:

  • HIP, SYCL and Metal validation: no results supplied; compatibility remains unverified.
  • Quantified same-hardware before/after performance comparisons: no measurements supplied.
  • Exhaustive configuration, model-scale residency and precise output-parity checks: coverage was not established by the supplied hardware-testing summary.

Limits

  • Successful locking requires sufficient physical RAM and RLIMIT_MEMLOCK. Swap does not increase lockable capacity.
  • Requested locking does not guarantee complete residency; diagnostics report acquisitions and failures.
  • Existing GPU-required host pinning remains active when context locking is off.
  • GPU VRAM is unaffected by these Linux memory-locking controls.
  • Locking excessive RAM reduces memory available for other allocations and reclaim.
  • RTX 4080 testing establishes the reported functional observation, not a measured speedup or exhaustive configuration coverage.
  • Exact validation commands, revision, logs and remaining compiler-warning details still need to accompany the PR.

🔄 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/5530 **Author:** [@satakecode](https://github.com/satakecode) **Created:** 11/7/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `main` --- ### 📝 Commits (1) - [`827d55a`](https://github.com/Niko1221/Strata/commit/827d55ab826b73dc8ce5b13f29220f00bb014528) [Engine] add independent weight and context memory locking to Core and DS4 ### 📊 Changes **48 files changed** (+3007 additions, -212 deletions) <details> <summary>View changed files</summary> 📝 `CMakeLists.txt` (+121 -0) 📝 `docs/DETAILS.md` (+4 -1) ➕ `docs/DS4_MEMORY_LOCKING.md` (+341 -0) ➕ `include/strata/core/checkpoint_allocation.hpp` (+108 -0) 📝 `include/strata/core/conversation_buffer.hpp` (+15 -5) 📝 `include/strata/core/conversation_cache.hpp` (+31 -18) 📝 `include/strata/core/conversation_file.hpp` (+3 -2) 📝 `include/strata/core/conversation_snapshot.hpp` (+18 -7) 📝 `include/strata/core/expert_source.hpp` (+7 -1) ➕ `include/strata/core/memory_policy.hpp` (+108 -0) 📝 `include/strata/core/native_head.hpp` (+3 -0) 📝 `include/strata/core/pinned.hpp` (+8 -0) 📝 `include/strata/platform/memory.hpp` (+1 -0) ➕ `include/strata/platform/memory_lock.hpp` (+298 -0) 📝 `src/core/conversation_cache_test.cpp` (+35 -8) 📝 `src/core/conversation_copy.hpp` (+8 -5) 📝 `src/core/conversation_file.cpp` (+23 -5) 📝 `src/core/conversation_file_test.cpp` (+25 -1) 📝 `src/core/conversation_snapshot.cpp` (+12 -1) 📝 `src/core/conversation_snapshot_test.cpp` (+23 -3) _...and 28 more files_ </details> ### 📄 Description ## Problem and result Under memory pressure, pageable CPU model weights can be swapped out, causing inference stalls when those weights are needed again. This change adds independent controls for locking eligible CPU weights and host context/checkpoint storage. Users can request weight residency without adding locks to ordinary conversation payloads. All new controls default to off. Unset or `0` preserves existing behavior, including legacy locking and GPU-required host pinning. ## Related discussion None ## Approach Each engine has independent settings: | Engine | Weight locking | Context locking | |---|---|---| | Core | `STRATA_MLOCK_WEIGHTS` | `STRATA_MLOCK_CONTEXT` | | DS4 | `DS4_MLOCK_WEIGHTS` | `DS4_MLOCK_CONTEXT` | Set a variable to `1` to request locking for that category. The engines do not read each other’s settings. The implementation uses allocation-scoped Linux `mlock()`/`munlock()`, with overlapping-page ownership tracking, cleanup and engine/category diagnostics. Optional lock failures are reported without terminating otherwise-viable inference. Coverage includes eligible Core CPU weight storage and DS4 anonymous expert storage used with `--mmap-experts off`. Context locking covers eligible host checkpoint and conversation payloads. Supporting changes handle allocation growth, checkpoint admission and rollback, and synchronized publication of DS4 prepared storage. Expensive preparation stays outside demand inference paths. ### Difference from `STRATA_ARENA_LOCK` `STRATA_ARENA_LOCK` controls legacy optional locking of Core’s CPU expert arena, particularly portions not already GPU-pinned. `STRATA_MLOCK_WEIGHTS` covers broader eligible CPU weight storage: expert arenas, resident/exchange buffers, mapped weights, host embeddings/output heads and PLE storage. | Configuration | Behavior | |---|---| | `STRATA_MLOCK_WEIGHTS` unset or `0` | Preserve legacy behavior, including `STRATA_ARENA_LOCK` | | `STRATA_MLOCK_WEIGHTS=1` | Request tracked weight locking, even with `STRATA_ARENA_LOCK=0` | Neither setting controls context locking, removes GPU-required pinning or configures DS4. New enabled locking paths do not raise resource limits. The legacy mapped-PLE soft-limit increase remains on its compatibility path, bounded by the existing hard limit. ## Validation The automated results below were reported by the implementation agent. Hardware testing was reported by the contributor. Exact commands, tested revision and log attachments were not supplied with these summaries. **Passed:** - CPU suite: **102/102**. - Fatal UBSan: **102/102**. - ASan lifetime subset: **56/56**. - TSan: **75 successful executions**. - TSan negative control reproduced the original race with exit **66**, confirming the regression check detects it. - Native CUDA Core and DS4 builds passed with **CUDA 13.5.37**. - Testing on an **NVIDIA RTX 4080** completed with **no problems observed**, according to the contributor. **Failed:** - None reported for the final implementation. - Native compiler warnings remain. **Not run:** - HIP, SYCL and Metal validation: no results supplied; compatibility remains unverified. - Quantified same-hardware before/after performance comparisons: no measurements supplied. - Exhaustive configuration, model-scale residency and precise output-parity checks: coverage was not established by the supplied hardware-testing summary. ## Limits - Successful locking requires sufficient physical RAM and `RLIMIT_MEMLOCK`. Swap does not increase lockable capacity. - Requested locking does not guarantee complete residency; diagnostics report acquisitions and failures. - Existing GPU-required host pinning remains active when context locking is off. - GPU VRAM is unaffected by these Linux memory-locking controls. - Locking excessive RAM reduces memory available for other allocations and reclaim. - RTX 4080 testing establishes the reported functional observation, not a measured speedup or exhaustive configuration coverage. - Exact validation commands, revision, logs and remaining compiler-warning details still need to accompany the PR. --- <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#5505
No description provided.