mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #3115] 0.1.45: segment_capacity's held/8 bound shrinks pool segments below the mmap threshold; evicted memory lingers in the glibc arena and the RAM admission loop drains the whole conversation cache #1250
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#1250
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?
Originally created by @wannagoxuf on GitHub (Oct 19, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/3115
Environment
--batch 4 --batch-groups auto,--kv k8v4 --kv-resident 524288--conversation-cache-mib 393216 --conversation-cache-slots 192 --conversation-cache-min-free-mib 65536 --conversation-cache-min-tokens 2000Observed on 0.1.45 (one day of traffic)
/proc/<pid>/mapsshows[heap]= 341.3 GiB in a single brk segment - the evicted conversations' pages linger in the glibc arena instead of returning to the kernel.MemAvailablestays pinned at 76-80 GiB, so the admission line (need + 64 GiB floor) is not reached, the loop keeps evicting (while (!admit() && evict_oldest())), and the pool gets drained.For contrast, on 0.1.44.1 with the same box, workload and
MALLOC_MMAP_THRESHOLD_=16777216, admission was well-behaved: a snapshot admission evicted 1-3 conversations (the freed pages returned to the kernel immediately andMemAvailablecrossed the line after the first evictions).Root cause
0.1.45's
ConversationBuffer::segment_capacity(count, previous, growing, held)bounds the append reserve byheld/8(at least 64 KiB) - a welcome memory saving (~40% per conversation by our measurement), but it means most segments of a parked conversation are smaller than 16 MiB (whileheld < 128 MiBevery segment is, and small conversations stay below entirely).Segments below glibc's mmap threshold are served from the arena;
free()puts them on arena free lists and the pages are not returned to the kernel, soMemAvailabledoes not move. The admission loop samples/proc/meminfoafter every eviction, sees "still not enough room", and keeps evicting - past the point where hundreds of GiB have actually been freed inside the process.On 0.1.44 the
previous*2growth reached the 16 MiB cap quickly, so settingMALLOC_MMAP_THRESHOLD_=16 MiBmade every segment its own mmap and the loop terminated after 1-3 evictions. On 0.1.45 that no longer covers the pool.Workaround we deploy (works, but environment-level)
MALLOC_MMAP_THRESHOLD_=1048576(1 MiB): every segment >= 1 MiB becomes its own mmap and eviction returns it at once. Withvm.max_map_countraised (1M here) the VMA budget holds (~100K VMAs at a full 384 GiB pool). Sub-1-MiB segments still linger, and we would rather not depend on libc tuning for correctness.Suggested fixes
malloc_trim(0)during the admission eviction loop (e.g. every 32 evictions and once after the loop). On glibc this returns arena free pages to the kernel regardless of thresholds, keeps the meminfo-based admission honest, and is essentially free elsewhere. This alone would have prevented the pool drain.ConversationBuffersegments directly withmmap(MAP_ANONYMOUS)/ release withmunmap- the code comment inconversation_cache.hppalready describes each segment as "its own allocation"; making that literal would decouple the admission loop from libc policy entirely.Happy to provide smaps dumps or test candidate patches on our 4-GPU box. Thanks for 0.1.45 - the piped read and split overlap are a big win for multi-turn long-context traffic.
@Niko1221 commented on GitHub (Oct 19, 2026):
Thanks for taking the time to report this.
We're resetting the tracker for 0.2.0-beta. There are more than 1,300 open issues and pull requests, too many for us to read properly, so we're closing everything that isn't being worked on right now. Closed here does not mean rejected.
To reopen it takes about two minutes:
/reopen. A check runs and either reopens the issue or lists what is still missing.The rules are in CONTRIBUTING.md.
--memory-limit-mib) #3557