Repository navigation
feat: transparent huge page stacks and per-thread stack cache #158
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: master
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 |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| #![cfg(not(any(target_arch = "wasm32", windows, miri)))] | ||
|
|
||
| extern crate stacker; | ||
|
|
||
| use std::thread; | ||
|
|
||
| #[inline(never)] | ||
| fn deep_marker() -> *mut u8 { | ||
|
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. Pretty sure that's UB according to Rust, but but given that this library already operates on stack, I think this may be legal? Will drop this test if not
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. ...Or, maybe I should just rewrite it to use rust_psm_stack_pointer(), at least that resolves the question of what happens if |
||
| let local = 0u8; | ||
| let bottom = (&local as *const u8 as usize - stacker::remaining_stack().unwrap()) & !4095; | ||
| (bottom + 64) as *mut u8 | ||
| } | ||
|
|
||
| #[test] | ||
| fn cached_stack_is_reused() { | ||
| stacker::set_cached_stacks(1); | ||
| thread::spawn(|| { | ||
| let written = stacker::grow(1024 * 1024, || { | ||
| let marker = deep_marker(); | ||
| unsafe { marker.write_volatile(0xab) }; | ||
| marker as usize | ||
| }); | ||
| let (read, value) = stacker::grow(1024 * 1024, || { | ||
| let marker = deep_marker(); | ||
| (marker as usize, unsafe { marker.read_volatile() }) | ||
| }); | ||
| assert_eq!(written, read); | ||
| assert_eq!(value, 0xab); | ||
| }) | ||
| .join() | ||
| .unwrap(); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #![cfg(all(target_os = "linux", not(miri)))] | ||
|
|
||
| extern crate stacker; | ||
|
|
||
| use std::thread; | ||
|
|
||
| #[test] | ||
| fn huge_page_stack_is_rounded_up() { | ||
| let size = match std::fs::read_to_string("/sys/kernel/mm/transparent_hugepage/hpage_pmd_size") | ||
| { | ||
| Ok(size) => size.trim().parse::<usize>().unwrap(), | ||
| Err(_) => return, | ||
| }; | ||
| stacker::set_huge_pages(true); | ||
| thread::spawn(move || { | ||
| stacker::grow(64 * 1024, || { | ||
| assert!(stacker::remaining_stack().unwrap() > size / 2); | ||
| }); | ||
| }) | ||
| .join() | ||
| .unwrap(); | ||
| } |
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.
Might switch to OnceLock