How do I control access to memory via virtual addresses?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
User avatar
mrjbom
Member
Member
Posts: 317
Joined: Sun Jul 21, 2019 7:34 am

How do I control access to memory via virtual addresses?

Post by mrjbom »

Hi.
I write MMU. And I have 4 questions about this.
1. I want to store page addresses and their busy status, for this I will create an array of 1048575 elements, is this correct?
2. I want to search for pages using a loop that will go through all the pages and search for free pages, on a virtual machine iterating over such a large array takes about 0.04-0.07 seconds and it seems to me that this is normal. Is this correct?
3. Upon request of memory, you will be given a virtual address, how can I when queried, the virtual address to give the physical address?
4. Do I use virtual addresses when allocating memory in the kernel?

I am particularly interested in the answer to question 2 and 3.
Thanks.
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How do I control access to memory via virtual addresses?

Post by iansjack »

1. You could use a bitmap instead. This reduces the storage to 1/8th and ...

2. ... increases the speed of searches.

3. You read the value from the appropriate Page Table entry.

4. Yes (although you may need to use physical addresses in some device drivers - e.g. for buffers in a NIC driver).
User avatar
mrjbom
Member
Member
Posts: 317
Joined: Sun Jul 21, 2019 7:34 am

Re: How do I control access to memory via virtual addresses?

Post by mrjbom »

iansjack wrote:1. You could use a bitmap instead. This reduces the storage to 1/8th and ...

2. ... increases the speed of searches.

3. You read the value from the appropriate Page Table entry.

4. Yes (although you may need to use physical addresses in some device drivers - e.g. for buffers in a NIC driver).
With regard to 1 and 2.

1. What kind of bitmap?
2. Using bitmap will increase the speed by 1/8?
User avatar
iansjack
Member
Member
Posts: 4703
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: How do I control access to memory via virtual addresses?

Post by iansjack »

Just an array of bytes, each of the 8 bits in the byte corresponding to a physical page. If the bit is set the page is allocated, if not set it is free.

This will reduce memory used to 1/8th of a simple array and will speed searches up by a factor of more than 8. You can efficiently test 32 (or 64 bits) at a time to see if any of them are not set.
Post Reply