Skip to content

fix(minimal in vm): raise rlimit to sane default - #1085

Merged
twitchyliquid64 merged 1 commit into
mainfrom
tom/check-sop
Jul 29, 2026
Merged

fix(minimal in vm): raise rlimit to sane default#1085
twitchyliquid64 merged 1 commit into
mainfrom
tom/check-sop

Conversation

@twitchyliquid64

@twitchyliquid64 twitchyliquid64 commented Jul 29, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features

    • MicroVMs now support a higher open-file limit by default.
    • Added best-effort configuration to customize the open-file limit during startup.
    • Startup now safely falls back to the highest supported limit when the requested value is unavailable.
  • Bug Fixes

    • Improved handling of unsupported open-file limit increases without preventing VM startup.

Note

Raise RLIMIT_NOFILE to 65536 in minimald microVM init processes

  • Adds raise_nofile_limit in guest.rs that sets both soft and hard RLIMIT_NOFILE to a requested value, falling back to the current hard limit if the request exceeds fs.nr_open.
  • Adds DEFAULT_MICROVM_NOFILE_LIMIT constant (65536) used automatically when minimald runs as microVM init.
  • Adds a hidden --rlimit-nofile CLI flag in main.rs to override the limit; the effective soft limit and any failures are logged.
  • Child processes forked by the daemon inherit the resulting limits.
  • Behavioral Change: microVM init processes now start with a soft and hard RLIMIT_NOFILE of 65536 instead of the system default.

Macroscope summarized 93e97d3.

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

MicroVM startup now configures and raises RLIMIT_NOFILE before daemon forks. The helper handles unreachable hard limits by falling back to the existing hard limit, and tests verify that the effective limit never decreases.

Changes

MicroVM open-file limit handling

Layer / File(s) Summary
RLIMIT_NOFILE helper and validation
crates/minimald/src/guest.rs
Adds the default limit, limit-raising helper, hard-limit fallback behavior, and monotonicity tests.
MicroVM startup integration
crates/minimald/src/main.rs
Adds the hidden --rlimit-nofile option, enables the default for microVM initialization, and applies it before forking with outcome logging.

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

Suggested reviewers: 0chroma

Poem

A rabbit lifts the limit high,
Before the daemon hops nearby.
If kernels say, “That’s far too wide,”
The old hard bound becomes the guide.
No open-file count shall slide!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers the change summary, but it misses the required Testing and Checklist sections from the template. Add explicit Summary, Testing, and Checklist sections, including test evidence and whether docs or a BREAKING CHANGE footer are needed.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly reflects the main change: raising the RLIMIT_NOFILE default in minimal VM init.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/minimald/src/main.rs`:
- Around line 484-503: Add or update the booted-VM integration test covering
listen_args.rlimit_nofile and guest::raise_nofile_limit so it boots a guest with
a configured RLIMIT_NOFILE and verifies PID 1 observes that inherited limit
before daemon or session startup. Retain the existing in-process setrlimit unit
coverage, but ensure the VM test validates inheritance across the fork/exec boot
boundary.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d654eea7-139d-4f0c-804d-91233d304162

📥 Commits

Reviewing files that changed from the base of the PR and between 0e25232 and 93e97d3.

📒 Files selected for processing (2)
  • crates/minimald/src/guest.rs
  • crates/minimald/src/main.rs

Comment on lines +484 to +503
// Before anything forks from us and inherits the limits. Best effort: the
// kernel default is the prior behaviour, not a reason to refuse to boot.
if let Some(limit) = listen_args.rlimit_nofile {
match guest::raise_nofile_limit(limit) {
Ok(effective) if effective >= limit => {
tracing::debug!(nofile = effective, "raised the open-file limit");
}
Ok(effective) => tracing::warn!(
requested = limit,
effective,
"the open-file limit could not be raised as far as requested; fd-hungry builds \
may fail with EMFILE"
),
Err(e) => tracing::warn!(
error = %e,
requested = limit,
"could not raise the open-file limit; fd-hungry builds may fail with EMFILE"
),
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== file list =="
git ls-files | rg '(^|/)(main\.rs|.*test.*|.*e2e.*|.*integration.*|justfile|JUSTFILE|Makefile|rust-toolchain\.toml|docs/.*rust-coding-standards\.md)$' || true

echo
echo "== search for rlimit / nofile =="
rg -n "rlimit_nofile|raise_nofile_limit|setrlimit|nofile|RLIMIT_NOFILE" crates docs .github justfile Makefile -S || true

echo
echo "== inspect minimald main around relevant lines =="
sed -n '430,540p' crates/minimald/src/main.rs

echo
echo "== search for integration tests around VM boot =="
rg -n "booted VM|boot.*VM|e2e|test-vm|integration test|daemon/session|session startup|PID 1" crates tests . -S || true

Repository: gominimal/minimal

Length of output: 50373


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '== helper references ==\n'
rg -n "raise_nofile_limit|rlimit_nofile" crates/minimald -S || true

printf '\n== likely test files ==\n'
fd -a -t f '.*(test|tests|e2e|integration).*' crates/minimald . || true

printf '\n== likely mentions of nofile in tests ==\n'
rg -n "nofile|NOFILE|EMFILE|RLIMIT_NOFILE" crates/minimald/tests crates/minimald/src crates/minimald -g '!target' -S || true

Repository: gominimal/minimal

Length of output: 6907


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== ast-grep outline: relevant test files =="
for f in crates/minvmd/tests/boot_integration.rs crates/minvmd/tests/resource_vm_integration.rs crates/minimald/src/guest.rs; do
  echo "--- $f ---"
  ast-grep outline "$f" --view expanded || true
done

echo
echo "== RLIMIT_NOFILE in test files =="
rg -n "RLIMIT_NOFILE|nofile|raise_nofile_limit|getrlimit|setrlimit|DEFAULT_MICROVM_NOFILE_LIMIT" \
  crates/minvmd/tests crates/minimald/src/guest.rs -S || true

echo
echo "== read boot_integration.rs slice =="
sed -n '1,220p' crates/minvmd/tests/boot_integration.rs

echo
echo "== read resource_vm_integration.rs slice =="
sed -n '1,260p' crates/minvmd/tests/resource_vm_integration.rs

echo
echo "== read guest.rs unit-test slice =="
sed -n '1320,1375p' crates/minimald/src/guest.rs

Repository: gominimal/minimal

Length of output: 17024


Add VM-backed coverage for RLIMIT_NOFILE. The current unit test only exercises setrlimit in-process; it doesn’t prove the guest PID 1 starts with the configured inherited limit before daemon/session startup. Add or update a booted-VM integration test that asserts the guest inherits the limit.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/minimald/src/main.rs` around lines 484 - 503, Add or update the
booted-VM integration test covering listen_args.rlimit_nofile and
guest::raise_nofile_limit so it boots a guest with a configured RLIMIT_NOFILE
and verifies PID 1 observes that inherited limit before daemon or session
startup. Retain the existing in-process setrlimit unit coverage, but ensure the
VM test validates inheritance across the fork/exec boot boundary.

Source: Coding guidelines

@twitchyliquid64
twitchyliquid64 merged commit b5c7857 into main Jul 29, 2026
27 checks passed
@twitchyliquid64
twitchyliquid64 deleted the tom/check-sop branch July 29, 2026 22:11
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.

2 participants