mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#3949
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/2253
Author: @alanthinker
Created: 10/13/2026
Status: 🔄 Open
Base:
main← Head:conversation-cache-ram-gate-release📝 Commits (5)
ab963c9serve: the RAM gate releases the heap and stops evicting when it cannot helpf09887fserve: the evict_oldest comment matches the raised mmap threshold (review)6e62d38serve: the RAM gate releases the heap and stops evicting when it cannot help3dbc9acserve: the evict_oldest comment matches the raised mmap threshold (review)3ee9597Merge the pre-rebase branch tip so the closed PR's head stays reachable for /reopen📊 Changes
6 files changed (+203 additions, -14 deletions)
View changed files
📝
include/strata/core/conversation_cache.hpp(+40 -2)📝
include/strata/core/conversation_memory.hpp(+5 -0)📝
src/core/conversation_cache_test.cpp(+102 -0)📝
src/core/conversation_memory.cpp(+15 -0)📝
src/core/conversation_memory_test.cpp(+29 -0)📝
src/program/generate.cpp(+12 -12)📄 Description
Problem and result
The physical-RAM gate of the parking path assumes an evicted parked conversation is visible to
/proc/meminfobefore the next check reads it. That assumption is wrong for the allocations this cache actually makes:ConversationBufferis a list of 16 MiB segments, and glibc's mmap threshold is dynamic - the first generation of segments is mmap'd, freeing one raises the threshold past 16 MiB (capped at 32 MiB), and every later segment comes from the main heap. Freeing one of those only moves the bytes onto the allocator's free list: RSS, and with itMemAvailable, does not move.On today's
main(0.2.0-beta) the gate added for #1347 evicts parked conversations one at a time and re-reads the figure after each. In steady state the figure never moves, so the loop can empty the whole cache and still refuse the snapshot - worse than the refusal it was meant to remove: every parked conversation is lost and every later request re-reads its whole prompt (measured in #1347: 270k tokens, 96 s, 32 times in one session).After this change a release (
malloc_trim(0)) runs before the first re-read and after every eviction, so a dropped conversation shows up in the next reading; and where the missing bytes exceed what the parked conversations could give back, the gate gives up before evicting anything.Related discussion
#1347 (the issue, reproduced on an RTX 4080 SUPER with 91 GB RAM), #1394 (the original PR by @Arthur031221, unmergeable after #879 / #1601 / #1573 landed), and this thread:
Approach
conversation_release_freed_memory()(malloc_trim(0)under__GLIBC__, a no-op elsewhere) is called before the first re-read and after every eviction.ConversationCache::admit_ram()gives up before evicting anything when the missing bytes exceedevictable_bytes()- whatevict_oldest()may actually take, i.e. entries not holding a pinned shared prefix - and re-checks the figure after each reading, so losing telemetry ends the loop.sample_host_memory():MemAvailable, the cgroup limits above the engine,--memory-limit-mib) and the refusal line keepsram_note().Validation
Rebased on
mainate88ee39d(0.2.0-beta, engine 0.1.45.3); branch tip3dbc9aca. Built and tested by me on the serving box from #1347: Linux, RTX 4080 SUPER (32 GB), 94 GB RAM, CUDA 13.2, sm_89.Passed:
cmake -B build -DSTRATA_BUILD_CONVERSATION_TESTS=ON -DSTRATA_ENABLE_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=89 && cmake --build build --target conversation_cache_test conversation_memory_testconversation_cache_test: 4829 checks passedconversation_memory_test: 24 checks passedsession_save_reclaim_test119 checks,conversation_file_test201 checks,conversation_split_failure_testpassedstratacompiles (CUDA 13.2, sm_89)Failed: none.
Not run: running the rebuilt 0.2.0-beta engine on the GPU (this box still serves on the deployed 0.1.x build; the binary compiled, it was not started); HIP, SYCL and Metal builds.
Separate from my checks: @alfre2v ran this branch (at
ab963c96+f09887f6) end-to-end on an RTX 3090 / 64 GB box, results in Related discussion; their soak numbers are theirs, not mine.Limits
malloc_trim(0)returns what has coalesced to an arena's top; a mid-heap segment that cannot coalesce stays invisible even after the release. The loop still converges: further evictions eventually coalesce, andevictable_bytes()bounds the case where even emptying the cache could not help.--session-save-reclaim(#1573) keeps the same assumption between its steps; left alone here to keep this PR to the parking gate.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.