CPS 346 Lecture notes: Demand Paging



Coverage: [OSCJ] §§9.1-9.3 (pp. 393-405)


Overview

virtual = in effect, if not in essence

virtual memory: still limited by swaps


Virtual Memory

  • entire process need not be in memory before it can execute
  • major advantage: programs larger than main memory can run (Fig. 9.1)
  • frees programmers from memory limitations
  • allows processes to share files easily and implement shared memory (Fig. 9.3)
  • easy mechanism for process creation (copy-on-write)
  • motivation
    • declaration of 100x100 array when typically only a 10x10 portion of it is used
    • in cases where entire program is needed, it is generally not needed all at the same time
  • benefits:
    • programmers no longer constrained by amount of main memory
    • higher degree of multiprogramming → higher CPU utilization and throughput, with no increase in response time or turnaround time
    • less I/O required to load or swap programs into memory → each program runs faster
    • more pages required only if the heap or stack grow (Fig. 9.2)


Demand Paging

  • same idea as pure paging, but now you only load a page on demand
  • this gives a higher degree of multiprogramming with only a little more overhead
  • use a lazy swapper (now called a pager) (Fig. 9.4)
  • initial load (Fig. 9.5)
  • concept of a page fault
  • where can a page fault occur (instruction or operand)?
  • in pure paging, a page fault represents a fatal error
  • in demand paging, a page fault means an additional page must be brought into memory and the instruction re-started
  • why must the instruction be restarted?
  • pure demand paging: bring no page(s) in initially; every process will page fault at least once
  • concept of locality of reference
Performance of Demand Paging
  • effective access time
  • probability of a page fault p
  • (1-p)*ma + p*page fault time


Page fault time

  • 12 step process; see list on pp. 355-356
  • Fig. 9.6
  1. service the page-fault interrupt
  2. read in the page
  3. restart the process
    Which is the most time-expensive step?
      #2 is the most time-costly; typically 8 milliseconds
      AND waiting time in queue for device.
    ma = 200ns

    pft = 8ms

    (1-p)*(200) + p*8,000,000 = 200 + 7,999,800p

    effective access time is directly proportional to page-fault rate

    if p is 1/1000, effective access time is 8.2 microseconds, a slow-down by a factor of 40 (!!!!) because of demand paging

    if we want the slowdown to be less than 10%, we need p < 0.0000025

    that is, fewer than 1 out of 399,990 accesses should fault


Copy-on-Write

  • can we do better than pure demand paging?
  • recall fork()? seem wasteful? why?
  • copy-on-write: both processes (parent and child) share all pages initially, and a shared page is only copied if and when either process writes to a shared page
  • not all shared pages need to be set to copy-on-write (e.g., pages containing the executable code)
  • Figs. 9.7 & 9.8
  • vfork(): virtual memory fork():
    • parent is suspended
    • child uses address space of the parent
    • vfork is intended to be used when the child calls exec immediately because no copying of pages takes place
    • extremely efficient method of process creation
    • sometimes used to implement command shells


References

    [OSCJ] A. Silberschatz, P.B. Galvin, and G. Gagne. Operating Systems Concepts with Java. John Wiley and Sons, Inc., Eighth edition, 2010.

Return Home