diff --git a/crates/data/src/memory.rs b/crates/data/src/memory.rs index 21b0688cf6..8d330f716d 100644 --- a/crates/data/src/memory.rs +++ b/crates/data/src/memory.rs @@ -66,8 +66,15 @@ fn read() -> (Option, &'static str) { let Some(mut s) = sysinfo::System::new().ok() else { return (None, "unknown") }; s.refresh_memory_specifics(sysinfo::MemoryRefreshKind::nothing().with_ram()); let Some(total) = Some(s.total_memory()).filter(|m| *m > 0) else { return (None, "unknown") }; - // A container's limit, on Linux; none is reported elsewhere. - match s.cgroup_limits().map(|c| c.total_memory).filter(|m| *m > 0 && *m < total) { + // A container's limit, on Linux; none is reported elsewhere. The limits of this process's own + // control group and those above it count, not only the root's: a `systemd-run` scope or a + // service's `MemoryMax` sits below the root, which is all a container's own namespace shows. + let own = sysinfo::get_current_pid().ok().and_then(|pid| { + s.refresh_processes_specifics(sysinfo::ProcessesToUpdate::Some(&[pid]), false, sysinfo::ProcessRefreshKind::nothing()); + s.process(pid)?.cgroup_limits() + }); + let limits = [own, s.cgroup_limits()].into_iter().flatten().map(|c| c.total_memory); + match limits.filter(|m| *m > 0 && *m < total).min() { Some(limit) => (Some(limit), "container"), None => (Some(total), "computer"), } diff --git a/docs/user-guide/analysis.md b/docs/user-guide/analysis.md index f154a422f2..5436e0f52c 100644 --- a/docs/user-guide/analysis.md +++ b/docs/user-guide/analysis.md @@ -1549,9 +1549,9 @@ cores; `gp.env` returns the threads and cores as `limits.threads` and `limits.co runs on one thread. `gp.env` also returns the memory limits on this computer (`limits`). On the desktop they follow the -computer's memory, or a container's limit when it is lower: each plans for a quarter of it, never +computer's memory, or a memory limit set on RustGIS (a container's, or a service's such as systemd's `MemoryMax`) when it is lower: each plans for a quarter of it, never below the web app's fixed limits and never above a ceiling. `limits.memorySource` says what they -follow: `computer`, `container` (a container's limit, lower than the computer's memory), +follow: `computer`, `container` (such a limit, lower than the computer's memory), `override` or `unknown`. For tests, or to reproduce a smaller computer, set the environment variable `RUSTGIS_MEMORY_BYTES` to the memory in bytes (such as `8589934592` for 8 GiB) before starting RustGIS: it replaces the memory read from the computer and any container limit, and the