Improve memory
Some checks failed
CI / Check (push) Failing after 2m0s
Build and publish Docker image / build-and-push (push) Successful in 7m36s

This commit is contained in:
Andras Schmelczer 2026-06-04 21:42:21 +01:00
parent d6d20ccd37
commit 843d14b7ba
6 changed files with 110 additions and 4 deletions

View file

@ -19,6 +19,25 @@ mod routes;
mod state;
pub mod utils;
// Use jemalloc as the global allocator. glibc malloc keeps freed memory in many
// per-CPU arenas and rarely returns it to the OS, so the transient buffers from
// the rayon/Polars-parallel data load stay resident and inflate steady-state RSS.
// jemalloc's decay-based purging (configured below) hands those pages back.
#[cfg(not(target_env = "msvc"))]
#[global_allocator]
static GLOBAL: tikv_jemallocator::Jemalloc = tikv_jemallocator::Jemalloc;
// Return dirty/muzzy pages to the OS ~1s after they go idle, and run a background
// thread to do so proactively (so RSS drops after the startup load peak without
// waiting for the next allocation). Read by jemalloc at startup via the
// `malloc_conf` symbol (unprefixed on Linux). Can be overridden by the
// `_RJEM_MALLOC_CONF` / `MALLOC_CONF` env var.
#[cfg(not(target_env = "msvc"))]
#[allow(non_upper_case_globals)]
#[used]
#[export_name = "malloc_conf"]
pub static malloc_conf: &[u8] = b"background_thread:true,dirty_decay_ms:1000,muzzy_decay_ms:1000\0";
use std::path::{Path, PathBuf};
use std::sync::Arc;
use std::time::Duration;