-
Notifications
You must be signed in to change notification settings - Fork 4
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
WIP: add api to check whether SQ and CQ count against memlock rlimit #36
Draft
problame
wants to merge
1
commit into
main
Choose a base branch
from
problame/memlock-learnings
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
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 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use std::{io::Write, os::unix::process::CommandExt}; | ||
|
||
/// Check whether a [`crate::System`]'s consumes memlock rlimit budget. | ||
/// | ||
/// Unsafe because this function forks & uses [`std::os::unix::process::Command::pre_exec`]. | ||
/// | ||
/// Panics in a bunch of places. | ||
/// | ||
pub unsafe fn does_system_consume_memlock_rlimit_budget() -> bool { | ||
// Fork a child process. | ||
// In the child process, set up a tokio-epoll-uring system. | ||
// Compare the memlock rlimit usage before and after. | ||
|
||
// poor man's bincode | ||
#[repr(C, packed)] | ||
struct RlimitPrePost { | ||
pre: (u64, u64), | ||
post: (u64, u64), | ||
} | ||
// Ensure `true` binary exists. | ||
std::process::Command::new("true") | ||
.output() | ||
.expect("canont exec `true` binary"); | ||
let output = std::process::Command::new("true") | ||
.pre_exec(|| { | ||
let rt = tokio::runtime::Builder::new_current_thread() | ||
.enable_all() | ||
.build()?; | ||
let pre = nix::sys::resource::getrlimit(nix::sys::resource::Resource::RLIMIT_MEMLOCK) | ||
.unwrap(); | ||
let system = rt.block_on(crate::System::launch()).unwrap(); | ||
// use the memory | ||
let ((), res) = rt.block_on(system.nop()); | ||
res.unwrap(); | ||
let post = nix::sys::resource::getrlimit(nix::sys::resource::Resource::RLIMIT_MEMLOCK) | ||
.unwrap(); | ||
let output = RlimitPrePost { pre, post }; | ||
let output_as_slice = std::slice::from_raw_parts( | ||
&output as *const _ as *const u8, | ||
std::mem::size_of_val(&output), | ||
); | ||
std::io::stdout().write_all(output_as_slice).unwrap(); | ||
Ok(()) | ||
}) | ||
.output() | ||
.unwrap(); | ||
assert_eq!(output.status.code().unwrap(), 0); | ||
assert_eq!(output.stdout.len(), std::mem::size_of::<RlimitPrePost>()); | ||
let (head, output, tail): (_, &[RlimitPrePost], _) = output.stdout.align_to(); | ||
assert_eq!(head.len(), 0); | ||
assert_eq!(tail.len(), 0); | ||
assert_eq!(output.len(), 1); | ||
let RlimitPrePost { pre, post } = output[0]; | ||
assert!(pre <= post, "above code can't use _less_ locked memory"); | ||
pre < post | ||
} |
This file contains 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 |
---|---|---|
|
@@ -8,3 +8,5 @@ mod test_util; | |
mod tests; | ||
|
||
pub(crate) const RING_SIZE: u32 = 128; | ||
|
||
pub mod kernel_support; |
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.
This doesn't make sense. What we want is not to get the limit, but the usage.
There's a file in
procfs
for that, the test I added in an earlier commit uses it.