From 722e5260bf51e063b7f9b8d8664fb56dea91b896 Mon Sep 17 00:00:00 2001 From: Em Sharnoff Date: Mon, 18 Sep 2023 10:47:48 -0700 Subject: [PATCH] vm-monitor: Don't set cgroup memory.max (#5333) All it does is make postgres OOM more often (which, tbf, means we're less likely to have e.g. compute_ctl get OOM-killed, but that tradeoff isn't worth it). Internally, this means removing all references to `memory.max` and the places where we calculate or store the intended value. As discussed in the sync earlier. ref: - https://neondb.slack.com/archives/C03H1K0PGKH/p1694698949252439?thread_ts=1694505575.693449&cid=C03H1K0PGKH - https://neondb.slack.com/archives/C03H1K0PGKH/p1695049198622759 --- libs/vm_monitor/src/cgroup.rs | 20 ++++---------------- libs/vm_monitor/src/runner.rs | 11 ++++++----- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/libs/vm_monitor/src/cgroup.rs b/libs/vm_monitor/src/cgroup.rs index fe1c514f76..3254fa4501 100644 --- a/libs/vm_monitor/src/cgroup.rs +++ b/libs/vm_monitor/src/cgroup.rs @@ -561,14 +561,7 @@ impl CgroupWatcher { /// Setting these values also affects the thresholds for receiving usage alerts. #[derive(Debug)] pub struct MemoryLimits { - high: u64, - max: u64, -} - -impl MemoryLimits { - pub fn new(high: u64, max: u64) -> Self { - Self { max, high } - } + pub high: u64, } // Methods for manipulating the actual cgroup @@ -645,12 +638,7 @@ impl CgroupWatcher { /// Set cgroup memory.high and memory.max. pub fn set_limits(&self, limits: &MemoryLimits) -> anyhow::Result<()> { - info!( - limits.high, - limits.max, - path = self.path(), - "writing new memory limits", - ); + info!(limits.high, path = self.path(), "writing new memory limits",); self.memory() .context("failed to get memory subsystem while setting memory limits")? .set_mem(cgroups_rs::memory::SetMemory { @@ -659,7 +647,7 @@ impl CgroupWatcher { high: Some(MaxValue::Value( u64::min(limits.high, i64::MAX as u64) as i64 )), - max: Some(MaxValue::Value(u64::min(limits.max, i64::MAX as u64) as i64)), + max: None, }) .context("failed to set memory limits") } @@ -667,7 +655,7 @@ impl CgroupWatcher { /// Given some amount of available memory, set the desired cgroup memory limits pub fn set_memory_limits(&mut self, available_memory: u64) -> anyhow::Result<()> { let new_high = self.config.calculate_memory_high_value(available_memory); - let limits = MemoryLimits::new(new_high, available_memory); + let limits = MemoryLimits { high: new_high }; info!( path = self.path(), memory = ?limits, diff --git a/libs/vm_monitor/src/runner.rs b/libs/vm_monitor/src/runner.rs index 8f904b879d..376017d784 100644 --- a/libs/vm_monitor/src/runner.rs +++ b/libs/vm_monitor/src/runner.rs @@ -257,12 +257,11 @@ impl Runner { new_cgroup_mem_high = cgroup.config.calculate_memory_high_value(available_memory); } - let limits = MemoryLimits::new( + let limits = MemoryLimits { // new_cgroup_mem_high is initialized to 0 but it is guarancontextd to not be here // since it is properly initialized in the previous cgroup if let block - new_cgroup_mem_high, - available_memory, - ); + high: new_cgroup_mem_high, + }; cgroup .set_limits(&limits) .context("failed to set cgroup memory limits")?; @@ -328,7 +327,9 @@ impl Runner { name = cgroup.path(), "updating cgroup memory.high", ); - let limits = MemoryLimits::new(new_cgroup_mem_high, available_memory); + let limits = MemoryLimits { + high: new_cgroup_mem_high, + }; cgroup .set_limits(&limits) .context("failed to set file cache size")?;