os9-p3c9-virtualmemory
os9-p3c9-virtualmemory
E-mail: hoai@hcmut.edu.vn
(partly based on slides of Le Thanh Van)
1 / 42
Outline
1 Background
3 Page-replacement algorithms
4 Frame allocation
5 Thrashing
6 Other consideration
2 / 42
Outline
1 Background
3 Page-replacement algorithms
4 Frame allocation
5 Thrashing
6 Other consideration
3 / 42
Role of virtual memory
4 / 42
Role of virtual memory
5 / 42
Demand paging
Idea
Demand paging is a strategy to load pages only as they are
needed (pager is not swapper)
Valid-invalid bit is
used to check
memory resident of a
page
6 / 42
Steps in demand paging
Pure demand paging
7 / 42
Hardware support
8 / 42
Hardware support
9 / 42
Performance of demand paging
Denote p be probability of a page fault
Effective access time = (1 − p) × memory access time
+p × page fault time
Page fault time generally consists of
1 Service the page-fault interrupt
2 Read in the page
3 Restart the process
10 / 42
Performance of demand paging
Denote p be probability of a page fault
Effective access time = (1 − p) × memory access time
+p × page fault time
Page fault time generally consists of
1 Service the page-fault interrupt
2 Read in the page
3 Restart the process
1 Background
3 Page-replacement algorithms
4 Frame allocation
5 Thrashing
6 Other consideration
12 / 42
Copy-on-write
Copy-on-write
Rapid process creation
Minimizing the number of new pages allocated to newly
created processes
Before
13 / 42
Page replacement
Some processes can utilize less pages than demanding
⇒ In order to increase multiprogramming degree, OS could
over-allocating memory (when increasing multiprogramming
degree)
14 / 42
Page replacement
Some processes can utilize less pages than demanding
⇒ In order to increase multiprogramming degree, OS could
over-allocating memory (when increasing multiprogramming
degree)
15 / 42
Basic page replacement
16 / 42
Basic page replacement
Minor tunnings
Many stuffs in above scheme can be modified to get better
performance, such as
modify bit (no need to write pages without any modification).
Read-only pages can be discarded when desired.
17 / 42
Outline
1 Background
3 Page-replacement algorithms
4 Frame allocation
5 Thrashing
6 Other consideration
18 / 42
Page replacement algorithm
Questions
How many frames allocated for a process ?
Which frame to be replaced ?
Different programs have different memory references
(namely reference string)
19 / 42
FIFO page replacement
20 / 42
FIFO page replacement
15 page faults
21 / 42
Optimal replacement algorithm
22 / 42
Optimal replacement algorithm
23 / 42
Optimal replacement algorithm
9 page faults
24 / 42
Optimal replacement algorithm
9 page faults
26 / 42
LRU replacement algorithm
27 / 42
LRU replacement algorithm
28 / 42
Other algorithms
29 / 42
Outline
1 Background
3 Page-replacement algorithms
4 Frame allocation
5 Thrashing
6 Other consideration
30 / 42
Minimum number of frames
→ 6 pages totally
31 / 42
Allocation algorithms
There are m frames
Equal allocation: n processes → b mn c for each process
Proportional allocation: virtual memory size of pi is si
X
a i = m × si / si
32 / 42
Allocation algorithms
There are m frames
Equal allocation: n processes → b mn c for each process
Proportional allocation: virtual memory size of pi is si
X
a i = m × si / si
1 Background
3 Page-replacement algorithms
4 Frame allocation
5 Thrashing
6 Other consideration
34 / 42
Thrashing
A process has no enough frames. Page faults occur frequently.
Time for paging is more than that for execution.
35 / 42
Thrashing
A process has no enough frames. Page faults occur frequently.
Time for paging is more than that for execution.
Thrashing
High paging activity is called thrashing
36 / 42
Working with thrashing
37 / 42
Working-set model
∆: working-set window
Working set: set of pages in the most recent ∆ pages
references
∆ = 10
39 / 42
Outline
1 Background
3 Page-replacement algorithms
4 Frame allocation
5 Thrashing
6 Other consideration
40 / 42
Prepaging: prevent large number of page faults that
occur when a process is started
Page size: choice of page sige is often performed in OS
design
TLB reach
Inverted page tables
Program structure
int i, j; int i, j;
int data[128][128]; int data[128][128];
41 / 42
Prepaging: prevent large number of page faults that
occur when a process is started
Page size: choice of page sige is often performed in OS
design
TLB reach
Inverted page tables
Program structure
int i, j; int i, j;
int data[128][128]; int data[128][128];