Compare commits

...

10 Commits

Author SHA1 Message Date
Fupan Li
91e66f0197 Merge pull request #83 from Tim-Zhang/release-0.2.10
release: v0.2.10
2022-06-29 16:48:56 +08:00
Tim Zhang
3340211c6e release: v0.2.10
Release version 0.2.10

Signed-off-by: Tim Zhang <tim@hyper.sh>
2022-06-29 16:44:00 +08:00
Tim Zhang
bd31dc0e7d Merge pull request #82 from dubek/ignore-set-kmem-limit-unsupported
memory: set_kmem_limit: ignore Unsupported error
2022-06-29 10:21:49 +08:00
Dov Murik
0c908cddf8 memory: set_kmem_limit: ignore Unsupported error
Setting (writing into) `memory.kmem.limit_in_bytes` is not supported in
Linux kernel >= 5.16 (see kernel commit 58056f77502: "memcg, kmem:
further deprecate kmem.limit_in_bytes"):
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=58056f77502

If the write call in `set_kmem_limit()` returns EOPNOTSUPP, log a
warning message but ignore the error (do nothing).

Add a unit-test for `set_kmem_limit` in cgroups v1.

Fix #81

Signed-off-by: Dov Murik <dov.murik1@il.ibm.com>
2022-06-27 08:29:40 +00:00
Tim Zhang
556dea62b9 Merge pull request #78 from esrlabs/pr-clippy
clippy: Fix clippy version 0.1.60
2022-06-01 18:50:25 +08:00
Bin Liu
1a8f9823eb Merge pull request #79 from esrlabs/pr-android
fix: build for aarch64-linux-android
2022-05-25 23:01:33 +08:00
Bin Liu
dda639f5ab Merge pull request #77 from rtzoeller/nix_0.24
Upgrade nix to 0.24, limit features
2022-05-25 22:58:46 +08:00
Ryan Zoeller
476219ab93 Upgrade nix to 0.24, limit features
This removes memoffset as an indirect dependency, and should decrease build times slightly.

Signed-off-by: Ryan Zoeller <rtzoeller@rtzoeller.com>
2022-04-30 18:37:57 -05:00
Felix Obenhuber
138c85c4b1 fix: build for aarch64-linux-android
With #77 nix provides statfs::CGROUP2_SUPER_MAGIC for the target_os
"android". Fix the build build for `target_os = "android"` by adding
this cfg setting to the "linux and not musl" impl of
`is_cgroup2_unified_mode`.

This patch depends opn #77 beeing merged.

Signed-off-by: Felix Obenhuber <felix@obenhuber.de>
2022-04-28 16:39:58 +02:00
Felix Obenhuber
92122de48d clippy: Fix clippy version 0.1.60
Fix clippy lints from clippy 0.1.60 (7737e0b 2022-04-04).

Signed-off-by: Felix Obenhuber <felix@obenhuber.de>
2022-04-28 16:36:57 +02:00
10 changed files with 47 additions and 24 deletions

View File

@@ -5,7 +5,7 @@ repository = "https://github.com/kata-containers/cgroups-rs"
keywords = ["linux", "cgroup", "containers", "isolation"]
categories = ["os", "api-bindings", "os::unix-apis"]
license = "MIT OR Apache-2.0"
version = "0.2.9"
version = "0.2.10"
authors = ["The Kata Containers community <kata-dev@lists.katacontainers.io>", "Levente Kurusa <lkurusa@acm.org>", "Sam Wilson <tecywiz121@hotmail.com>"]
edition = "2018"
homepage = "https://github.com/kata-containers/cgroups-rs"
@@ -14,7 +14,7 @@ readme = "README.md"
[dependencies]
log = "0.4"
regex = "1.1"
nix = "0.23.0"
nix = { version = "0.24", default-features = false, features = ["event", "fs", "process"] }
libc = "0.2"
serde = { version = "1.0", features = ["derive"], optional = true }

View File

@@ -295,7 +295,7 @@ fn parse_cfs_quota_and_period(mut file: File) -> Result<CfsQuotaAndPeriod> {
return Err(Error::from_string(format!("invaild format: {}", content)));
}
let quota = parse_max_value(&fields[0].to_string())?;
let quota = parse_max_value(fields[0])?;
let period = fields[1]
.parse::<u64>()
.map_err(|e| Error::with_cause(ParseError, e))?;

View File

@@ -52,12 +52,11 @@ fn register_memory_event(
eventfd(0, EfdFlags::EFD_CLOEXEC).map_err(|e| Error::with_cause(ReadFailed, e))?;
let event_control_path = cg_dir.join("cgroup.event_control");
let data;
if arg.is_empty() {
data = format!("{} {}", eventfd, event_file.as_raw_fd());
let data = if arg.is_empty() {
format!("{} {}", eventfd, event_file.as_raw_fd())
} else {
data = format!("{} {} {}", eventfd, event_file.as_raw_fd(), arg);
}
format!("{} {} {}", eventfd, event_file.as_raw_fd(), arg)
};
// write to file and set mode to 0700(FIXME)
fs::write(&event_control_path, data).map_err(|e| Error::with_cause(WriteFailed, e))?;

View File

@@ -170,7 +170,7 @@ impl Hierarchy for V1 {
}
fn root_control_group(&self) -> Cgroup {
Cgroup::load(auto(), "".to_string())
Cgroup::load(auto(), "")
}
fn root(&self) -> PathBuf {
@@ -246,7 +246,7 @@ impl Hierarchy for V2 {
}
fn root_control_group(&self) -> Cgroup {
Cgroup::load(auto(), "".to_string())
Cgroup::load(auto(), "")
}
fn root(&self) -> PathBuf {
@@ -297,7 +297,10 @@ impl Default for V2 {
pub const UNIFIED_MOUNTPOINT: &str = "/sys/fs/cgroup";
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
#[cfg(any(
all(target_os = "linux", not(target_env = "musl")),
target_os = "android"
))]
pub fn is_cgroup2_unified_mode() -> bool {
use nix::sys::statfs;

View File

@@ -771,7 +771,7 @@ impl fmt::Display for MaxValue {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
MaxValue::Max => write!(f, "max"),
MaxValue::Value(num) => write!(f, "{}", num.to_string()),
MaxValue::Value(num) => write!(f, "{}", num),
}
}
}

View File

@@ -8,6 +8,7 @@
//!
//! See the Kernel's documentation for more information about this subsystem, found at:
//! [Documentation/cgroup-v1/memory.txt](https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt)
use log::warn;
use std::collections::HashMap;
use std::io::Write;
use std::path::PathBuf;
@@ -840,8 +841,15 @@ impl MemController {
self.open_path("memory.kmem.limit_in_bytes", true)
.and_then(|mut file| {
file.write_all(limit.to_string().as_ref())
.map_err(|e| Error::with_cause(WriteFailed, e))
let r = file.write_all(limit.to_string().as_ref());
match r {
Ok(()) => Ok(()),
Err(ref e) if e.raw_os_error() == Some(libc::EOPNOTSUPP) => {
warn!("memory.kmem.limit_in_bytes is unsupported by the kernel");
Ok(())
}
Err(e) => Err(Error::with_cause(WriteFailed, e)),
}
})
}

View File

@@ -17,7 +17,7 @@ use crate::{ControllIdentifier, ControllerInternal, Controllers, Resources, Subs
pub struct SystemdController {
base: PathBuf,
path: PathBuf,
v2: bool,
_v2: bool,
}
impl ControllerInternal for SystemdController {
@@ -66,7 +66,7 @@ impl SystemdController {
Self {
base: root.clone(),
path: root,
v2,
_v2: v2,
}
}
}

View File

@@ -47,7 +47,8 @@ pub fn test_memory_res_build() {
{
let c: &MemController = cg.controller_of().unwrap();
if !c.v2() {
assert_eq!(c.kmem_stat().limit_in_bytes, 128 * 1024 * 1024);
// Note: we don't tests the value of c.kmem_stat().limit_in_bytes because on Linux
// kernel >= 5.16 setting this value is unsupported.
assert_eq!(c.memory_stat().swappiness, 70);
}
assert_eq!(c.memory_stat().limit_in_bytes, 1024 * 1024 * 1024);
@@ -137,11 +138,8 @@ pub fn test_hugepages_res_build() {
{
let c: &HugeTlbController = cg.controller_of().unwrap();
assert!(c.limit_in_bytes(&"2MB".to_string()).is_ok());
assert_eq!(
c.limit_in_bytes(&"2MB".to_string()).unwrap(),
4 * 2 * 1024 * 1024
);
assert!(c.limit_in_bytes("2MB").is_ok());
assert_eq!(c.limit_in_bytes("2MB").unwrap(), 4 * 2 * 1024 * 1024);
}
cg.delete().unwrap();
}

View File

@@ -40,5 +40,5 @@ fn test_hugetlb_sizes() {
}
fn assert_no_error(r: Result<u64>) {
assert!(!r.is_err())
assert!(r.is_ok())
}

View File

@@ -23,7 +23,7 @@ fn test_disable_oom_killer() {
if !mem_controller.v2() {
// disable oom killer
let r = mem_controller.disable_oom_killer();
assert!(!r.is_err());
assert!(r.is_ok());
// after disable
let m = mem_controller.memory_stat();
@@ -33,6 +33,21 @@ fn test_disable_oom_killer() {
cg.delete().unwrap();
}
#[test]
fn set_kmem_limit_v1() {
let h = cgroups_rs::hierarchies::auto();
if h.v2() {
return;
}
let cg = Cgroup::new(h, String::from("set_kmem_limit_v1"));
{
let mem_controller: &MemController = cg.controller_of().unwrap();
mem_controller.set_kmem_limit(1).unwrap();
}
cg.delete().unwrap();
}
#[test]
fn set_mem_v2() {
let h = cgroups_rs::hierarchies::auto();