Memory manager align on 4K boundaries

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
michaellangford
Posts: 21
Joined: Tue Jun 21, 2016 6:41 am
Libera.chat IRC: quad4

Memory manager align on 4K boundaries

Post by michaellangford »

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!)
User avatar
Ch4ozz
Member
Member
Posts: 170
Joined: Mon Jul 18, 2016 2:46 pm
Libera.chat IRC: esi

Re: Memory manager align on 4K boundaries

Post by Ch4ozz »

Im using this for my malloc function:

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;
}
Nothing too advanced though, just change the * 0x1000 to your needs

Hope I understood your question right
Sourcer
Member
Member
Posts: 58
Joined: Fri Jun 17, 2016 11:29 pm
Libera.chat IRC: WalterPinkman

Re: Memory manager align on 4K boundaries

Post by Sourcer »

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)
User avatar
michaellangford
Posts: 21
Joined: Tue Jun 21, 2016 6:41 am
Libera.chat IRC: quad4

Re: Memory manager align on 4K boundaries

Post by michaellangford »

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!)
Post Reply