Solved

Virtual to physical address: bits being lost in translation?

Posted on 2014-10-20
13
202 Views
Last Modified: 2014-10-26
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
0
Comment
Question by:mrwad99
  • 7
  • 5
13 Comments
 
LVL 32

Expert Comment

by:phoffric
ID: 40392304
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
 
LVL 19

Author Comment

by:mrwad99
ID: 40392368
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
 
LVL 84

Expert Comment

by:ozo
ID: 40392498
In this example, users have 4GB-1GB=3GB virtual space on a machine with 1GB physical memory
0
 
LVL 19

Author Comment

by:mrwad99
ID: 40392513
?  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
 
LVL 84

Expert Comment

by:ozo
ID: 40392523
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
 
LVL 19

Author Comment

by:mrwad99
ID: 40392563
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 84

Expert Comment

by:ozo
ID: 40392567
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
 
LVL 19

Author Comment

by:mrwad99
ID: 40394211
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
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 40394218
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
 
LVL 19

Author Comment

by:mrwad99
ID: 40394278
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
 
LVL 84

Expert Comment

by:ozo
ID: 40395182
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
 
LVL 19

Author Comment

by:mrwad99
ID: 40401777
I haven't forgotten this; I need to take more time to study what has been said so bear with me please :)
0
 
LVL 19

Author Closing Comment

by:mrwad99
ID: 40405181
Thanks.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Windows 7 does not have the best desktop search built in. This is something Windows 7 users have struggled with. You type something in, and your search results don’t always match what you are looking for, or it doesn’t actually work at all. There ar…
Windows 10 is here and for most admins this means frustration and challenges getting that first working Windows 10 image. As in my previous sysprep articles, I've put together a simple help guide to get you through this process. The aim is to achiev…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now