-
Notifications
You must be signed in to change notification settings - Fork 98
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
Replacing the allocation technique in memory allocation stress test #570
Conversation
8249bf2
to
1ffd520
Compare
@@ -103,22 +101,22 @@ fn wakeup_all_child_threads(pair_clone: Arc<(Mutex<bool>, Condvar)>) { | |||
drop(started); | |||
} | |||
|
|||
fn traverse_buffer(buf: &mut Vec<i32>, scan_interval: usize) { | |||
let mut ptr = 0; | |||
fn traverse_buffer(buf: *mut u8, size: usize, _scan_interval: usize) { |
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.
Is it intentional that scan_interval is no longer used? Should the parameter just be removed instead?
large_vector.resize(size, 0); | ||
|
||
// Create a layout based on the size and alignment | ||
let align = get_random_num(2, PAGE_SIZE).next_power_of_two(); |
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 works, but has a slight bias toward larger alignments. If you want the different alignments to have the same probability, you could do something like generating a number X between 0 and 12 inclusive, and then using the alignment (1 << X). Not a big deal.
|
||
// Allocate memory using the global allocator | ||
let ptr = unsafe { alloc(layout) }; | ||
assert!(!ptr.is_null()); |
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.
It would also be nice to check that the allocated memory is correctly aligned.
I am replacing the Vector new functions with raw allocator functions to allocate and deallocate memory