Skip to content

Raise host NOFILE capacity for the guest FD table#204

Open
Xalestar wants to merge 2 commits into
sysprog21:mainfrom
Xalestar:fix-host-nofile-capacity
Open

Raise host NOFILE capacity for the guest FD table#204
Xalestar wants to merge 2 commits into
sysprog21:mainfrom
Xalestar:fix-host-nofile-capacity

Conversation

@Xalestar

@Xalestar Xalestar commented Jul 14, 2026

Copy link
Copy Markdown

Problem

elfuse exposes a guest FD table with 1024 entries, but the host process may start with a much smaller soft RLIMIT_NOFILE. On a host soft limit of 256, the stress test can open only about 248 guest descriptors before the host runs out of descriptors, even though the guest table still has capacity.

Host capacity and guest-visible NOFILE state also need to remain separate: exposing the internal reserve reports an unreachable limit, while forwarding guest setrlimit to the host can remove capacity needed by fork IPC.

Change

  • Require host soft RLIMIT_NOFILE capacity for FD_TABLE_SIZE plus a 64-descriptor host reserve.
  • Raise only the host soft limit and preserve its hard limit.
  • Fail at startup with a diagnostic when the hard limit cannot provide the required capacity.
  • Keep a guest-side 1024/1024 NOFILE limit for getrlimit, setrlimit, prlimit64, proc reporting, and FD allocation.
  • Keep guest NOFILE updates from changing the internal host limit.
  • Carry guest NOFILE state through fork IPC and restore inherited FDs before applying a lowered soft limit.
  • Recheck internal host capacity in fork helpers before receiving the parent FD table.

Verification

  • Focused test-stress with host soft limit 256: pass
  • Focused test-stress with host soft limit 4096: pass
  • Host hard limit 256: expected startup failure and diagnostic verified
  • Guest NOFILE reports 1024/1024 without exposing the 64-FD host reserve
  • Fork after lowering guest soft and hard NOFILE to 3 preserves an inherited pipe
  • make check: 69 tests passed; BusyBox 82 passed, 0 failed, 2 skipped
  • make test-matrix-elfuse-aarch64: 235 passed, 0 failed, 4 skipped
  • make test-matrix-qemu-aarch64: 215 passed, 0 failed, 24 skipped
  • make lint: pass with existing project warnings
  • clang-format dry run for all changed C and header files: pass
  • git diff --check: pass

Questions for maintainers

  1. Is a 64-descriptor host reserve acceptable, or would another policy better match the project?
  2. When the host hard limit is below the required capacity, should elfuse fail at startup as proposed here, or derive a smaller guest-visible limit?

Related work

PR #148 addresses the same issue by raising the host limit in fdtable initialization and adding a host-side low-limit regression wrapper. This PR also separates guest-visible NOFILE state from elfuse internal host capacity and preserves that state across fork IPC.

Close #68

elfuse exposes a 1024-entry guest FD table but currently inherits the
host RLIMIT_NOFILE unchanged. With a host soft limit of 256, guests hit
host-side EMFILE after opening 248 additional descriptors and
test-stress fails deterministically.

Ensure the top-level elfuse process has capacity for FD_TABLE_SIZE plus
64 descriptors reserved for runtime-owned pipes, fork IPC, debugger
sockets, and sysroot/FUSE plumbing. Preserve the host hard limit and
report a startup error when the required capacity cannot be established.

Fork helpers inherit the capacity established by the top-level process
and do not reapply the startup policy after a guest may have changed
RLIMIT_NOFILE.
@Xalestar Xalestar marked this pull request as ready for review July 14, 2026 09:50
cubic-dev-ai[bot]

This comment was marked as resolved.

@Max042004

Copy link
Copy Markdown
Collaborator

Add "Close #68" at the end of PR and commit message.

Because PR #148 also address same issue. So please also mention this PR.

Keep the host descriptor reserve internal by serving guest NOFILE queries and updates from a guest-side 1024/1024 limit. Guest setrlimit no longer lowers the host capacity that elfuse needs for runtime and fork IPC.

Carry the guest limit through the fork protocol, restore inherited descriptors before applying a lowered soft limit, and recheck host capacity in fork helpers. Add regressions for hidden reserve reporting and fork after lowering the hard limit.

PR sysprog21#148 addresses the same low-host-limit failure with a different startup policy and a host-side regression wrapper.

Close sysprog21#68
@Xalestar Xalestar force-pushed the fix-host-nofile-capacity branch from 32b48db to e189210 Compare July 14, 2026 10:59
@Xalestar

Copy link
Copy Markdown
Author

Done. The PR body now mentions PR #148 and ends with Close #68. The latest commit message was also amended to include both references (e189210).

@jserv jserv requested a review from Max042004 July 14, 2026 13:29
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.

test-stress FD exhaustion subtest fails with default macOS file-descriptor limit

2 participants