Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libcgroups v2 manager stats failed when no hugetlb releated files #2512

Open
Sherlock-Holo opened this issue Nov 7, 2023 · 3 comments
Open

Comments

@Sherlock-Holo
Copy link

if a cgroup doesn't contain hugetlb releated files, the v2 manager will fail with

Caused by:
0: io error: failed to read /sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/prctl-ttt/hugetlb.2MB.events: No such file or directory (os error 2)
1: failed to read /sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service/prctl-ttt/hugetlb.2MB.events: No such file or directory (os error 2)

@YJDoc2
Copy link
Collaborator

YJDoc2 commented Nov 7, 2023

Hey, thanks for reporting this. Can you also add your system information / setup and how you were running this, so we can try to reproduce?

@Sherlock-Holo
Copy link
Author

Sherlock-Holo commented Nov 7, 2023

I am using archlinux

uname -a

Linux sherlock 6.5.9-arch2-1 #1 SMP PREEMPT_DYNAMIC Thu, 26 Oct 2023 00:52:20 +0000 x86_64 GNU/Linux

pub fn show_cgroup_info<M>(manager: &M, name: &str) -> anyhow::Result<CgroupInfo>
where
    M: CgroupManager,
    M::Error: Error + Send + Sync + 'static,
{
    let stats = manager
        .stats()
        .with_context(|| format!("get cgroup {name} info failed"))?;
    let memory = (stats.memory.memory.limit != u64::MAX)
        .then(|| Byte::from_bytes(stats.memory.memory.limit as _));

    Ok(CgroupInfo {
        cpu: CpuInfo {
            cpu: MaxOrInt::Int(0),
        },
        memory: MemoryInfo { limit: memory },
    })
}

and when I call this function, I use the v2 manager implement

@xiaoyang-sde
Copy link
Contributor

xiaoyang-sde commented Nov 12, 2023

The stats method of libcgroups::v2::Manager assumes that all types of controller listed in CONTROLLER_TYPES are enabled in the cgroup it manages. Therefore, it will attempt to read the hugetlb.2MB.events file even if the hugetlb controller is not enabled.

fn stats(&self) -> Result<Stats, Self::Error> {
let mut stats = Stats::default();
for subsystem in CONTROLLER_TYPES {
match subsystem {
ControllerType::Cpu => stats.cpu = Cpu::stats(&self.full_path)?,
ControllerType::HugeTlb => stats.hugetlb = HugeTlb::stats(&self.full_path)?,
ControllerType::Pids => {
stats.pids = Pids::stats(&self.full_path).map_err(V2ManagerError::PidsStats)?
}
ControllerType::Memory => stats.memory = Memory::stats(&self.full_path)?,
ControllerType::Io => stats.blkio = Io::stats(&self.full_path)?,
_ => continue,
}
}
Ok(stats)
}

I think a potential solution is to implement a method similar to util::get_available_controllers, which reads the enabled controllers of the current cgroup, and then generate stats for these enabled controllers. (I'm willing to submit a pull request if this issue needs to be addressed.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants