Skip to content

Commit

Permalink
schnauzer: extend oci_defaults helper to apply higher MEMLOCK limits …
Browse files Browse the repository at this point in the history
…when EFA is attached

Signed-off-by: Yutong Sun <[email protected]>
  • Loading branch information
ytsssun committed Sep 13, 2024
1 parent 04702ec commit fab7d74
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions sources/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sources/api/schnauzer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ log.workspace = true
maplit.workspace = true
models.workspace = true
num_cpus.workspace = true
pciclient.workspace = true
percent-encoding.workspace = true
pest.workspace = true
pest_derive.workspace = true
Expand Down
19 changes: 18 additions & 1 deletion sources/api/schnauzer/src/helpers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ mod error {
source: std::net::AddrParseError,
},

#[snafu(display("Failed to check if EFA device is attached: {}", source))]
CheckEfaFailure { source: pciclient::Error },

#[snafu(display(
"Expected an absolute URL, got '{}' in template '{}': '{}'",
url_str,
Expand Down Expand Up @@ -1311,7 +1314,21 @@ fn oci_spec_capabilities(value: &Value) -> Result<String, RenderError> {
fn oci_spec_resource_limits(
value: &Value,
) -> Result<HashMap<OciDefaultsResourceLimitType, OciDefaultsResourceLimitV1>, RenderError> {
Ok(serde_json::from_value(value.clone())?)
let mut rlimits: HashMap<OciDefaultsResourceLimitType, OciDefaultsResourceLimitV1> =
serde_json::from_value(value.clone())?;
if !rlimits.contains_key(&OciDefaultsResourceLimitType::MaxLockedMemory) {
if pciclient::is_efa_attached().context(error::CheckEfaFailureSnafu)? {
let max_locked_memory_limits = OciDefaultsResourceLimitV1 {
soft_limit: -1,
hard_limit: -1,
};
rlimits.insert(
OciDefaultsResourceLimitType::MaxLockedMemory,
max_locked_memory_limits,
);
}
}
Ok(rlimits)
}

// =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
Expand Down

0 comments on commit fab7d74

Please sign in to comment.