Link to home
Start Free TrialLog in
Avatar of mrwad99
mrwad99Flag for United Kingdom of Great Britain and Northern Ireland

asked on

Virtual to physical address: bits being lost in translation?

Ah hello.

(Note: I had trouble choosing the best topics for this, so apologies in advance if my choices upset anyone.)

I am reading about virtual memory, specifically the process of translating a virtual address into a physical address.  I wasn't having any real trouble until I came across the following two sets of University notes (both PDF, quite small):

http://rdsrc.us/BZZ9ic (page 12) and http://rdsrc.us/HmAy7m (page 36)

In the case of a 32bit system, both of these state that we take a 32 bit virtual address (comprised of 20 bits for the virtual page number, and 12 bits for the offset), look that up in the page table to get a corresponding page table entry which then gives us an 18 bit physical frame number, to which we append the offset to get the actual memory address.

Why do we suddenly have an 18bit physical frame number: where have the other two bits gone??

(I've probably overlooked something caused by the fact that I have been giving this subject too much attention...)

TIA
Avatar of phoffric
phoffric

The number of physical pages is usually much less than the number of virtual pages due to limited amount of physical memory. That is why you have an extended memory on disk, called the swap space.
(Sorry I don't have time to give a more extensive answer.)
Avatar of mrwad99

ASKER

OK.  If I have 18 address bits then I have 2^18 pages, which means I am addressing 2^18 * 4096 bytes = 1GB.

If I have 20 address bits I can address the full 4GB.  Now, I understand that we can't address the full 4GB for a user process because the kernel code will need to live in some of that, so can it be implied from those lecture notes that there is only 1GB of user space available?  I thought the split was 1GB to 3GB??
In this example, users have 4GB-1GB=3GB virtual space on a machine with 1GB physical memory
Avatar of mrwad99

ASKER

?  I'm not understanding you ozo.  Where are you getting the statement that the machine has 1gb physical ram?  With 32 bits we can address 4??
Yes, with 32 bits we can address 4GB of virtual space, of which the kernel uses 1GB,
and with 30 bits for physical address, we can address 1GB of physical ram.
Avatar of mrwad99

ASKER

Hmmm...ok then so it seems that if we do have a machine with 4GB (and as you have said the kernel will reserve 1GB of that for itself), then the user can only address 1GB: So what happens to the other 2GB?

Also, what happens to the other two bits; if I give a virtual address that has the two MSBs set, they get chopped off when we generate the physical address?!

<COnfused still>
The other 2GB gets swapped out onto disk.
The other 2 bits are remapped by the page table, which would indicate which of them are not currently in physical memory.
Avatar of mrwad99

ASKER

I am still confused.  Sorry; please humour me with a little more your knowledge.

Having followed through those sets of notes they don't clearly justify why we lose two bits for the physical address, which is poor for academic material.

Assuming we have 4GB virtual address space and 4GB physical memory (hence ignoring what phoffric said, which, whereas true, adds complication here), why on earth would we *choose* to only be able to address 1GB of that physical ram by using just 30 bits for the address (which is what is happening here)?  Regardless of whether or not the kernel uses 1GB, we are still not making use of 2GB?  This seems crazy!
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mrwad99

ASKER

OK; thank you.

1) So you have deduced that purely from the fact that the lecture notes show 18 bits as the physical frame address, and 12 bits as the offset (hence 30 bits), even though the notes don't actually say that anywhere?  And if that diagram would have showed the full 20 bits being used as the physical frame address (instead of 18), we could have addressed the full 4GB?  (in which case, I wouldn't have needed to ask this question!)  Correct?

2) But as has been said, the kernel often reserves 1GB for itself, so it would be doubtful if we, as users, could address the full 4GB.  (Or can we?)  If we can't, that means we can address 3GB.  However, I can't see how we could achieve this, as with a split of bits 18:12 for <physical frame number>:<offset> we can only address 1GB, with a split 19:12 we can address 2GB, and with 20:12 we can address the full 4GB.

How would we achieve the addressing of 3GB for users?
To address 3GB, you would need 32 bits of virtual address.
If the kernal has reserved 1GB of that space, then a user attempting to access that part of the 32 bit space should get a segmentation fault.
Avatar of mrwad99

ASKER

I haven't forgotten this; I need to take more time to study what has been said so bear with me please :)
Avatar of mrwad99

ASKER

Thanks.