Page 1 of 1

How do I control access to memory via virtual addresses?

Posted: Mon Feb 24, 2020 3:03 am
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.

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

Posted: Mon Feb 24, 2020 5:03 am
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).

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

Posted: Mon Feb 24, 2020 6:39 am
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?

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

Posted: Mon Feb 24, 2020 7:52 am
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.