mirror of
https://github.com/apple/container.git
synced 2026-10-18 12:09:10 +00:00
Set memory.low for vminitd to avoid kernel reclaiming its memory (#682)
Sets `memory.low` for `vminitd` cgroup to make kernel avoid reclaiming its memory under high memory pressure. Even if the container process runs in memory cgroup, consuming lots of page cache can lead to reclaiming `vminitd`'s page cache memory , which hangs the `vminitd`. Setting `memory.low` makes kernel avoid reclaiming `vminitd`'s page so that we can guarantee the proper `vminitd` operation under high memory pressure.
This commit is contained in:
1 parent
833b07f4f5
commit
de58d1dd09
2 files changed
+23
-4
No files matched your search
@@ -252,6 +252,21 @@ package struct Cgroup2Manager: Sendable {
|
||||
)
|
||||
}
|
||||
|
||||
package func setMemoryLow(bytes: UInt64) throws {
|
||||
self.logger?.debug(
|
||||
"setting memory.low",
|
||||
metadata: [
|
||||
"path": "\(self.path.path)",
|
||||
"bytes": "\(bytes)",
|
||||
]
|
||||
)
|
||||
|
||||
try Self.writeValue(
|
||||
path: self.path,
|
||||
value: String(bytes),
|
||||
fileName: "memory.low")
|
||||
}
|
||||
|
||||
package func getMemoryEvents() throws -> MemoryEvents {
|
||||
let content = try readFileContent(fileName: "memory.events")
|
||||
let values = parseKeyValuePairs(content)
|
||||
|
||||
@@ -123,19 +123,23 @@ struct AgentCommand: AsyncParsableCommand {
|
||||
try cgManager.toggleAllAvailableControllers(enable: true)
|
||||
|
||||
// Set memory.high threshold to 75 MiB
|
||||
let threshold: UInt64 = 75 * 1024 * 1024
|
||||
try cgManager.setMemoryHigh(bytes: threshold)
|
||||
let high: UInt64 = 75 * 1024 * 1024
|
||||
// Set memory.low to 50 MiB to avoid reclaiming vminitd's memory
|
||||
let low: UInt64 = 50 * 1024 * 1024
|
||||
|
||||
try cgManager.setMemoryHigh(bytes: high)
|
||||
try cgManager.setMemoryLow(bytes: low)
|
||||
try cgManager.addProcess(pid: getpid())
|
||||
|
||||
let memoryMonitor = try MemoryMonitor(
|
||||
cgroupManager: cgManager,
|
||||
threshold: threshold,
|
||||
threshold: high,
|
||||
logger: log
|
||||
) { [log] (currentUsage, highMark) in
|
||||
log.warning(
|
||||
"vminitd memory threshold exceeded",
|
||||
metadata: [
|
||||
"threshold_bytes": "\(threshold)",
|
||||
"threshold_bytes": "\(high)",
|
||||
"current_bytes": "\(currentUsage)",
|
||||
"high_events_total": "\(highMark)",
|
||||
])
|
||||
|
||||
Reference in new issue
Block a user