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 <mgrigorov@apache.org>
This commit is contained in:
Martin Tzvetanov Grigorov 2025-07-02 14:14:18 +03:00
parent aa366d593d
commit 45da2257ec
No known key found for this signature in database
GPG key ID: 3194FD8C1AE300EF

View file

@ -865,7 +865,10 @@ fn total_memory_bytes() -> Option<u64> {
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
}