-
Notifications
You must be signed in to change notification settings - Fork 8
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
Add memory page size alignment for madvise, mlock and munlock #19
base: master
Are you sure you want to change the base?
Conversation
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.
mlock now implicitly requires user to guarantee address alignment, and I agree that changing it is good.
/// Retrieve page size of the system | ||
/// | ||
/// Used for alignment | ||
unsafe fn page_size() -> 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.
We can use the page size cache in alloc mod.
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.
You're right, shouldn't be doing syscalls everytime we mlock/munlock. I've initialized the alloc_init()
function and returned the PAGE_SIZE
from the alloc
module instead
src/mlock.rs
Outdated
// start address of the page obtained from masked the value of the page size | ||
// with the memory address | ||
// | ||
let start_addr = (addr as usize) & !(page_size - 1); |
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 should be put into a separate function and some tests added.
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.
I've refactored it out to a separate function, and added a few tests to check whether it returns the right start and end page offsets
static ALLOC_INIT: Once = Once::new(); | ||
static mut PAGE_SIZE: usize = 0; | ||
pub(crate) static ALLOC_INIT: Once = Once::new(); | ||
pub(crate) static mut PAGE_SIZE: usize = 0; |
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.
ALLOC_INIT should probably be called PAGE_SIZE_INIT and put in a separate module
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.
Sure, I can move it to an init
module or something like that. Are you thinking of adding anything else?
Improved memory alignment in mlock and munlock functions(including madvise) to ensure proper page boundary handling. This adjustment aligns memory regions to the system's page size across unix systems