I am learning the different types of memory management. I don't understand the point of having an offset bits in a virtual address. And also why page sizes are made power of 2
?
My primary confusion is: give me an example of an offset being used in instruction to access a certain virtual address?
My second confusion is: The usual statement is that if the size of logical address is 2^m
and page size is 2^n
, then the high-order m-n bits of a logical address designate the page number.
● Page number (p) – used as an index into a page table which. contains base address of each page in physical memory. ● Page offset (d) – combined with base address to define the. physical memory address that is sent to the memory unit.
The most significant bits of the virtual or physical address specify the virtual or physical page number. The least significant bits specify the word within the page and are called the page offset.
I think your primary and secondary confusions are due to general confusion on the subject :)
Let me talk around this a bit and hopefully I can be of some help. First, an analogy - imagine that you're trying to locate a house in a city. Imagine that each house was given a unique number - you can imagine that the number of houses would soon get very large and confusing. Now imagine that you introduce the concept of streets - the house numbers now become a bit more managable as you've grouped them into nice chunks. So: Streets = Page number, house number = offset address.
The whole point of having virtual memory pages is to allow the computer to carve memory up into managable chunks and not waste too much of it. Carving it into chunks (pages) allows granular control of access, paging and other nice things like that. The smaller your pages, the less memory you're going to waste (if process A requires 32k of memory, and your page size is 64k, you're going to end up with some which isn't used), but the higher the overhead on the system.
As to why page sizes are powers of 2, this is down the not wasting space within the address. As computers are based on binary (at the moment), everything tends to boil down to powers of 2. Imagine if you have stuff based on factors of 10. 10 in binary is 1010 - you've got to use 4 bits to hold it, so why not go for the full range of values you can get out of 4 bits: 0000 - 1111 (0 to 15 = 16 values).
Sorry I've waffled on a bit - I hope this nudges you in the right direction!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With