From b3fdb0ad1d3c68d6be03f88fbfd69ccf0a10abca Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Tue, 3 Nov 2026 00:30:05 +0100 Subject: [PATCH] engine: release the page cache of the shards and MTP pack once more after the serve stack is open (4-5 GiB of dense tensors were left resident) --- crates/leleka-runtime/src/backend_original_serve.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/leleka-runtime/src/backend_original_serve.rs b/crates/leleka-runtime/src/backend_original_serve.rs index ec499cbb..e1f1cee3 100644 --- a/crates/leleka-runtime/src/backend_original_serve.rs +++ b/crates/leleka-runtime/src/backend_original_serve.rs @@ -719,6 +719,18 @@ mod runner { })]); publish_prefix_summary(&stack, shared); crate::load_clock::lap("serve_stack_open_total"); + // The first release (right after the expert bank was copied) cannot see what the stack open reads next: the dense tensors of shard 0 and the + // MTP pack go through the page cache (4-5 GiB measured at idle on the 5090), and the resident copies are in the engine's own memory. Give + // those pages back too, so that no model byte is held twice (clean pages only, POSIX_FADV_DONTNEED, never drop_caches; best effort). + #[cfg(target_os = "linux")] + if options.expert_source == crate::backend::ExpertSource::Resident { + let mut files: Vec = model_files.clone(); + if let Some(dir) = options.mtp_rt_directory.as_ref() { + files.extend(["experts.bin", "dense.bin"].map(|name| dir.join(name))); + } + let paths: Vec<&std::path::Path> = files.iter().map(PathBuf::as_path).collect(); + crate::memory_governor::drop_file_cache(&paths); + } leleka_memory::telemetry::set_settings(crate::serve_tuning::describe(&options, context_tokens, workers, None)); // operator telemetry: GPU/RAM/CPU once a second, throughput and cache hits recorded per request leleka_memory::telemetry::set_context_max(u64::from(context_tokens));