Skip to content

Return the per-process open-file limit on the BSDs - #3808

Merged
dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:bsd-max-fds-per-process
Oct 15, 2026
Merged

dbwiddis merged 1 commit into
oshi:masterfrom
dbwiddis:bsd-max-fds-per-process

Conversation

@dbwiddis

@dbwiddis dbwiddis commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

FileSystem.getMaxFileDescriptorsPerProcess() was wrong on all four BSDs:

OS Before After
FreeBSD, DragonFly BSD kern.maxfiles (the system-wide limit) kern.maxfilesperproc
NetBSD kern.maxfilesperproc, which does not exist: always 0 proc.curproc.rlimit.descriptors.hard
OpenBSD kern.maxfilesperproc, which does not exist: always 0 hard RLIMIT_NOFILE via getrlimit (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_max is the same idea). OpenBSD has no proc.curproc tree, hence a native hook. Both are capped at kern.maxfiles, which the kernel enforces regardless of an unlimited resource limit; the helper is on AbstractFileSystem with a unit test.

Also:

  • The FreeBSD base's queryOpenFiles/queryMaxFiles hooks become one querySysctl(name) hook, matching the macOS and OpenBSD bases.
  • NetBSD's own-process soft/hard open-file limit fallback (used when no backend can call getrlimit) also tried kern.maxfilesperproc; it now reads proc.curproc.rlimit.descriptors.soft/.hard before kern.maxfiles.

Verification

  • FreeBSD 16-CURRENT (cfarm430): JNA and FFM both 941580 = kern.maxfilesperproc = ulimit -Hn (was 1046204).
  • DragonFly 6.4 (cfarm152): JNA and FFM both 130832 = kern.maxfilesperproc (was 523328).
  • NetBSD 10.1 (cfarm428) and OpenBSD 7.9 (cfarm220): sysctls checked by hand (kern.maxfilesperproc absent on both; NetBSD proc.curproc.rlimit.descriptors.hard = 3404; OpenBSD has no proc. tree). The code itself is untested there beyond CI, as neither host has a JDK.
  • Full gate with -Paggregate-coverage green on macOS.

Summary by CodeRabbit

  • Bug Fixes
    • BSD systems now report the hard per-process open-file limit, capped at the system-wide maximum when available.
    • Corrected inaccurate per-process limit results on FreeBSD, DragonFly BSD, NetBSD, and OpenBSD.

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.
@coderabbitai

coderabbitai Bot commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 177a4f34-a072-4438-a211-f3d994e000b7
📥 Commits

Reviewing files that changed from the base of the PR and between c0a77e3 and e5a4753.

📒 Files selected for processing: 11
  • CHANGELOG.md
  • oshi-common/src/main/java/oshi/software/common/AbstractFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdFileSystem.java
  • oshi-common/src/test/java/oshi/software/common/AbstractFileSystemTest.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdFileSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemFFM.java
  • oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdFileSystemJNA.java
  • oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemJNA.java

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.

⏰ Context from checks skipped due to timeout: 9
  • GitHub Check: Test JDK 25, FreeBSD
  • GitHub Check: Test JDK 25, OpenIndiana
  • GitHub Check: Test JDK 25, NetBSD
  • GitHub Check: Test JDK 25, OpenBSD
  • GitHub Check: Lint (ForbiddenAPIs, Javadoc, SLF4J)
  • GitHub Check: Error Prone
  • GitHub Check: Test JDK 25, windows-latest
  • GitHub Check: Lint (Spotless, Checkstyle)
  • GitHub Check: Analyze (java)
🧰 Additional context used
📚 Code guidelines: 2
AGENTS.md — auto-discovered
CONTRIBUTING.md — auto-discovered
📓 Path-based instructions: 3
Source excerpt: **Banned APIs** (`config/forbidden-apis.txt` and friends, enforced by `forbiddenapis:check`): `oshi-core-ffm` may not reference `com.sun.jna.**`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdFileSystemFFM.java
  • oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemFFM.java
Source excerpt: **Banned APIs** (`config/forbidden-apis.txt` and friends, enforced by `forbiddenapis:check`): `oshi-common` may not reference `com.sun.jna.**`, `java.lang.foreign.**`, or any `System.load`/`loadLibrary`.

