Add memory page size alignment for madvise, mlock and munlock - #19
Add memory page size alignment for madvise, mlock and munlock#19Eyob94 wants to merge 3 commits into
Conversation
quininer
left a comment
There was a problem hiding this comment.
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.
We can use the page size cache in alloc mod.
There was a problem hiding this comment.
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
| // 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.
it should be put into a separate function and some tests added.
There was a problem hiding this comment.
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.
ALLOC_INIT should probably be called PAGE_SIZE_INIT and put in a separate module
There was a problem hiding this comment.
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