<< Chapter < Page Chapter >> Page >

So far we have disentangled the programmer's view of memory from the system's view using a mapping mechanism. Each sees a differentorganization. This makes it easier for the OS to shuffle users around and simplifies memory sharing between users.

However, until now a user process had to be completely loaded into memory before it could run. This is wasteful since aprocess only needs a small amount of its total memory at any one time (locality). Virtual memory permits a process to run with only some of itsvirtual address space loaded into physical memory.

The memory hierarchy

The idea is to produce the illusion of a memory with the size of the disk and the speed of main memory.

Data can be in registers (very fast), caches (fast), main memory (not so fast, or disk (slow). Keep the things that you usefrequently as close to you (and as fast to access) as possible.

The reason that this works is that most programs spend most of their time in only a small piece of the code. Give Knuth'sestimate of 90% of the time in 10% of the code. Introduce again the principle oflocality.

Page faults

If not all of process is loaded when it is running, what happens when it references a byte that is only in the backing store?Hardware and software cooperate to make things work anyway.

  • First, extend the page tables with an extra bit "present". If present is not set then a reference to the page results in a trap. This trap isgiven a special name, page fault.
  • Any page not in main memory right now has the "present" bit cleared in its page table entry.
  • When page fault occurs:
    • Operating system brings page into memory.
    • Page table is updated, "present" bit is set.
    • The process is continued.

Continuing process is very tricky, since it may have been aborted in the middle of an instruction. Do not want user process tobe aware that the page fault even happened.

  • Can the instruction just be skipped?
  • Suppose the instruction is restarted from the beginning. How is the "beginning" located?
  • Even if the beginning is found, what about instructions with side effects, like:

ld [%r2], %r2

  • Without additional information from the hardware, it may be impossible to restart a process after a page fault. Machines that permitrestarting must have hardware support to keep track of all the side effects so that they can be undone before restarting.
  • Forest Baskett's approach for the old Zilog Z8000 (two processors, one just for handling page faults)
  • IBM 370 solution (execute long instructions twice).
  • If you think about this when designing the instruction set, it is not too hard to make a machine virtualizable. It is much harder to do afterthe fact. VAX is example of doing it right.

Effective access time calculation

We can calculate the estimated cost of page faults by performing an effective access time calculation. The basic idea is thatsometimes you access a location quickly (there is no page fault) and sometimes more slowly (you have to wait for a page to come into memory). We use the costof each type of access and the percentage of time that it occurs to compute the average time to access a word.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Operating systems. OpenStax CNX. Aug 13, 2009 Download for free at http://cnx.org/content/col10785/1.2
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Operating systems' conversation and receive update notifications?

Ask