Skip to content

Commit bbe4159

Browse files
authored
LinuxContainer: Give a bit of overhead memory (#472)
The guest agent isn't free, and today we were sizing the VMs memory allotment and the containers cgroup to the same value. This change gives some overhead memory to the VM (50MB for now) for the guest agent.
1 parent 8446f89 commit bbe4159

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

Sources/Containerization/LinuxContainer.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,22 @@ extension LinuxContainer {
404404
var modifiedRootfs = self.rootfs
405405
modifiedRootfs.options.removeAll(where: { $0 == "ro" })
406406

407+
// Calculate VM memory with overhead for the guest agent.
408+
// The container cgroup limit stays at the requested memory, but the VM
409+
// gets an additional 50MB for the guest agent (could be higher, could be lower
410+
// but this is a decent baseline for now).
411+
//
412+
// Clamp to system RAM if the total would exceed it as Virtualization.framework
413+
// bounds us to this.
414+
let guestAgentOverhead: UInt64 = 50.mib()
415+
let vmMemory = min(
416+
self.memoryInBytes + guestAgentOverhead,
417+
ProcessInfo.processInfo.physicalMemory
418+
)
419+
407420
let vmConfig = VMConfiguration(
408421
cpus: self.cpus,
409-
memoryInBytes: self.memoryInBytes,
422+
memoryInBytes: vmMemory,
410423
interfaces: self.interfaces,
411424
mountsByID: [self.id: [modifiedRootfs] + self.config.mounts],
412425
bootLog: self.config.bootLog,

0 commit comments

Comments
 (0)