Mooncake/scripts
Venkat Raman 3ac7de25ac
[Store] Add lock-free MmapArena allocator for buffer mmap path (#1820)
* [Store] Add lock-free MmapArena allocator for buffer mmap path

Replace per-allocation mmap() syscalls in allocate_buffer_mmap_memory()
with a lock-free atomic bump allocator (MmapArena). Pre-allocates a
configurable pool (default 64GB) and serves allocations via CAS loop,
reducing allocation latency from ~1us (mmap syscall) to ~50ns (atomic).

Allocation lifecycle is static: all callers (ClientBufferAllocator,
global segments in RealClient::setup_internal) allocate at startup and
free at shutdown. The arena outlives all allocations, so the bump-only
(no individual free) design is correct for this usage pattern.

Feature-flagged via gflags:
  --use_mmap_arena_allocator (default: true)
  --mmap_arena_pool_size (default: 64GB)

Falls back to direct mmap() when arena is disabled, fails to init,
or is exhausted.

Cherry-picked from flow-ipc-poc branch (utils.cpp perf path only).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* [Store] Fix three correctness issues in MmapArena

1. Honor caller's alignment contract: allocate() now accepts a
   per-call alignment parameter and uses max(arena default, caller
   request). allocate_buffer_mmap_memory() forwards its alignment
   argument to the arena. Previously, the caller's alignment was
   silently ignored — the arena always used 64-byte alignment
   regardless of what the caller requested.

2. Remove MAP_POPULATE from arena pool mmap: the default pool is
   64GB but callers typically use only a fraction (e.g. 4GB of
   segments). MAP_POPULATE would pre-fault all 64GB of pages upfront,
   causing seconds of startup delay and potentially triggering OOM
   on machines with less physical memory. Pages now fault on demand.

3. Make alignment_ atomic and store it BEFORE the CAS on pool_base_:
   previously alignment_ was a plain size_t written AFTER the release
   CAS, so the store was not in the happens-before relationship
   established by the acquire-release pair on pool_base_. Now both
   alignment_ and pool_size_ are stored before the CAS with the
   release fence guaranteeing their visibility to readers.

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-05-03 14:18:18 +08:00
..
ascend fix (CI): hardcode Ascend mirror URL and remove pull_request_target routing (#1992) 2026-04-28 10:36:43 +08:00
management [CLI] add script for metadata management (#1746) 2026-03-26 13:18:19 +08:00
tone_tests [Store] Add lock-free MmapArena allocator for buffer mmap path (#1820) 2026-05-03 14:18:18 +08:00
build_wheel.sh [Build] Update build_wheel.sh package installation logic (#1950) 2026-04-22 12:49:47 +08:00
check_hicache_hugepage_requirements.py [Store] Add lock-free MmapArena allocator for buffer mmap path (#1820) 2026-05-03 14:18:18 +08:00
code_format.sh [Misc] Fix silent failure in `code_format.sh` when clang-format is missing (#1824) 2026-04-06 12:19:26 +08:00
generate_cluster_topology.py [TE] Add TENT codebase to main (Phase 1: structural import) (#1213) 2025-12-22 19:22:13 +08:00
run_tests.sh [Store] add safe tensor API (#1199) 2026-02-26 10:11:10 +08:00
test_async_store.py [store] add async api (#1265) 2025-12-25 16:46:14 +08:00
test_copy_move_api.py [Store][Feature] copy and move client support (#1364) 2026-02-06 19:02:02 +08:00
test_drain_http_api.py feat(store): expose drain job control via master HTTP API (#1815) 2026-04-09 14:33:45 +08:00
test_hicache_hugepage_requirements.py [Store] Add lock-free MmapArena allocator for buffer mmap path (#1820) 2026-05-03 14:18:18 +08:00
test_installation.sh [Store] feat: Add standalone deployment implementation for Client (#1084) 2025-11-25 23:57:30 +08:00
test_tensor_api.py [Store] Unified parallel tensor IO (#1389) 2026-04-27 23:39:40 +08:00
test_upsert_api.py [Store] Unified parallel tensor IO (#1389) 2026-04-27 23:39:40 +08:00