// ConvertMemorySwapToCgroupV2Value converts MemorySwap value from OCI spec
// for use by cgroup v2 drivers. A conversion is needed since Resources.MemorySwap
// is defined as memory+swap combined, while in cgroup v2 swap is a separate value.
ConvertMemorySwapToCgroupV2Value converts MemorySwap value from OCI spec
for use by cgroup v2 drivers. A conversion is needed since Resources.MemorySwap
is defined as memory+swap combined, while in cgroup v2 swap is a separate value.
ConvertMemorySwapToCgroupV2Value converts MemorySwap value from OCI spec for use by cgroup v2 drivers . A conversion is needed since Resources . MemorySwap is defined as memory + swap combined while in cgroup v2 swap is a separate value .
fn convert_memory_swap_to_v2_value(memory_swap: i64, memory: i64) -> Result<i64> {
    // for compatibility with cgroup1 controller, set swap to unlimited in
    // case the memory is set to unlimited, and swap is not explicitly set,
    // treating the request as "set both memory and swap to unlimited".
    if memory == -1 && memory_swap == 0 {
        return Ok(-1);
    }
    if memory_swap == -1 || memory_swap == 0 {
        // -1 is "max", 0 is "unset", so treat as is
        return Ok(memory_swap);
    }
    // sanity checks
    if memory == 0 || memory == -1 {
        return Err(anyhow!("unable to set swap limit without memory limit"));
    }
    if memory < 0 {
        return Err(anyhow!("invalid memory value: {}", memory));
    }
    if memory_swap < memory {
        return Err(anyhow!("memory+swap limit should be >= memory limit"));
    }
    Ok(memory_swap - memory)
}
fn convert_memory_swap_to_v2_value ( memory_swap : i64 , memory : i64 ) -> Result < i64 > { // for compatibility with cgroup1 controller, set swap to unlimited in // case the memory is set to unlimited, and swap is not explicitly set, // treating the request as "set both memory and swap to unlimited". if memory == - 1 && memory_swap == 0 { return Ok ( - 1 ) ; } if memory_swap == - 1 || memory_swap == 0 { // -1 is "max", 0 is "unset", so treat as is return Ok ( memory_swap ) ; } // sanity checks if memory == 0 || memory == - 1 { return Err ( anyhow ! ( " " ) ) ; } if memory < 0 { return Err ( anyhow ! ( " " memory ) ) ; } if memory_swap < memory { return Err ( anyhow ! ( " " ) ) ; } Ok ( memory_swap - memory ) }
ConvertMemorySwapToCgroupV2Value converts MemorySwap value from OCI spec
for use by cgroup v2 drivers.
ConvertMemorySwapToCgroupV2Value converts MemorySwap value from OCI spec for use by cgroup v2 drivers .
memory_swap
i64
memory
i64