📄 CodeRabbit inference engine (AGENTS.md)

Files:

  • oshi-common/src/main/java/oshi/software/common/AbstractFileSystem.java
  • oshi-common/src/test/java/oshi/software/common/AbstractFileSystemTest.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdFileSystem.java
  • oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java
Source excerpt: The Changelog lets users know what's changed.

📄 CodeRabbit inference engine (CONTRIBUTING.md)

Files:

  • CHANGELOG.md
🔇 Additional comments: 11
oshi-common/src/main/java/oshi/software/common/AbstractFileSystem.java: 1

43-57: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java: 1

228-250: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdFileSystem.java: 1

166-168: LGTM!

oshi-common/src/test/java/oshi/software/common/AbstractFileSystemTest.java: 1

50-60: LGTM!

CHANGELOG.md: 1

19-19: LGTM!

oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdFileSystem.java: 1

60-61: LGTM!

Also applies to: 93-98

oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemJNA.java: 1

7-10: LGTM!

Also applies to: 25-33

oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemFFM.java: 1

7-19: LGTM!

Also applies to: 23-23, 28-29, 34-44

oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdFileSystem.java: 1

110-110: LGTM!

Also applies to: 115-115, 120-120, 178-178, 180-181, 183-183

oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdFileSystemJNA.java: 1

13-13: LGTM!

Also applies to: 19-20

oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdFileSystemFFM.java: 1

13-13: LGTM!

Also applies to: 19-20

📝 Walkthrough

The change updates per-process file-descriptor limit retrieval on FreeBSD, NetBSD, and OpenBSD. It adds a shared limit-capping helper, changes FreeBSD sysctl access, and adds JNA and FFM access to the OpenBSD hard resource limit.

Changes: BSD file-descriptor limits

Layer / File(s) Summary
Shared cap and NetBSD limits
oshi-common/src/main/java/oshi/software/common/AbstractFileSystem.java, oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdOSProcess.java, oshi-common/src/main/java/oshi/software/common/os/unix/netbsd/NetBsdFileSystem.java, oshi-common/src/test/java/oshi/software/common/AbstractFileSystemTest.java, CHANGELOG.md
Adds capAtSystemLimit and tests its limit handling. NetBSD uses the hard process limit, capped at the system maximum. NetBSD process-limit queries use getrlimit first, then sysctl and fallback values.
FreeBSD sysctl access
oshi-common/src/main/java/oshi/software/common/os/unix/freebsd/FreeBsdFileSystem.java, oshi-core/src/main/java/oshi/software/os/unix/freebsd/FreeBsdFileSystemJNA.java, oshi-core-ffm/src/main/java/oshi/software/os/unix/freebsd/FreeBsdFileSystemFFM.java
FreeBSD queries kern.openfiles, kern.maxfiles, and kern.maxfilesperproc through a shared named-sysctl method. The JNA and FFM implementations read the supplied sysctl name.
OpenBSD hard-limit retrieval
oshi-common/src/main/java/oshi/software/common/os/unix/openbsd/OpenBsdFileSystem.java, oshi-core/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemJNA.java, oshi-core-ffm/src/main/java/oshi/software/os/unix/openbsd/OpenBsdFileSystemFFM.java
OpenBSD uses the hard RLIMIT_NOFILE value, capped at the system maximum. The JNA and FFM implementations return the hard limit or -1 when retrieval fails.

Priority: ⬇️ Low

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix · Severity of issue fixed: Low

Merge Risk: ⚪ Minimal · up to e5a47

The BSD limit changes appear mergeable after normal checks; no actionable defect is established.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 22.73% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 10 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly and concisely describes the main change: returning per-process open-file limits on BSD systems.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 22.73% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 22 functions across 10 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit checked the limits twice,
Then capped the count to fit it nice.
Through sysctl paths and native calls,
The hard limit answered from its walls.
I thump for tidy file counts today!

Comment @coderabbitai help to get the list of available commands.

@dbwiddis
dbwiddis merged commit 77408b8 into oshi:master Oct 15, 2026
17 of 18 checks passed
@dbwiddis
dbwiddis deleted the bsd-max-fds-per-process branch October 15, 2026 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant