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
LVL 19
mrwad99Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

phoffricCommented:
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.)
0
mrwad99Author Commented:
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??
0
ozoCommented:
In this example, users have 4GB-1GB=3GB virtual space on a machine with 1GB physical memory
0
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

mrwad99Author Commented:
?  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??
0
ozoCommented:
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.
0
mrwad99Author Commented:
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>
0
ozoCommented:
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.
0
mrwad99Author Commented:
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!
0
ozoCommented:
In this scenario, we are only able to address 1GB of that physical ram because that is all the physical ram we have available.

If we had 4GB of physical ram, then we would have had 32 bits of physical address.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
mrwad99Author Commented:
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?
0
ozoCommented:
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.
0
mrwad99Author Commented:
I haven't forgotten this; I need to take more time to study what has been said so bear with me please :)
0
mrwad99Author Commented:
Thanks.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Theory

From novice to tech pro — start learning today.