question about virtual memory

  • Thread starter Thread starter takashi
  • Start date Start date
T

takashi

Hi,I am very confused about what virtual memory really is. I have
heard that since a lot of programs are very big compared to relatively
small RAM these days, people started to use the part of hard drive as
a virtual memory. But suppose that I have a memory which can store the
first 10 instructions and the data those 10 instructions needs. Does
the cpu first fetches all of those informations in RAM, and then once
the cpu is done with those instructions and data, it looks for the
next 10 instructions in the hard drive, and copy those instructions
into RAM to execute them? Or the cpu simply goes to the virtual
memory(hard drive)
in a very random way? I have got the feeling that accessing to a hard
drive takes much longer than retrieving the data from RAM, so it seems
more reasonable to fetch as many related instructions and data into
RAM first, instead of fetching a piece of instructions or data from a
hard drive randomly..
I am also confused with the term " offset". This term was used when
the idea that a virtual memory consists of "pages" was introduced. I
was told that pages consist of "virtual page frame number" and
"offset". I still don't understand what this offset does. It seems
that in order to relate the address in virtual memory to the address
in physical memeory,a process page table needs only a virtual page
frame number.
Could anybody help me?
Thank you, and have a good day.
 
Hi,I am very confused about what virtual memory really is. I have
heard that since a lot of programs are very big compared to relatively
small RAM these days, people started to use the part of hard drive as
a virtual memory. But suppose that I have a memory which can store the
first 10 instructions and the data those 10 instructions needs. Does
the cpu first fetches all of those informations in RAM, and then once
the cpu is done with those instructions and data, it looks for the
next 10 instructions in the hard drive, and copy those instructions
into RAM to execute them? Or the cpu simply goes to the virtual
memory(hard drive)
in a very random way? I have got the feeling that accessing to a hard
drive takes much longer than retrieving the data from RAM, so it seems
more reasonable to fetch as many related instructions and data into
RAM first, instead of fetching a piece of instructions or data from a
hard drive randomly..
I am also confused with the term " offset". This term was used when
the idea that a virtual memory consists of "pages" was introduced. I
was told that pages consist of "virtual page frame number" and
"offset". I still don't understand what this offset does. It seems
that in order to relate the address in virtual memory to the address
in physical memeory,a process page table needs only a virtual page
frame number.


not everything you;ve heard is quite correct...
many years ago RAM was quite expensive so most computers had very little...
but today RAM is a lot less expensive so most people have a lot of it in
their
machines

as an application uses RAM...if there is not enough avail...
then the virtual memory (swapfile) is used..
and yes, you are correct, using the harddrive for "memory"
is a lot slower than using actual RAM.

back in the days when machines might have only had 8 megs of RAM...
virtual memory was quite important...
but with machines having 500megs to 1 gig of RAM...
it's not too likely that virtual memory is terribly important...
 
Hi,I am very confused about what virtual memory really is. I have
heard that since a lot of programs are very big compared to relatively
small RAM these days, people started to use the part of hard drive as
a virtual memory. But suppose that I have a memory which can store the
first 10 instructions and the data those 10 instructions needs. Does
the cpu first fetches all of those informations in RAM, and then once
the cpu is done with those instructions and data, it looks for the
next 10 instructions in the hard drive, and copy those instructions
into RAM to execute them? Or the cpu simply goes to the virtual
memory(hard drive)
in a very random way? I have got the feeling that accessing to a hard
drive takes much longer than retrieving the data from RAM, so it seems
more reasonable to fetch as many related instructions and data into
RAM first, instead of fetching a piece of instructions or data from a
hard drive randomly..
I am also confused with the term " offset". This term was used when
the idea that a virtual memory consists of "pages" was introduced. I
was told that pages consist of "virtual page frame number" and
"offset". I still don't understand what this offset does. It seems
that in order to relate the address in virtual memory to the address
in physical memeory,a process page table needs only a virtual page
frame number.
Could anybody help me?
Thank you, and have a good day.

Clear up a couple of points
The CPU Always fetches instructions from RAM. It never talks directly
to a hard drive. A hard drive is always read and written in blocks,
which are normally 512KB. So how does virtual memory work.

An X86 processor can logically address 4gb of memory. Using special
registers in the processor, physical ram addresses can be mapped to
any part of that address space in chunks called pages. In addition
these registers can also indicate that memory doesn't exist, or that
the memory is on an external storage device (virtual memory). When a
program references memory that is not present (swapped out,
non-existant), a special processor event called a trap suspends the
current instruction, save the processor state, and passes control to a
special service routine in the OS to figure out what to do. That
routine will find a place in ram to swap in the page from external
storage. It might have to write a page already in memory to this
external storage to make room for the needed memory. Once this is
done, the program resumes the interupted instruction. If the page
requested has never been allocated, then it may get allocated or a
page fault error can occur and the program terminated.

This is very simplified, but I hope it helps
 
Back
Top