serve: a full conversation cache evicts to pass the physical-RAM gate instead of dropping the snapshot
The parking path has two gates in series: make_room() balances the cache's own budget, then conversation_memory_admit() checks the host's free RAM against the snapshot plus --conversation-cache-min-free-mib. The second was final: a failure dropped the snapshot even though the cache held conversations whose RAM it could have, and the next request read its whole prompt again (270k tokens, 96 s, measured by the reporter in #1347). Evict the least recently active parked conversations until the gate admits the snapshot, bounded by the slot count; entries that hold a pinned shared prefix are not evicted. The failure line says how many were evicted and how many remain. Reported with the fix by alanthinker in #1347.
This commit is contained in:
1 parent
d7932123e1
commit
940011dad9
3 files changed
+63
-9
No files matched your search
@@ -7019,12 +7019,33 @@ int main(int argc, char** argv) {
|
||||
const uint64_t floor = (uint64_t) o.conversation_cache_min_free_mib * 1024 * 1024;
|
||||
const size_t retained = reuse.bytes() + stage_retained;
|
||||
const size_t additional = estimate > retained ? estimate - retained : 0;
|
||||
if (!strata::core::conversation_memory_admit(strata::core::conversation_available_memory(),
|
||||
additional, floor)) {
|
||||
std::fprintf(stderr, "strata serve: conversation cache: skip parking (physical RAM admission; need %zu MiB plus %lld MiB floor, or telemetry unavailable)\n",
|
||||
additional >> 20, (long long) o.conversation_cache_min_free_mib);
|
||||
// The physical-RAM gate: the incoming snapshot has to fit beside the floor. make_room()
|
||||
// above only balanced the cache's own budget, so a full cache leaves this one short even
|
||||
// though every parked conversation could give its RAM back - and refusing here throws
|
||||
// away the whole prompt read that produced this snapshot (measured: 270k tokens, 96 s).
|
||||
// Evict the least recently active parked conversations until it fits, or until none are
|
||||
// left. Each ConversationBuffer is a list of 16 MiB segments, each segment its own
|
||||
// allocation, so an evicted entry is back with the kernel before the next check reads
|
||||
// /proc/meminfo; no waiting is needed. slots() bounds the loop, and the two lines
|
||||
// below say what it did either way.
|
||||
size_t evicted = 0;
|
||||
auto admit = [&] {
|
||||
return strata::core::conversation_memory_admit(
|
||||
strata::core::conversation_available_memory(), additional, floor);
|
||||
};
|
||||
while (!admit() && conversations.size() > 0 && evicted < conversations.slots() &&
|
||||
conversations.evict_oldest())
|
||||
++evicted;
|
||||
if (!admit()) {
|
||||
std::fprintf(stderr, "strata serve: conversation cache: skip parking (physical RAM admission; need %zu MiB plus %lld MiB floor; evicted %zu, %zu still parked, or telemetry unavailable)\n",
|
||||
additional >> 20, (long long) o.conversation_cache_min_free_mib,
|
||||
evicted, conversations.size());
|
||||
return true;
|
||||
}
|
||||
if (evicted)
|
||||
std::fprintf(stderr, "strata serve: conversation cache: evicted %zu parked conversation%s to admit this snapshot (%zu MiB plus %lld MiB floor)\n",
|
||||
evicted, evicted == 1 ? "" : "s", additional >> 20,
|
||||
(long long) o.conversation_cache_min_free_mib);
|
||||
strata::core::SavedConversation image;
|
||||
size_t reused_bytes = 0;
|
||||
if (!strata::core::conversation_snapshot_save(image, view, ss, g, draft0, err,
|
||||
|
||||
Reference in new issue
Block a user