MOD-9881 Track shared SVS thread pool memory & expose it through public API#967
Open
meiravgri wants to merge 7 commits into
Open
MOD-9881 Track shared SVS thread pool memory & expose it through public API#967meiravgri wants to merge 7 commits into
meiravgri wants to merge 7 commits into
Conversation
introduce VecSim_GlobalStatsInfo
🛡️ Jit Security Scan Results✅ No security findings were detected in this PR
Security scan by Jit
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0ce994f. Configure here.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #967 +/- ##
==========================================
+ Coverage 96.95% 96.97% +0.01%
==========================================
Files 130 130
Lines 7749 7829 +80
==========================================
+ Hits 7513 7592 +79
- Misses 236 237 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The shared
VecSimSVSThreadPoolsingleton was previously created via rawnewwith the default allocator, so its slot vector and per-slotThreadSlotobjects bypassedVecSimAllocatorand were invisible to any memory accounting downstream (FT.INFO,INFO MODULES, etc.).This PR:
VecSimAllocator(usingVecsimSTLAllocatorfor the slot vector andstd::allocate_sharedfor thread objects).size_t VecSim_GetGlobalMemory(void)returning the total bytes of process-wide VecSim allocations not tied to any single index — today equal to the shared SVS thread pool's tracked allocation size.VECSIM_INFOvia two new fields:GLOBAL_MEMORY— appended at the top level of every algorithm's debug response by the C API wrapperVecSimIndex_DebugInfoIterator. Always present (value may be 0).SHARED_SVS_THREADPOOL_MEMORY— appended at the end of any SVS algorithm section bySVSIndex::debugInfoIterator(). Present at the top level of a non-tiered SVS response, or insideBACKEND_INDEXof a tiered SVS response.Public API change
Before
// (no API to query process-wide VecSim memory)After
Callers (e.g. RediSearch) can fold this into per-spec or process-wide memory metrics without depending on which algorithm contributes.
VECSIM_INFO(FT.DEBUG) output changeCommon header (every algorithm, unchanged)
FLAT — 11 → 12 fields
<common header × 10> BLOCK_SIZE + GLOBAL_MEMORYHNSW — 18 → 19 fields
<common header × 10> BLOCK_SIZE, M, EF_CONSTRUCTION, EF_RUNTIME, MAX_LEVEL, ENTRYPOINT, EPSILON, NUMBER_OF_MARKED_DELETED + GLOBAL_MEMORYSVS (non-tiered) — 25 → 27 fields
Tiered HNSW — 16 → 17 fields
<common header × 10> (ALGORITHM = "TIERED") MANAGEMENT_LAYER_MEMORY, BACKGROUND_INDEXING, TIERED_BUFFER_LIMIT FRONTEND_INDEX = nested [<FLAT fields, 11>] (no GLOBAL_MEMORY in nested) BACKEND_INDEX = nested [<HNSW fields, 18>] (no GLOBAL_MEMORY in nested) TIERED_HNSW_SWAP_JOBS_THRESHOLD + GLOBAL_MEMORYTiered SVS — 17 → 18 fields
Two emission rules
GLOBAL_MEMORYis appended exactly once, at the outermost iterator level, by the C API wrapper. Never appears inside a nestedFRONTEND_INDEX/BACKEND_INDEX.SHARED_SVS_THREADPOOL_MEMORYis appended at the end of any SVS algorithm section bySVSIndex::debugInfoIterator(). So it shows up at the top level of a non-tiered SVS response, or insideBACKEND_INDEXof a tiered SVS response — never duplicated.Stats / API output change
VecSim_GetGlobalMemory()Before: API did not exist. The pool's slot vector and per-slot
ThreadSlotobjects went through the default allocator and were not tracked anywhere.After:
Per-index
getAllocationSize()(SVS only)Before: Did not include any per-index portion of the parallelism slot, since the pool was untracked entirely.
After: Each SVS index's per-index allocator now tracks its own
parallelismslot (a small fixed-size structure inside the index, allocated through the index'sVecSimAllocator). The shared pool itself remains process-wide and reported viaVecSim_GetGlobalMemory().Cross-field invariant
Since the SVS thread pool is currently the only contributor to global memory:
This invariant is enforced by the new gtest
SVSTest.debugInfoGlobalMemoryEqualsSharedSVSThreadPoolMemory. If a future contributor is added toVecSim_GetGlobalMemory()without updating breakdowns, the test will catch the drift.Tests
SVSTest.debugInfoGlobalMemoryEqualsSharedSVSThreadPoolMemory— asserts both new fields exist exactly once in a non-tiered SVS response and report the same bytes asVecSim_GetGlobalMemory().compareFlatIndexInfoToIterator,compareHNSWIndexInfoToIterator,compareSVSIndexInfoToIteratorto take anexpect_global_memoryparameter (defaulttrue) — needed because these comparators are called both with the C API iterator (top level, has GLOBAL_MEMORY) and as nested-backend comparators insidecompareTieredIndexInfoToIterator(no GLOBAL_MEMORY).SVS25 → 26,TIERED_SVSupdated accordingly.FLAT/HNSW/TIERED_HNSWfield-count constants represent the C++ method count (no GLOBAL_MEMORY); the comparators add+1when called with the C API iterator.getSVSFields()/getTieredSVSFields()updated to reflect the new field positions.Compatibility
VECSIM_INFO. Existing consumers parsing by field name are unaffected; consumers indexing by position must shift their expectations accordingly (covered above).VecSim_GetGlobalMemory()is purely additive.Mark if applicable
Note
Medium Risk
Adds a new public API and changes
VECSIM_INFO/debug iterator output field counts/order, which can affect downstream consumers that rely on positional parsing or memory accounting. Core search/indexing logic is unchanged, but the thread-pool allocation tracking and singleton initialization checks could impact stats reporting if incorrect.Overview
Adds process-wide VecSim memory reporting by tracking allocations of the shared SVS thread pool through a dedicated
VecSimAllocatorand exposing it via newVecSim_GetGlobalMemory().VecSimIndex_DebugInfoIteratornow appends a top-levelGLOBAL_MEMORYfield for all algorithms, while SVS debug info addsSHARED_SVS_THREADPOOL_MEMORYto report the pool’s bytes (and adjusts iterator capacity/count expectations accordingly). SVS index construction and size estimation were updated to account for per-indexVecSimSVSThreadPoolparallelism allocation, and unit tests/utilities were updated to validate the new fields and revised field counts.Reviewed by Cursor Bugbot for commit 31c0e0a. Bugbot is set up for automated code reviews on this repo. Configure here.