-
Notifications
You must be signed in to change notification settings - Fork 15
Raise host fd limit to back the guest fd table #148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |
| test-sysroot-create-paths test-fork-ipc-protocol-host test-identity-override-host \ | ||
| test-proctitle-host test-proctitle-low-stack \ | ||
| test-sysroot-procfs-exec test-timeout-disable test-fuse-alpine \ | ||
| test-sysroot-nofollow test-sysroot-chdir perf | ||
| test-sysroot-nofollow test-sysroot-chdir test-fd-limit-stock perf | ||
|
|
||
| ## Build and run the assembly hello world test | ||
| test-hello: $(ELFUSE_BIN) $(TEST_HELLO_DEP) | ||
|
|
@@ -43,6 +43,8 @@ check: $(ELFUSE_BIN) $(TEST_DEPS) check-syscall-coverage \ | |
| $(BUILD_DIR)/test-fork-ipc-protocol-host \ | ||
| $(BUILD_DIR)/test-identity-override-host | ||
| @bash tests/driver.sh -e $(ELFUSE_BIN) -d $(TEST_DIR) -v | ||
| @printf "\n$(BLUE)━━━ stock fd-limit (256) regression ━━━$(RESET)\n" | ||
| @$(MAKE) --no-print-directory test-fd-limit-stock | ||
| @printf "\n$(BLUE)━━━ TLBI RVAE1IS encoder unit test ━━━$(RESET)\n" | ||
| @$(BUILD_DIR)/test-tlbi-encoder-host | ||
| @printf "\n$(BLUE)━━━ fork IPC protocol identity unit test ━━━$(RESET)\n" | ||
|
|
@@ -74,6 +76,15 @@ check: $(ELFUSE_BIN) $(TEST_DEPS) check-syscall-coverage \ | |
| @printf "\n$(BLUE)━━━ hot-syscall guardrail ━━━$(RESET)\n" | ||
| @$(MAKE) --no-print-directory test-bench-guardrail | ||
|
|
||
| ## Rerun the fd-heavy stress test with the soft RLIMIT_NOFILE forced to the | ||
| ## stock macOS default (256): fdtable_init must raise the host limit itself. | ||
| FD_LIMIT_STOCK_DEPS := $(ELFUSE_BIN) | ||
| ifndef GUEST_TEST_BINARIES | ||
| FD_LIMIT_STOCK_DEPS += $(BUILD_DIR)/test-stress | ||
| endif | ||
| test-fd-limit-stock: $(FD_LIMIT_STOCK_DEPS) | ||
| @bash -c 'ulimit -S -n 256 && exec "$(ELFUSE_BIN)" "$(TEST_DIR)/test-stress"' | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The Prompt for AI agents |
||
|
|
||
| ## Hot-syscall performance guardrail: ensure getpid, libc clock_gettime, | ||
| ## and 1-byte /dev/urandom reads stay under their TODO ns/op ceilings. | ||
| ## Builds the dynamic-glibc variant opportunistically; the script skips | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,10 +10,12 @@ | |
| * access through fd_lock. | ||
| */ | ||
|
|
||
| #include <limits.h> | ||
| #include <stdatomic.h> | ||
| #include <stdbool.h> | ||
| #include <stdlib.h> | ||
| #include <string.h> | ||
| #include <sys/resource.h> | ||
| #include <unistd.h> | ||
| #include <errno.h> | ||
| #include <dirent.h> | ||
|
|
@@ -145,11 +147,35 @@ static int fd_bitmap_find_free(int minfd) | |
|
|
||
| /* fdtable_init. */ | ||
|
|
||
| /* Raise the host RLIMIT_NOFILE soft limit to min(OPEN_MAX, rlim_max), the | ||
| * largest value macOS accepts. The stock soft limit is 256, far below the | ||
| * FD_TABLE_SIZE fds this table advertises to guests, and every guest fd needs | ||
| * at least one backing host fd. | ||
| * | ||
| * Returns without changing anything if getrlimit fails or the limit already | ||
| * meets the target (an inherited higher limit is never lowered); setrlimit | ||
| * failure is ignored. | ||
| */ | ||
| static void fd_raise_host_nofile(void) | ||
| { | ||
| struct rlimit rl; | ||
|
|
||
| if (getrlimit(RLIMIT_NOFILE, &rl) != 0) | ||
| return; | ||
| rlim_t want = (rl.rlim_max < OPEN_MAX) ? rl.rlim_max : OPEN_MAX; | ||
| if (rl.rlim_cur >= want) | ||
| return; | ||
| rl.rlim_cur = want; | ||
| (void) setrlimit(RLIMIT_NOFILE, &rl); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: If raising the host fd limit fails (e.g. in a constrained container or sandbox), the guest-visible Consider syncing the guest limit down when Prompt for AI agents |
||
| } | ||
|
|
||
| /* Initialize the FD table and bitmap, pre-open stdin/stdout/stderr. Extracted | ||
| * from syscall_init(); call before any guest code runs. | ||
| */ | ||
| void fdtable_init(void) | ||
| { | ||
| fd_raise_host_nofile(); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Please either run the host raise only during initial bootstrap, or serialize/restore the guest nofile state across the fork path before guest code resumes. |
||
|
|
||
| memset(fd_table, 0, sizeof(fd_table)); | ||
|
|
||
| /* Mark all FDs as free in bitmap */ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please wrap this target with the same 60-second timeout used by the normal test driver, or move the lowered-rlimit case into a driver script that already has timeout handling.