From 45da2257ec37a927de193c02202729342a09b17e Mon Sep 17 00:00:00 2001 From: Martin Tzvetanov Grigorov Date: Wed, 2 Jul 2025 14:14:18 +0300 Subject: [PATCH] Take into account the allowed max memory of the container When Meilisearch runs inside a container (e.g. Docker or Kubernetes) it may run with less max memory than the available on the host, e.g. `docker run --memory 1G ...` Fixes #5616 Signed-off-by: Martin Tzvetanov Grigorov --- crates/meilisearch/src/option.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/meilisearch/src/option.rs b/crates/meilisearch/src/option.rs index 9658352c8..675046cf4 100644 --- a/crates/meilisearch/src/option.rs +++ b/crates/meilisearch/src/option.rs @@ -865,7 +865,10 @@ fn total_memory_bytes() -> Option { let mem_kind = RefreshKind::nothing().with_memory(MemoryRefreshKind::nothing().with_ram()); let mut system = System::new_with_specifics(mem_kind); system.refresh_memory(); - Some(system.total_memory()) + system + .cgroup_limits() + .map(|limits| limits.total_memory) + .or_else(|| Some(system.total_memory())) } else { None }