Repository navigation
Return the per-process open-file limit on the BSDs - #3808
Conversation
FreeBSD and DragonFly BSD returned kern.maxfiles, the system-wide limit, from getMaxFileDescriptorsPerProcess(); they now read kern.maxfilesperproc. The FreeBSD base's two single-purpose hooks become one querySysctl(name) hook, the shape the macOS and OpenBSD bases already use. NetBSD and OpenBSD read kern.maxfilesperproc, which neither has, so both always returned 0. They now return the hard RLIMIT_NOFILE, the ceiling a process may raise its limit to and the analogue of Solaris's rlim_fd_max: NetBSD through proc.curproc.rlimit.descriptors.hard (a forked sysctl inherits the JVM's limits), OpenBSD, which has no proc.curproc, through a new getrlimit hook in both backends. Both are capped at kern.maxfiles, which the kernel enforces regardless of an unlimited resource limit. NetBSD's own-process open-file limit fallback, used when no backend can call getrlimit, also tried kern.maxfilesperproc; it now reads proc.curproc.rlimit.descriptors.soft or .hard before kern.maxfiles. Verified JNA and FFM on FreeBSD 16 (941580) and DragonFly 6.4 (130832) against sysctl. The NetBSD and OpenBSD sysctls were checked by hand; the code is untested there (no JDK on those hosts) beyond CI.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
FileSystem.getMaxFileDescriptorsPerProcess()was wrong on all four BSDs:kern.maxfiles(the system-wide limit)kern.maxfilesperprockern.maxfilesperproc, which does not exist: always 0proc.curproc.rlimit.descriptors.hardkern.maxfilesperproc, which does not exist: always 0RLIMIT_NOFILEviagetrlimit(JNA and FFM)NetBSD and OpenBSD have no per-process sysctl, so they return the hard resource limit, the ceiling a process may raise its limit to (Solaris's
rlim_fd_maxis the same idea). OpenBSD has noproc.curproctree, hence a native hook. Both are capped atkern.maxfiles, which the kernel enforces regardless of an unlimited resource limit; the helper is onAbstractFileSystemwith a unit test.Also:
queryOpenFiles/queryMaxFileshooks become onequerySysctl(name)hook, matching the macOS and OpenBSD bases.getrlimit) also triedkern.maxfilesperproc; it now readsproc.curproc.rlimit.descriptors.soft/.hardbeforekern.maxfiles.Verification
kern.maxfilesperproc=ulimit -Hn(was 1046204).kern.maxfilesperproc(was 523328).kern.maxfilesperprocabsent on both; NetBSDproc.curproc.rlimit.descriptors.hard= 3404; OpenBSD has noproc.tree). The code itself is untested there beyond CI, as neither host has a JDK.-Paggregate-coveragegreen on macOS.Summary by CodeRabbit