sys: cope with unavailable KSM sharing info

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2023-02-02 16:12:15 +01:00
parent 2cebe420c1
commit ce389914ff

View File

@ -455,8 +455,11 @@ pub fn read_meminfo() -> Result<ProcFsMemInfo, Error> {
meminfo.swapused = meminfo.swaptotal - meminfo.swapfree;
let spages_line = file_read_firstline("/sys/kernel/mm/ksm/pages_sharing")?;
meminfo.memshared = spages_line.trim_end().parse::<u64>()? * 4096;
meminfo.memshared = match file_read_firstline("/sys/kernel/mm/ksm/pages_sharing") {
Ok(spages_line) => spages_line.trim_end().parse::<u64>()? * 4096,
Err(err) if err.kind() == std::io::ErrorKind::NotFound => 0,
Err(err) => return Err(err),
};
Ok(meminfo)
}