Skip to content
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

Merged
merged 1 commit into from
Apr 5, 2024

Conversation

NirjharRoyiitk
Copy link
Contributor

I am replacing the Vector new functions with raw allocator functions to allocate and deallocate memory

@NirjharRoyiitk NirjharRoyiitk force-pushed the nr-replace-stress-test-allocation branch from 8249bf2 to 1ffd520 Compare April 4, 2024 06:06
@arai-fortanix arai-fortanix self-requested a review April 4, 2024 18:24
@@ -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) {
Copy link
Contributor

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();
Copy link
Contributor

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());
Copy link
Contributor

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.

@NirjharRoyiitk NirjharRoyiitk added this pull request to the merge queue Apr 5, 2024
Merged via the queue into master with commit a5eff2f Apr 5, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants