mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-05 19:47:53 +00:00
kata-types: Optimize memory adjuesting by only gathering memory info
The Coniguration initialization was observed to be significantly slow due to the extensive system information gathering performed by `sysinfo::System::new_all()`. This function collects data on CPU, memory, disks, and network, most of which is unnecessary for Kata's memory adjusting config phase, where only the total system memory is required. This commit optimizes the initialization process by implementing a more targeted approach to retrieve only the total system memory. This avoids the overhead of collecting a large amount of irrelevant data, resulting in a noticeable performance improvement. Fixes #11165 Signed-off-by: alex.lyn <alex.lyn@antgroup.com>
This commit is contained in:
parent
bf93b5daf1
commit
97a1942f86
@ -26,7 +26,7 @@ serde_json = "1.0.73"
|
||||
thiserror = "1.0"
|
||||
toml = "0.5.8"
|
||||
serde-enum-str = "0.4"
|
||||
sysinfo = "0.30.5"
|
||||
sysinfo = "0.34.2"
|
||||
|
||||
oci-spec = { version = "0.6.8", features = ["runtime"] }
|
||||
safe-path = { path = "../safe-path" }
|
||||
|
@ -33,7 +33,7 @@ use std::collections::HashMap;
|
||||
use std::io::{self, Result};
|
||||
use std::path::Path;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use sysinfo::System;
|
||||
use sysinfo::{MemoryRefreshKind, RefreshKind, System};
|
||||
|
||||
mod dragonball;
|
||||
pub use self::dragonball::{DragonballConfig, HYPERVISOR_NAME_DRAGONBALL};
|
||||
@ -751,7 +751,9 @@ impl MemoryInfo {
|
||||
"Memory backend file {} is invalid: {}"
|
||||
)?;
|
||||
if self.default_maxmemory == 0 {
|
||||
let s = System::new_all();
|
||||
let s = System::new_with_specifics(
|
||||
RefreshKind::nothing().with_memory(MemoryRefreshKind::everything()),
|
||||
);
|
||||
self.default_maxmemory = Byte::from_u64(s.total_memory())
|
||||
.get_adjusted_unit(Unit::MiB)
|
||||
.get_value() as u32;
|
||||
|
Loading…
Reference in New Issue
Block a user