Skip to content
Open
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
26 changes: 14 additions & 12 deletions vminitd/Sources/Cgroup/Cgroup2Manager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,29 +206,31 @@ package struct Cgroup2Manager: Sendable {
])

if let memory = resources.memory, let limit = memory.limit {
// The OCI spec defines -1 as unlimited; cgroup v2 expects "max".
let value = limit < 0 ? "max" : String(limit)
try Self.writeValue(
path: self.path,
value: String(limit),
value: value,
fileName: "memory.max"
)
}

if let cpu = resources.cpu {
if let quota = cpu.quota, let period = cpu.period {
// cpu.max format is "quota period"
let value = "\(quota) \(period)"
try Self.writeValue(
path: self.path,
value: value,
fileName: "cpu.max"
)
}
if let cpu = resources.cpu, let quota = cpu.quota, let period = cpu.period {
// cpu.max format is "quota period"
let value = "\(quota) \(period)"
try Self.writeValue(
path: self.path,
value: value,
fileName: "cpu.max"
)
}

if let pids = resources.pids {
// The OCI spec defines -1 as unlimited; cgroup v2 expects "max".
let value = pids.limit < 0 ? "max" : String(pids.limit)
try Self.writeValue(
path: self.path,
value: String(pids.limit),
value: value,
fileName: "pids.max"
)
}
Expand Down
Loading