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

Set Linux sysctl defaults for vm configuration #156

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions vmm/task/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,39 @@ async fn handle_signals(signals: Signals) {
}
}

lazy_static! {
static ref DEFAULT_SYSCTL: HashMap<&'static str, &'static str> = {
let mut map = HashMap::new();

// Enable memory hierarchical account.
// For more information see https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt
map.insert("/sys/fs/cgroup/memory/memory.use_hierarchy", "1");

// Set overcommit_memory to 1, allowing the kernel to overcommit memory,
// allocate more memory than is physically available
map.insert("/proc/sys/vm/overcommit_memory", "1");

// Enable automatic expiration of nodest connections
map.insert("/proc/sys/net/ipv4/vs/expire_nodest_conn", "1");
map
};
}

async fn init_vm_rootfs() -> Result<()> {
let mounts = VM_ROOTFS_MOUNTS.clone();
mount_static_mounts(mounts).await?;
// has to mount /proc before find cgroup mounts
let cgroup_mounts = get_cgroup_mounts(PROC_CGROUPS, false).await?;
mount_static_mounts(cgroup_mounts).await?;
// Enable memory hierarchical account.
// For more information see https://www.kernel.org/doc/Documentation/cgroup-v1/memory.txt
tokio::fs::write("/sys/fs/cgroup/memory/memory.use_hierarchy", "1")
.await
.map_err(io_error!(e, "failed to set cgroup hierarchy to 1"))

// Set default sysctl
for sysctl in DEFAULT_SYSCTL.iter() {
tokio::fs::write(&sysctl.0, &sysctl.1)
.await
.map_err(io_error!(e, "failed to set cgroup hierarchy to 1"))?;
}

Ok(())
}

// Continue to do initialization that depend on shared path.
Expand Down
Loading