Compare commits

...

4 Commits

Author SHA1 Message Date
Meghan Denny
0753741181 Merge branch 'main' into nektro-patch-32447 2024-11-19 02:28:52 -08:00
Meghan Denny
c7a7dd0521 bad copy/paste 2024-11-16 03:23:23 -08:00
Meghan Denny
eca4c9720c only reassign file_limit if setrlimit succeeds 2024-11-16 03:09:51 -08:00
Meghan Denny
72a058706b zig: always set a reasonable NOFILE rlimit max 2024-11-16 03:03:48 -08:00

View File

@@ -797,26 +797,34 @@ pub const FileSystem = struct {
return std.math.maxInt(usize);
}
const LIMITS = [_]std.posix.rlimit_resource{ std.posix.rlimit_resource.STACK, std.posix.rlimit_resource.NOFILE };
inline for (LIMITS, 0..) |limit_type, i| {
const limit = try std.posix.getrlimit(limit_type);
blk: {
const resource = std.posix.rlimit_resource.STACK;
const limit = try std.posix.getrlimit(resource);
if (limit.cur < limit.max) {
var new_limit = std.mem.zeroes(std.posix.rlimit);
new_limit.cur = limit.max;
new_limit.max = limit.max;
if (std.posix.setrlimit(limit_type, new_limit)) {
if (i == 1) {
Limit.handles = limit.max;
} else {
Limit.stack = limit.max;
}
} else |_| {}
std.posix.setrlimit(resource, new_limit) catch break :blk;
Limit.stack = limit.max;
}
if (i == LIMITS.len - 1) return limit.max;
}
var file_limit: usize = 0;
blk: {
const resource = std.posix.rlimit_resource.NOFILE;
const limit = try std.posix.getrlimit(resource);
file_limit = limit.max;
if (limit.cur < limit.max or limit.max < 163840) {
var new_limit = std.mem.zeroes(std.posix.rlimit);
new_limit.cur = @max(limit.max, 163840);
new_limit.max = @max(limit.max, 163840);
std.posix.setrlimit(resource, new_limit) catch break :blk;
file_limit = new_limit.max;
Limit.handles = file_limit;
}
}
return file_limit;
}
var _entries_option_map: *EntriesOption.Map = undefined;