Memory manager align on 4K boundaries
- michaellangford
- Posts: 21
- Joined: Tue Jun 21, 2016 6:41 am
- Libera.chat IRC: quad4
Memory manager align on 4K boundaries
Hello, I wrote a simple bitmap memory allocator, using the map of free memory given by GRUB, and linker symbols for where my kernel is. It works fine, and allocates 4KB blocks. I have made it so that it stores the bitmap after the kernel, and only allocates memory after the kernel. I want to use it for page allocation, but I'm not sure how to have it align on 4K boundaries. Any suggestions? Would modifying the memory space that my manager has to work with by increasing the base pointer until it is 4K aligned work? Thanks!
"Out of memory: Please memorize the following numbers and type them back in when asked for page number 42". - linguofreak
"Quote me in your forum signature" - Sortie (Check!)
"Quote me in your forum signature" - Sortie (Check!)
Re: Memory manager align on 4K boundaries
Im using this for my malloc function:
Nothing too advanced though, just change the * 0x1000 to your needs
Hope I understood your question right
Code: Select all
uint32_t mmap_to_address(uint32_t index, uint32_t bit)
{
if(index >= BITMAP_SIZE || bit >= 32)
return -1;
return 0x20000 * index + bit * 0x1000;
}
Hope I understood your question right
Re: Memory manager align on 4K boundaries
I align the base pointer just as you've said. This does the job pretty well.
Code: Select all
#define NEXT_PAGE_BOUNDARY(val) ((val & ~(PAGE_SIZE -1)) + PAGE_SIZE)
- michaellangford
- Posts: 21
- Joined: Tue Jun 21, 2016 6:41 am
- Libera.chat IRC: quad4
Re: Memory manager align on 4K boundaries
Thanks! Your information helped get an idea for 4KB aligning everything. I've got it 4KB aligned now.
"Out of memory: Please memorize the following numbers and type them back in when asked for page number 42". - linguofreak
"Quote me in your forum signature" - Sortie (Check!)
"Quote me in your forum signature" - Sortie (Check!)