authorgravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-11-01 23:23:05+01:00
committergravatar for 14938807+xackus@users.noreply.github.comxackus <14938807+xackus@users.noreply.github.com> 2020-11-01 23:32:25+01:00
log7703f4c60a501c4f4bc74c7d814619aa818d601b
tree6f5e7629712bbf6e758f551a87af44a4b2414677
parent2e1cef75086a0b606fd8f1f7a0cda4ab2f0b7a49

stage2: ask for more file descriptors


2 files changed, 19 insertions(+), 48 deletions(-)

src/main.zig+19-25
...@@ -2982,35 +2982,29 @@ fn parseCodeModel(arg: []const u8) std.builtin.CodeModel {...@@ -2982,35 +2982,29 @@ fn parseCodeModel(arg: []const u8) std.builtin.CodeModel {
2982/// garbage collector to run concurrently to zig processes, and to allow multiple2982/// garbage collector to run concurrently to zig processes, and to allow multiple
2983/// zig processes to run concurrently with each other, without clobbering each other.2983/// zig processes to run concurrently with each other, without clobbering each other.
2984fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {2984fn gimmeMoreOfThoseSweetSweetFileDescriptors() void {
2985 switch (std.Target.current.os.tag) {2985 if (!@hasDecl(std.os, "rlimit")) return;
2986 .windows, .wasi, .uefi, .other, .freestanding => return,
2987 // std lib is missing getrlimit/setrlimit.
2988 // https://github.com/ziglang/zig/issues/6361
2989 //else => {},
2990 else => return,
2991 }
2992 const posix = std.os;2986 const posix = std.os;
2993 var lim = posix.getrlimit(posix.RLIMIT_NOFILE, &lim) catch return; // Oh well; we tried.2987
2988 var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried.
2994 if (lim.cur == lim.max) return;2989 if (lim.cur == lim.max) return;
2990
2991 // Do a binary search for the limit.
2992 var min: posix.rlim_t = lim.cur;
2993 var max: posix.rlim_t = 1 << 20;
2994 // But if there's a defined upper bound, don't search, just set it.
2995 if (lim.max != posix.RLIM_INFINITY) {
2996 min = lim.max;
2997 max = lim.max;
2998 }
2999
2995 while (true) {3000 while (true) {
2996 // Do a binary search for the limit.3001 lim.cur = min + (max - min) / 2;
2997 var min: posix.rlim_t = lim.cur;3002 if (posix.setrlimit(.NOFILE, lim)) |_| {
2998 var max: posix.rlim_t = 1 << 20;3003 min = lim.cur;
2999 // But if there's a defined upper bound, don't search, just set it.3004 } else |_| {
3000 if (lim.max != posix.RLIM_INFINITY) {3005 max = lim.cur;
3001 min = lim.max;
3002 max = lim.max;
3003 }
3004 while (true) {
3005 lim.cur = min + (max - min) / 2;
3006 if (posix.setrlimit(posix.RLIMIT_NOFILE, lim)) |_| {
3007 min = lim.cur;
3008 } else |_| {
3009 max = lim.cur;
3010 }
3011 if (min + 1 < max) continue;
3012 return;
3013 }3006 }
3007 if (min + 1 >= max) break;
3014 }3008 }
3015}3009}
30163010
src/stage1/os.cpp-23
...@@ -977,29 +977,6 @@ int os_init(void) {...@@ -977,29 +977,6 @@ int os_init(void) {
977#elif defined(__MACH__)977#elif defined(__MACH__)
978 host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &macos_monotonic_clock);978 host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &macos_monotonic_clock);
979 host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &macos_calendar_clock);979 host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &macos_calendar_clock);
980#endif
981#if defined(ZIG_OS_POSIX)
982 // Raise the open file descriptor limit.
983 // Code lifted from node.js
984 struct rlimit lim;
985 if (getrlimit(RLIMIT_NOFILE, &lim) == 0 && lim.rlim_cur != lim.rlim_max) {
986 // Do a binary search for the limit.
987 rlim_t min = lim.rlim_cur;
988 rlim_t max = 1 << 20;
989 // But if there's a defined upper bound, don't search, just set it.
990 if (lim.rlim_max != RLIM_INFINITY) {
991 min = lim.rlim_max;
992 max = lim.rlim_max;
993 }
994 do {
995 lim.rlim_cur = min + (max - min) / 2;
996 if (setrlimit(RLIMIT_NOFILE, &lim)) {
997 max = lim.rlim_cur;
998 } else {
999 min = lim.rlim_cur;
1000 }
1001 } while (min + 1 < max);
1002 }
1003#endif980#endif
1004 return 0;981 return 0;
1005}982}