View Single Post
  #3  
Old August 18th 03, 12:37 PM
Jim Turner
external usenet poster
 
Posts: n/a
Default

On Mon, 18 Aug 2003 07:16:00 GMT, takashi wrote:

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