| author | |
| committer | |
| log | 8dda64fa3e1d3249baa948dc0558e3f65d71e6df |
| tree | beceee28f51886280f8ede8caffb1475ad5e3edf |
| parent | 06b4526a3e15d776437cdcf45d76ed34c6c39272 |
| signature |
On Darwin, according to the man pages for setrlimit(), when adjusting
max number of open fds, the reported hard max by getrlimit() is only
theoretical, while the actual maximum, set in the kernel, is hardcoded
in the header file. Therefore, the reported max has to be adjusted
as `min(OPEN_MAX, lim.max)`.
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>2 files changed, 11 insertions(+), 0 deletions(-)
lib/std/os/bits/darwin.zig+3| ... | @@ -1475,6 +1475,9 @@ pub const CLOCK_UPTIME_RAW_APPROX = 9; | ... | @@ -1475,6 +1475,9 @@ pub const CLOCK_UPTIME_RAW_APPROX = 9; |
| 1475 | pub const CLOCK_PROCESS_CPUTIME_ID = 12; | 1475 | pub const CLOCK_PROCESS_CPUTIME_ID = 12; |
| 1476 | pub const CLOCK_THREAD_CPUTIME_ID = 16; | 1476 | pub const CLOCK_THREAD_CPUTIME_ID = 16; |
| 1477 | 1477 | ||
| 1478 | /// Max open files per process | ||
| 1479 | /// https://opensource.apple.com/source/xnu/xnu-4903.221.2/bsd/sys/syslimits.h.auto.html | ||
| 1480 | pub const OPEN_MAX = 10240; | ||
| 1478 | pub const RUSAGE_SELF = 0; | 1481 | pub const RUSAGE_SELF = 0; |
| 1479 | pub const RUSAGE_CHILDREN = -1; | 1482 | pub const RUSAGE_CHILDREN = -1; |
| 1480 | 1483 |
src/main.zig+8| ... | @@ -2986,6 +2986,14 @@ fn gimmeMoreOfThoseSweetSweetFileDescriptors() void { | ... | @@ -2986,6 +2986,14 @@ fn gimmeMoreOfThoseSweetSweetFileDescriptors() void { |
| 2986 | const posix = std.os; | 2986 | const posix = std.os; |
| 2987 | 2987 | ||
| 2988 | var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried. | 2988 | var lim = posix.getrlimit(.NOFILE) catch return; // Oh well; we tried. |
| 2989 | if (std.Target.current.isDarwin()) { | ||
| 2990 | // On Darwin, `NOFILE` is bounded by a hardcoded value `OPEN_MAX`. | ||
| 2991 | // According to the man pages for setrlimit(): | ||
| 2992 | // setrlimit() now returns with errno set to EINVAL in places that historically succeeded. | ||
| 2993 | // It no longer accepts "rlim_cur = RLIM_INFINITY" for RLIM_NOFILE. | ||
| 2994 | // Use "rlim_cur = min(OPEN_MAX, rlim_max)". | ||
| 2995 | lim.max = std.math.min(posix.darwin.OPEN_MAX, lim.max); | ||
| 2996 | } | ||
| 2989 | if (lim.cur == lim.max) return; | 2997 | if (lim.cur == lim.max) return; |
| 2990 | 2998 | ||
| 2991 | // Do a binary search for the limit. | 2999 | // Do a binary search for the limit. |