Skip to content

Commit ab8e549

Browse files
bug(wrap): add oom_score_adj to exec specs
This value can be forwarded from a CRI and ensures an appropriate OOM score is set for processes in cases where high memory use is seen. Signed-off-by: Alexander Merritt <alexander@edera.dev>
1 parent 17e5773 commit ab8e549

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

src/config.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ pub struct ExecutableSpec {
8585
/// Requires `no_new_privs = true`.
8686
#[serde(default)]
8787
pub seccomp: Option<SeccompFilter>,
88+
89+
/// An optional out-of-memory score adjustment value.
90+
pub oom_score_adj: Option<i32>,
8891
}
8992

9093
#[derive(Default, Debug, Serialize, Deserialize)]

src/runner.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,11 @@ impl CreateRequestBuilder {
211211
self
212212
}
213213

214+
pub fn set_oom_score_adj(mut self, score: i32) -> CreateRequestBuilder {
215+
self.config.exec.oom_score_adj = Some(score);
216+
self
217+
}
218+
214219
pub fn set_hostname(mut self, hostname: &str) -> CreateRequestBuilder {
215220
self.config.hostname = hostname.to_string().into();
216221
self

src/wrap.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,12 @@ impl Wrappable for CreateRequest {
639639

640640
debug!("mount tree finalized, doing final prep");
641641

642+
// Ensure the process receives the desired out-of-memory score adjustment.
643+
// If not specified, we do want to pro-actively set this value to the
644+
// kernel-default of zero, else the subprocess inherits the styrolite
645+
// oom score (which is typcially set to a very low value).
646+
fs::write("/proc/self/oom_score_adj", self.exec.oom_score_adj.unwrap_or(0).to_string())?;
647+
642648
// We need to toggle SECBIT before we change UID/GID,
643649
// or else changing UID/GID may cause us to lose the capabilities
644650
// we need to explicitly drop capabilities later on.

0 commit comments

Comments
 (0)