Page 1 of 1

virtual memory

Posted: Thu Sep 11, 2014 3:35 am
by szarek
Hi,
I can't understand one thing:
I'm reading that: http://www.jamesmolloy.co.uk/tutorial_h ... aging.html
And I give you the citate from this website:
4MB may seem like a large overhead, and to be fair, it is. If you have 4GB of physical RAM, it's not much. However, if you are working on a machine that has 16MB of RAM, you've just lost a quarter of your available memory! What we want is something progressive, that will take up an amount of space proportionate to the amount of RAM you have.
And now I understand why 4GB physical memory require 4MB for page table.
But, in the citate is written if we have 16 MB physically memory we also need 4MB for page table. Why?
After all, we need to map less memory than 4GB RAM.
I calculate this that:
We have 32-bit entries. Every page is 4KB. So there are 16 * 1024 / 4 = 4096 pages, so the same is number of entries. Every entries is 32bit, so:
4096*32 / 8 / 1024 = 16 KB.
Please help me :)

Re: virtual memory

Posted: Thu Sep 11, 2014 3:52 am
by Brendan
Hi,
szarek wrote:
4MB may seem like a large overhead, and to be fair, it is. If you have 4GB of physical RAM, it's not much. However, if you are working on a machine that has 16MB of RAM, you've just lost a quarter of your available memory! What we want is something progressive, that will take up an amount of space proportionate to the amount of RAM you have.
And now I understand why 4GB physical memory require 4MB for page table.
But, in the citate is written if we have 16 MB physically memory we also need 4MB for page table. Why?
After all, we need to map less memory than 4GB RAM.
So, you're saying that you "want something progressive, that will take up an amount of space proportionate to the amount of RAM you have"?
szarek wrote:I calculate this that:
We have 32-bit entries. Every page is 4KB. So there are 16 * 1024 / 4 = 4096 pages, so the same is number of entries. Every entries is 32bit, so:
4096*32 / 8 / 1024 = 16 KB.
I estimate that your kernel will only need to use 8 MiB RAM (where the other 8 MiB is left for applications/processes to use). I calculate that you'd only need 8 KiB for page tables in that case (not 16 KiB)... ;)


Cheers,

Brendan

Re: virtual memory

Posted: Thu Sep 11, 2014 3:53 am
by mallard
Imagine that, for some reason, you map the first 4KB of every 4MB block of virtual memory. That would take up 4MB of physical memory, but you'd need to have a page table for every 4MB block, taking up another 4MB.

Thus, the amount of memory required for page tables isn't just influenced by how much memory is mapped, but also how spread out it is, so the maximum amount of memory needed for page tables is always 4MB, no matter how much physical memory you actually have.