Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ pub struct ExecutableSpec {
/// Requires `no_new_privs = true`.
#[serde(default)]
pub seccomp: Option<SeccompFilter>,

/// An optional out-of-memory score adjustment value.
pub oom_score_adj: Option<i32>,
}

#[derive(Default, Debug, Serialize, Deserialize)]
Expand Down
10 changes: 10 additions & 0 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ impl AttachRequestBuilder {
self
}

pub fn set_oom_score_adj(mut self, score: i32) -> AttachRequestBuilder {
self.config.exec.oom_score_adj = Some(score);
self
}

pub fn push_namespace(mut self, ns: Namespace) -> AttachRequestBuilder {
if self.config.namespaces.is_none() {
self.config.namespaces = vec![].into();
Expand Down Expand Up @@ -211,6 +216,11 @@ impl CreateRequestBuilder {
self
}

pub fn set_oom_score_adj(mut self, score: i32) -> CreateRequestBuilder {
self.config.exec.oom_score_adj = Some(score);
self
}

pub fn set_hostname(mut self, hostname: &str) -> CreateRequestBuilder {
self.config.hostname = hostname.to_string().into();
self
Expand Down
13 changes: 13 additions & 0 deletions src/wrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,15 @@ impl Wrappable for CreateRequest {

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

// Ensure the process receives the desired out-of-memory score adjustment.
// If not specified, we do want to pro-actively set this value to the
// kernel-default of zero, else the subprocess inherits the styrolite
// oom score (which is typically set to a very low value).
fs::write(
"/proc/self/oom_score_adj",
self.exec.oom_score_adj.unwrap_or(0).to_string(),
)?;

// We need to toggle SECBIT before we change UID/GID,
// or else changing UID/GID may cause us to lose the capabilities
// we need to explicitly drop capabilities later on.
Expand Down Expand Up @@ -841,6 +850,10 @@ impl Wrappable for AttachRequest {

apply_capabilities(self.capabilities.as_ref())?;

if let Some(score) = self.exec.oom_score_adj {
fs::write("/proc/self/oom_score_adj", score.to_string())?;
}

debug!("all namespaces joined -- forking child");
fork_and_wait()?;

Expand Down
Loading