Skip to content

Commit 97dd633

Browse files
committed
vminitd: Set nofile rlimit to max
Not sure why we had this at 65k.
1 parent db113ff commit 97dd633

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

vminitd/Sources/vminitd/InitCommand.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ struct InitCommand {
3434

3535
static func run(log: Logger) async throws {
3636
var log = log
37-
38-
try Self.adjustLimits()
37+
try Self.adjustLimits(log)
3938

4039
// when running under debug mode, launch vminitd as a sub process of pid1
4140
// so that we get a chance to collect better logs and errors before pid1 exists
@@ -170,13 +169,14 @@ struct InitCommand {
170169
log.info("child process exited with code: \(exitCode)")
171170
}
172171

173-
private static func adjustLimits() throws {
174-
var limits = rlimit()
175-
guard getrlimit(RLIMIT_NOFILE, &limits) == 0 else {
176-
throw POSIXError(.init(rawValue: errno)!)
172+
private static func adjustLimits(_ log: Logger) throws {
173+
let nrOpen = try String(contentsOfFile: "/proc/sys/fs/nr_open", encoding: .utf8)
174+
.trimmingCharacters(in: .whitespacesAndNewlines)
175+
guard let max = rlim_t(nrOpen) else {
176+
throw POSIXError(.EINVAL)
177177
}
178-
limits.rlim_cur = 65536
179-
limits.rlim_max = 65536
178+
log.debug("setting RLIMIT_NOFILE to \(max)")
179+
var limits = rlimit(rlim_cur: max, rlim_max: max)
180180
guard setrlimit(RLIMIT_NOFILE, &limits) == 0 else {
181181
throw POSIXError(.init(rawValue: errno)!)
182182
}

0 commit comments

Comments
 (0)