-
Notifications
You must be signed in to change notification settings - Fork 5
fix: increase Hyperlight I/O buffer for large hostfs writes #81
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -525,16 +525,27 @@ impl ListenPorts { | |
| // --------------------------------------------------------------------------- | ||
|
|
||
| /// Configuration for a Unikraft VM. | ||
| #[non_exhaustive] | ||
| pub struct VmConfig { | ||
| pub heap_size: u64, | ||
| pub stack_size: u64, | ||
| pub io_buffer_size: usize, | ||
| } | ||
|
|
||
| /// Hyperlight I/O buffer size (128 KiB). Each host function call is serialized | ||
| /// into a FlatBuffer and pushed onto a shared-memory stack whose capacity is | ||
| /// `io_buffer_size`. The hostfs VFS layer chunks writes at 32 KiB, but after | ||
| /// base64 encoding + JSON envelope + FlatBuffer framing a single chunk | ||
| /// occupies ~44 KiB. The Hyperlight SDK default (16 KiB) is too small; 128 KiB | ||
| /// accommodates any single-chunk RPC with comfortable headroom. | ||
| const DEFAULT_IO_BUFFER_SIZE: usize = 128 * 1024; | ||
|
|
||
| impl Default for VmConfig { | ||
| fn default() -> Self { | ||
| Self { | ||
| heap_size: 512 * 1024 * 1024, | ||
| stack_size: 8 * 1024 * 1024, | ||
| io_buffer_size: DEFAULT_IO_BUFFER_SIZE, | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -553,9 +564,17 @@ impl VmConfig { | |
| self | ||
| } | ||
|
|
||
| /// Set the I/O buffer size for host function calls (default 128 KiB). | ||
| pub fn with_io_buffer_size(mut self, size: usize) -> Self { | ||
| self.io_buffer_size = size; | ||
| self | ||
| } | ||
|
|
||
| fn sandbox_config(&self) -> SandboxConfiguration { | ||
| let mut cfg = SandboxConfiguration::default(); | ||
| cfg.set_heap_size(self.heap_size); | ||
| cfg.set_input_data_size(self.io_buffer_size); | ||
| cfg.set_output_data_size(self.io_buffer_size); | ||
|
Comment on lines
573
to
+577
Contributor
Author
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. Pre-existing issue — |
||
|
|
||
| // Scratch holds page tables + CoW copies of writable pages touched at | ||
| // runtime. pt_estimate covers page tables; the base covers kernel | ||
|
|
@@ -2008,6 +2027,7 @@ pub struct SandboxBuilder { | |
| args: Vec<String>, | ||
| heap_size: Option<u64>, | ||
| stack_size: Option<u64>, | ||
| io_buffer_size: Option<usize>, | ||
| preopens: Vec<Preopen>, | ||
| network: Option<NetworkPolicy>, | ||
| listen_ports: Option<ListenPorts>, | ||
|
|
@@ -2057,6 +2077,14 @@ impl SandboxBuilder { | |
| self | ||
| } | ||
|
|
||
| /// Shared-memory I/O buffer size for host function calls (default 128 KiB). | ||
| /// Must be large enough to hold a single base64-encoded hostfs write chunk | ||
| /// plus JSON and FlatBuffer framing (~44 KiB for the default 32 KiB chunk). | ||
| pub fn io_buffer_size(mut self, bytes: usize) -> Self { | ||
| self.io_buffer_size = Some(bytes); | ||
| self | ||
| } | ||
|
|
||
| /// Expose a host directory to the guest. `lib/hostfs` mounts each | ||
| /// `preopen.host_dir` at `preopen.guest_path`; FS tool handlers | ||
| /// cover all of them and route by guest path prefix. Repeatable — | ||
|
|
@@ -2101,6 +2129,7 @@ impl SandboxBuilder { | |
| let config = VmConfig { | ||
| heap_size: self.heap_size.unwrap_or(512 * 1024 * 1024), | ||
| stack_size: self.stack_size.unwrap_or(8 * 1024 * 1024), | ||
| io_buffer_size: self.io_buffer_size.unwrap_or(DEFAULT_IO_BUFFER_SIZE), | ||
| }; | ||
| let tools = if self.has_tools { | ||
| Some(self.tools) | ||
|
|
@@ -2154,6 +2183,7 @@ impl Sandbox { | |
| args: Vec::new(), | ||
| heap_size: None, | ||
| stack_size: None, | ||
| io_buffer_size: None, | ||
| preopens: Vec::new(), | ||
| network: None, | ||
| listen_ports: None, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -280,6 +280,42 @@ fn runtime_filesystem_mkdir_and_stat() { | |
| cleanup(&tmp); | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Large binary write | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
| #[test] | ||
| fn runtime_filesystem_large_binary_write() { | ||
| let tmp = tempdir("hl-rt-bigwrite"); | ||
| let preopen = match Preopen::new(&tmp, "/host") { | ||
| Ok(p) => p, | ||
| Err(e) => { | ||
| eprintln!("SKIP: cannot create preopen: {e}"); | ||
| cleanup(&tmp); | ||
| return; | ||
| } | ||
| }; | ||
| let Some(mut rt) = setup_with_mount(preopen) else { | ||
| cleanup(&tmp); | ||
| return; | ||
| }; | ||
|
|
||
| let size = 40 * 1024; | ||
| let timing = rt | ||
| .run_code(&format!( | ||
| "with open('/host/big.bin', 'wb') as f: f.write(b'x' * {})", | ||
| size | ||
| )) | ||
| .unwrap(); | ||
| assert_eq!(timing.exit_code, 0); | ||
|
|
||
| let data = std::fs::read(tmp.join("big.bin")).unwrap(); | ||
| assert_eq!(data.len(), size); | ||
| assert!(data.iter().all(|&b| b == b'x')); | ||
|
Comment on lines
+304
to
+314
Contributor
Author
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. Fixed — using |
||
|
|
||
| cleanup(&tmp); | ||
| } | ||
|
|
||
| // --------------------------------------------------------------------------- | ||
| // Network policy enforcement | ||
| // --------------------------------------------------------------------------- | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Fixed — added
#[non_exhaustive]toVmConfig.