cgroups_rs/systemd/
memory.rs1use crate::systemd::error::{Error, Result};
7use crate::systemd::{MEMORY_LIMIT, MEMORY_LOW, MEMORY_MAX, MEMORY_SWAP_MAX};
8
9pub fn limit(limit: i64, v2: bool) -> Result<(&'static str, u64)> {
11 let id = if v2 { MEMORY_MAX } else { MEMORY_LIMIT };
12
13 Ok((id, limit as u64))
14}
15
16pub fn low(low: i64, v2: bool) -> Result<(&'static str, u64)> {
18 if !v2 {
19 return Err(Error::CgroupsV1NotSupported);
20 }
21
22 Ok((MEMORY_LOW, low as u64))
23}
24
25pub fn swap(swap: i64, v2: bool) -> Result<(&'static str, u64)> {
27 if !v2 {
28 return Err(Error::CgroupsV1NotSupported);
29 }
30
31 Ok((MEMORY_SWAP_MAX, swap as u64))
32}