Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Virtual to physical address: bits being lost in translation?

Posted on 2014-10-20
13
Medium Priority
?
212 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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
 
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 2000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This article will show how Aten was able to supply easy management and control for Artear's video walls and wide range display configurations of their newsroom.
Simple Linear Regression
Starting up a Project

715 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