Professional Documents
Culture Documents
Ch07 Main Memory and Virtual Memory
Ch07 Main Memory and Virtual Memory
Operating System Concepts – 10th Edition Silberschatz, Galvin and Gagne ©2018
Background
Operating System Concepts – 10th Edition 9.2 Silberschatz, Galvin and Gagne ©2018
Base and Limit Registers
A pair of base and limit registers define the logical address space
CPU must check every memory access generated in user mode to be
sure it is between base and limit for that user
Operating System Concepts – 10th Edition 9.3 Silberschatz, Galvin and Gagne ©2018
Logical vs. Physical Address Space
Operating System Concepts – 10th Edition 9.4 Silberschatz, Galvin and Gagne ©2018
Memory-Management Unit (MMU)
Hardware device that at run time maps virtual to physical
address. Many methods possible, covered in the rest of this
chapter
To start, consider simple scheme where the value in the
relocation register is added to every address generated by a user
process at the time it is sent to memory
Base register now called relocation register
MS-DOS on Intel 80x86 used 4 relocation registers
The user program deals with logical addresses; it never sees the
real physical addresses
Logical address bound to physical addresses
Operating System Concepts – 10th Edition 9.5 Silberschatz, Galvin and Gagne ©2018
Dynamic relocation using a relocation register
Operating System Concepts – 10th Edition 9.6 Silberschatz, Galvin and Gagne ©2018
Swapping
A process can be swapped temporarily out of memory to a backing
store, and then brought back into memory for continued execution
Total physical memory space of processes can exceed
physical memory
Backing store – fast disk large enough to accommodate copies of
all memory images for all users; must provide direct access to these
memory images
Roll out, roll in – swapping variant used for priority-based
scheduling algorithms; lower-priority process is swapped out so
higher-priority process can be loaded and executed
Major part of swap time is transfer time; total transfer time is
directly proportional to the amount of memory swapped
Operating System Concepts – 10th Edition 9.7 Silberschatz, Galvin and Gagne ©2018
Context Switch Time including Swapping
Operating System Concepts – 10th Edition 9.8 Silberschatz, Galvin and Gagne ©2018
Multiple-partition allocation
Multiple-partition allocation
Degree of multiprogramming limited by number of partitions
Variable-partition sizes for efficiency (sized to a given process’ needs)
Hole – block of available memory; holes of various size are scattered
throughout memory
When a process arrives, it is allocated memory from a hole large enough to
accommodate it
Process exiting frees its partition, adjacent free partitions combined
Operating system maintains information about:
a) allocated partitions b) free partitions (hole)
Operating System Concepts – 10th Edition 9.9 Silberschatz, Galvin and Gagne ©2018
Dynamic Storage-Allocation Problem
How to satisfy a request of size n from a list of free holes?
Worst-fit: Allocate the largest hole; must also search entire list
Produces the largest leftover hole
Operating System Concepts – 10th Edition 9.10 Silberschatz, Galvin and Gagne ©2018
First Fit vs. Best Fit vs. Worst Fit
Worst Fit
First Fit
Best Fit
Fragmentation
External Fragmentation – total memory space exists to
satisfy a request, but it is not contiguous
Internal Fragmentation – allocated memory may be slightly
larger than requested memory; this size difference is memory
internal to a partition, but not being used
First fit analysis reveals that given N blocks allocated, 0.5 N
blocks lost to fragmentation
Operating System Concepts – 10th Edition 9.12 Silberschatz, Galvin and Gagne ©2018
MM Techniques: Segmentation
Memory-management scheme that supports user view of memory A
program is a collection of segments
A segment is a logical unit such as:
main program procedure
function
method object
local variables, global variables common
block
stack symbol table
arrays
Operating System Concepts – 10th Edition 9.13 Silberschatz, Galvin and Gagne ©2018
User’s View of a Program Logical View of Segmentation
1 4
4
3 2
user space
p
h
y
s
i
Operating System Concepts – 10th Edition 9.14 Silberschatz, Galvin and Gagne ©2018
Segmentation Architecture
Logical address consists of a two tuple:
<segment-number, offset>,
Operating System Concepts – 10th Edition 9.15 Silberschatz, Galvin and Gagne ©2018
Segmentation Hardware
Operating System Concepts – 10th Edition 9.16 Silberschatz, Galvin and Gagne ©2018
Example
Operating System Concepts – 10th Edition 9.17 Silberschatz, Galvin and Gagne ©2018
Example cont.
Operating System Concepts – 10th Edition 9.18 Silberschatz, Galvin and Gagne ©2018
Paging
Physical address space of a process can be noncontiguous;
process is allocated physical memory whenever the latter is
available
Avoids external fragmentation
Avoids problem of varying sized memory chunks
Divide physical memory into fixed-sized blocks called frames
Size is power of 2, 512 bytes, 4096 and ,..16 Mbytes Divide
logical memory into blocks of same size called pages Keep
track of all free frames
To run a program of size N pages, need to find N free frames and
load program
Set up a page table to translate logical to physical addresses
Still have Internal fragmentation
Operating System Concepts – 10th Edition 9.19 Silberschatz, Galvin and Gagne ©2018
Address Translation Scheme
Address generated by CPU is divided into:
Page number (p) – used as an index into a page table which
contains base address of each page in physical memory
Page offset (d) – combined with base address to define the
physical memory address that is sent to the memory unit
Operating System Concepts – 10th Edition 9.20 Silberschatz, Galvin and Gagne ©2018
Paging Hardware
Operating System Concepts – 10th Edition 9.21 Silberschatz, Galvin and Gagne ©2018
Paging Model of Logical and Physical Memory
Operating System Concepts – 10th Edition 9.22 Silberschatz, Galvin and Gagne ©2018
Operating System Concepts – 10th Edition 9.23 Silberschatz, Galvin and Gagne ©2018
Virtual Memory Concept
Virtual memory – separation of user logical memory from physical memory
Only part of the program needs to be in memory for execution
Logical address space can therefore be much larger than physical address space
Allows address spaces to be shared by several processes
Allows for more efficient process creation
Operating System Concepts – 10th Edition 9.24 Silberschatz, Galvin and Gagne ©2018
Page Fault
A page fault occurs when the CPU generates a logical address for a
page that is not in physical memory:
Operating System Concepts – 10th Edition 9.25 Silberschatz, Galvin and Gagne ©2018
Page and Frame Replacement Algorithms
Operating System Concepts – 10th Edition 9.26 Silberschatz, Galvin and Gagne ©2018
First-In-First-Out (FIFO) Algorithm
Reference string: 7,0,1,2,0,3,0,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1
3 frames (3 pages can be in memory at a time per process)
15 page faults
Self Study:
LIFO, LRU
(Moodle: TextBook)
Operating System Concepts – 10th Edition 9.27 Silberschatz, Galvin and Gagne ©2018