Skip to content

Fix: Accurate memory statistics for arena allocators (#608) - #717

Merged
ashvardanian merged 3 commits into
unum-cloud:main-devfrom
swasik:issue-608-mem-stats
Feb 22, 2026
Merged

ashvardanian merged 3 commits into
unum-cloud:main-devfrom
swasik:issue-608-mem-stats

Conversation

@swasik

@swasik swasik commented Feb 22, 2026

Copy link
Copy Markdown
Contributor

Fixes #608 — total_allocated() in memory_mapping_allocator_gt was reverse-engineering totals by dividing capacity in a loop, producing wrong results when ceil2() caused non-uniform capacity jumps.

Changes

  • index_plugins.hpp — Replace the reverse-engineering loop with a total_allocated_ member incremented on each arena allocation. Handled in move ops and reset().
  • index_dense.hpp — Add memory_stats_t struct and memory_stats() method returning per-tape (graph / vectors) breakdowns of allocated, wasted, and reserved bytes.
  • rust/lib.{hpp,cpp,rs} — Expose memory_stats() through the cxx bridge as a shared MemoryStats struct with 6 fields, wired from NativeIndex to the high-level Index wrapper.

All C++ and Rust tests pass.

…ator_gt` (unum-cloud#608)

The previous `total_allocated()` reverse-engineered the total by dividing
`last_capacity_` by the capacity multiplier in a loop. This was inaccurate
when `ceil2(extended_bytes)` produced larger-than-expected arena sizes,
causing the reverse calculation to undercount.

Add a `total_allocated_` member that is incremented on each arena
allocation and returned directly, making the method O(1) and exact.
Add `memory_stats_t` to `index_dense_gt` returning separate allocated,
wasted, and reserved byte counts for both the graph tape allocator
(alignment 64) and the vectors tape allocator (alignment 8).
Add `MemoryStats` shared struct to the cxx bridge and wire it through
`NativeIndex::memory_stats()` in C++ to `Index::memory_stats()` in Rust,
giving Rust callers per-tape allocated/wasted/reserved breakdowns.
@swasik swasik mentioned this pull request Feb 22, 2026
3 tasks done
@ashvardanian
ashvardanian changed the base branch from main to main-dev February 22, 2026 10:56
@ashvardanian
ashvardanian merged commit 24c5bed into unum-cloud:main-dev Feb 22, 2026
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.

Feature: More accurate memory statistics

2 participants