What is the relationship between page addressing and virtual

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
mrjbom
Member
Member
Posts: 317
Joined: Sun Jul 21, 2019 7:34 am

What is the relationship between page addressing and virtual

Post by mrjbom »

Hello.
I'm trying to implement dynamic memory allocation(malloc(), free()).

I have already written page frame allocator(code), it can sequentially allocate pages of 4 KB and delete them sequentially(from the last to the first).

Will such a primitive page Manager be enough for my purpose?
If so, what should I do next?
Last edited by mrjbom on Fri Jan 17, 2020 5:57 am, edited 1 time in total.
Octocontrabass
Member
Member
Posts: 5578
Joined: Mon Mar 25, 2013 7:01 pm

Re: What is the relationship between page addressing and vir

Post by Octocontrabass »

The page frames containing your kernel are marked "available" in the multiboot memory map. You need to make sure your page frame allocator will not try to allocate those pages.

It's a good idea to translate the multiboot memory map into some other structure, such as a bitmap. This will make it easier to mark your kernel's page frames as allocated. It will also be easier to allocate and free non-sequential pages.

If you want to use virtual memory, you should write your virtual memory manager before you write your dynamic allocator since the dynamic allocator will need to call the virtual memory manager.
User avatar
mrjbom
Member
Member
Posts: 317
Joined: Sun Jul 21, 2019 7:34 am

Re: What is the relationship between page addressing and vir

Post by mrjbom »

Octocontrabass wrote:The page frames containing your kernel are marked "available" in the multiboot memory map. You need to make sure your page frame allocator will not try to allocate those pages.

It's a good idea to translate the multiboot memory map into some other structure, such as a bitmap. This will make it easier to mark your kernel's page frames as allocated. It will also be easier to allocate and free non-sequential pages.
About page frame allocator: What else do I need to do in my page frame allocator?
1. Make sure that when selecting pages, they do not touch the location where the kernel is located.
What else should I do?
User avatar
~
Member
Member
Posts: 1227
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Re: What is the relationship between page addressing and vir

Post by ~ »

mrjbom wrote:Hello.
I'm trying to implement dynamic memory allocation(malloc(), free()).

I have already written page frame allocator(code), it can sequentially allocate pages of 4 KB and delete them sequentially(from the last to the first).

Will such a primitive page Manager be enough for my purpose?
If so, what should I do next?
- Check how many free pages there are after the block and maybe before it so that you can know if there is enough room to do an expansive realloc or not.

- Make sure that you can distinguish which virtual pages belong to which block if you allocate 2 or 3 distinct contiguous blocks. You can use the AVL field of virtual pages themselves to select the same value 1 to 7 for a same block and make sure to choose a distinct one than the contiguous blocks immediately before and after it.

- Make sure that you can free any memory for a failed allocation (just set up debugging values to emulate not having enough memory at different stages).

- Write code to optimize by just copying physical page entries instead of copying page contents for reallocating your blocks for realloc when they don't fit at their current virtual area, for a huge speed improvement.

- Search for free physical and virtual memory/blocks.

- Try to allocate, resize up and down (reallocate) and free for example a 40-Megabyte block. This one will ultimately allow you to test the real speed of your algorithms. If it takes for example 2 seconds to allocate such a 40MB block, you will have to take some time apart (normally months or a year until you are expert) to find the fastest algorithms you can, to make the interesting investigation about which are the slowest parts of the code and what are the very best ways to accelerate it and exactly why.





Keeping your paging entries consistently at 0 makes it possible that you don't need any additional structures to keep track of what is allocated or free.
YouTube:
http://youtube.com/@AltComp126

My x86 emulator/kernel project and software tools/documentation:
http://master.dl.sourceforge.net/projec ... ip?viasf=1
Post Reply