Virtual Memory

References:

  1. Abraham Silberschatz, Greg Gagne, and Peter Baer Galvin, "Operating System Concepts, Ninth Edition ", Chapter 9

9.1 Background


Figure 9.1 - Diagram showing virtual memory that is larger than physical memory


Figure 9.2 - Virtual address space


Figure 9.3 - Shared library using virtual memory

9.2 Demand Paging


Figure 9.4 - Transfer of a paged memory to contiguous disk space

9.2.1 Basic Concepts


Figure 9.5 - Page table when some pages are not in main memory.


Figure 9.6 - Steps in handling a page fault

9.2.2 Performance of Demand Paging

( 1 - p ) * ( 200 ) + p * 8000000

= 200 + 7,999,800 * p

which clearly depends heavily on p! Even if only one access in 1000 causes a page fault, the effective access time drops from 200 nanoseconds to 8.2 microseconds, a slowdown of a factor of 40 times. In order to keep the slowdown less than 10%, the page fault rate must be less than 0.0000025, or one in 399,990 accesses.

9.3 Copy-on-Write


Figure 9.7 - Before process 1 modifies page C.


Figure 9.8 - After process 1 modifies page C.

9.4 Page Replacement


Figure 9.9 - Ned for page replacement.

9.4.1 Basic Page Replacement


Figure 9.10 - Page replacement.


Figure 9.11 - Graph of page faults versus number of frames.

9.4.2 FIFO Page Replacement


Figure 9.12 - FIFO page-replacement algorithm.


Figure 9.13 - Page-fault curve for FIFO replacement on a reference string.

9.4.3 Optimal Page Replacement


Figure 9.14 - Optimal page-replacement algorithm

9.4.4 LRU Page Replacement


Figure 9.15 - LRU page-replacement algorithm.


Figure 9.16 - Use of a stack to record the most recent page references.

9.4.5 LRU-Approximation Page Replacement

9.4.5.1 Additional-Reference-Bits Algorithm

9.4.5.2 Second-Chance Algorithm


Figure 9.17 - Second-chance ( clock ) page-replacement algorithm.

9.4.5.3 Enhanced Second-Chance Algorithm

9.4.6 Counting-Based Page Replacement

9.4.7 Page-Buffering Algorithms

There are a number of page-buffering algorithms that can be used in conjunction with the afore-mentioned algorithms, to improve overall performance and sometimes make up for inherent weaknesses in the hardware and/or the underlying page-replacement algorithms:

9.4.8 Applications and Page Replacement

9.5 Allocation of Frames

We said earlier that there were two important tasks in virtual memory management: a page-replacement strategy and a frame-allocation strategy. This section covers the second part of that pair.

9.5.1 Minimum Number of Frames

9.5.2 Allocation Algorithms

9.5.3 Global versus Local Allocation

9.5.4 Non-Uniform Memory Access

9.6 Thrashing

9.6.1 Cause of Thrashing


Figure 9.18 - Thrashing


Figure 9.19 - Locality in a memory-reference pattern.

9.6.2 Working-Set Model


Figure 9.20 - Working-set model.

9.6.3 Page-Fault Frequency


Figure 9.21 - Page-fault frequency.


Unnumbered side bar in Ninth Edition

9.7 Memory-Mapped Files

9.7.1 Basic Mechanism


Figure 9.22 Memory-mapped files.

9.7.2 Shared Memory in the Win32 API


Figure 9.23 - Shared memory in Windows using memory-mapped I/O.


Figure 9.24


Figure 9.25

9.7.3 Memory-Mapped I/O

9.8 Allocating Kernel Memory

9.8.1 Buddy System


Figure 9.26

9.8.2 Slab Allocation


Figure 9.27 - Slab allocation.

9.9 Other Considerations

9.9.1 Prepaging

9.9.2 Page Size

9.9.3 TLB Reach

9.9.4 Inverted Page Tables

9.9.5 Program Structure

9.9.6 I/O Interlock and Page Locking

There are several occasions when it may be desirable to lock pages in memory, and not let them get paged out:


Figure 9.28 - The reason why frames used for I/O must be in memory.

9.10 Operating-System Examples ( Optional )

9.10.1 Windows

9.10.2 Solaris


Figure 9.29 - Solaris page scanner.

9.11 Summary