OSDev.org
https://forum.osdev.org/

What is the relationship between page addressing and virtual
https://forum.osdev.org/viewtopic.php?f=1&t=36448
Page 1 of 1

Author:  mrjbom [ Thu Jan 16, 2020 2:17 pm ]
Post subject:  What is the relationship between page addressing and virtual

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?

Author:  Octocontrabass [ Fri Jan 17, 2020 5:50 am ]
Post subject:  Re: What is the relationship between page addressing and vir

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.

Author:  mrjbom [ Fri Jan 17, 2020 6:20 am ]
Post subject:  Re: What is the relationship between page addressing and vir

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?

Author:  ~ [ Fri Jan 17, 2020 9:49 am ]
Post subject:  Re: What is the relationship between page addressing and vir

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.

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/