CPS 356 Lecture notes: Demand Paging
Coverage: [OSCJ8] §§9.1-9.3 (pp. 393-405)
virtual = in effect, if not in essence
virtual memory: still limited by swaps
- 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)
- declaration of 100x100 array when typically only a 10x10 portion of
- in cases where entire program is needed,
it is generally not needed all at the same time
- 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)
Performance of 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
- 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
- service the page-fault interrupt
- read in the page
- 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
Under Linux, fork(2) is implemented using copy-on-write pages, so the only
penalty incurred by fork(2) is the time and memory required to duplicate the
parent's page tables, and to create a unique task structure for the child.
However, in the bad old days a fork(2) would require making a complete copy
of the caller's data space, often needlessly, since usually immediately
afterward an exec(3) is done. Thus, for greater efficiency, BSD introduced
the vfork() system call, which did not fully copy the address space of the
parent process, but borrowed the parent's memory and thread of control until
a call to execve(2) or an exit occurred. The parent process was suspended
while the child was using its resources. The use of vfork() was tricky: for
example, not modifying data in the parent process depended on knowing which
variables were held in a register.
||A. Silberschatz, P.B. Galvin, and G. Gagne.
Operating Systems Concepts with Java.
John Wiley and Sons, Inc., Eighth edition, 2010.