Chapter 10: Virtual Memory
Chapter 10: Virtual Memory
Chapter 10: Virtual Memory
=
=
for allocation
frames of number total
process of size
59 64
137
127
5 64
137
10
127
10
64
2
1
2
~ =
~ =
=
=
=
a
a
s
s
m
i
Silberschatz, Galvin and Gagne 2002 10.37 Operating System Concepts
Priority Allocation
Use a proportional allocation scheme using priorities
rather than size.
If process P
i
generates a page fault,
select for replacement one of its frames.
select for replacement a frame from a process with lower
priority number.
Silberschatz, Galvin and Gagne 2002 10.38 Operating System Concepts
Global vs. Local Allocation
Global replacement process selects a replacement
frame from the set of all frames; one process can take a
frame from another.
Local replacement each process selects from only its
own set of allocated frames.
Silberschatz, Galvin and Gagne 2002 10.39 Operating System Concepts
Thrashing
If a process does not have enough pages, the page-
fault rate is very high. This leads to:
low CPU utilization.
operating system thinks that it needs to increase the degree
of multiprogramming.
another process added to the system.
Thrashing a process is busy swapping pages in and
out.
Silberschatz, Galvin and Gagne 2002 10.40 Operating System Concepts
Thrashing
Why does paging work?
Locality model
Process migrates from one locality to another.
Localities may overlap.
Why does thrashing occur?
E size of locality > total memory size
Silberschatz, Galvin and Gagne 2002 10.41 Operating System Concepts
Locality In A Memory-Reference Pattern
Silberschatz, Galvin and Gagne 2002 10.42 Operating System Concepts
Working-Set Model
A working-set window a fixed number of page
references
Example: 10,000 instruction
WSS
i
(working set of Process P
i
) =
total number of pages referenced in the most recent A
(varies in time)
if A too small will not encompass entire locality.
if A too large will encompass several localities.
if A = will encompass entire program.
D = E WSS
i
total demand frames
if D > m Thrashing
Policy if D > m, then suspend one of the processes.
Silberschatz, Galvin and Gagne 2002 10.43 Operating System Concepts
Working-set model
Silberschatz, Galvin and Gagne 2002 10.44 Operating System Concepts
Keeping Track of the Working Set
Approximate with interval timer + a reference bit
Example: A = 10,000
Timer interrupts after every 5000 time units.
Keep in memory 2 bits for each page.
Whenever a timer interrupts copy and sets the values of all
reference bits to 0.
If one of the bits in memory = 1 page in working set.
Why is this not completely accurate?
Improvement = 10 bits and interrupt every 1000 time
units.
Silberschatz, Galvin and Gagne 2002 10.45 Operating System Concepts
Page-Fault Frequency Scheme
Establish acceptable page-fault rate.
If actual rate too low, process loses frame.
If actual rate too high, process gains frame.
Silberschatz, Galvin and Gagne 2002 10.46 Operating System Concepts
Other Considerations
Prepaging
Page size selection
fragmentation
table size
I/O overhead
locality
Silberschatz, Galvin and Gagne 2002 10.47 Operating System Concepts
Other Considerations (Cont.)
TLB Reach - The amount of memory accessible from the
TLB.
TLB Reach = (TLB Size) X (Page Size)
Ideally, the working set of each process is stored in the
TLB. Otherwise there is a high degree of page faults.
Silberschatz, Galvin and Gagne 2002 10.48 Operating System Concepts
Increasing the Size of the TLB
Increase the Page Size. This may lead to an increase in
fragmentation as not all applications require a large page
size.
Provide Multiple Page Sizes. This allows applications
that require larger page sizes the opportunity to use them
without an increase in fragmentation.
Silberschatz, Galvin and Gagne 2002 10.49 Operating System Concepts
Other Considerations (Cont.)
Program structure
int A[][] = new int[1024][1024];
Each row is stored in one page
Program 1 for (j = 0; j < A.length; j++)
for (i = 0; i < A.length; i++)
A[i,j] = 0;
1024 x 1024 page faults
Program 2 for (i = 0; i < A.length; i++)
for (j = 0; j < A.length; j++)
A[i,j] = 0;
1024 page faults
Silberschatz, Galvin and Gagne 2002 10.50 Operating System Concepts
Other Considerations (Cont.)
I/O Interlock Pages must sometimes be locked into
memory.
Consider I/O. Pages that are used for copying a file from
a device must be locked from being selected for eviction
by a page replacement algorithm.
Silberschatz, Galvin and Gagne 2002 10.51 Operating System Concepts
Reason Why Frames Used For I/O Must Be In Memory
Silberschatz, Galvin and Gagne 2002 10.52 Operating System Concepts
Operating System Examples
Windows NT
Solaris 2
Silberschatz, Galvin and Gagne 2002 10.53 Operating System Concepts
Windows NT
Uses demand paging with clustering. Clustering brings
in pages surrounding the faulting page.
Processes are assigned working set minimum and
working set maximum.
Working set minimum is the minimum number of pages
the process is guaranteed to have in memory.
A process may be assigned as many pages up to its
working set maximum.
When the amount of free memory in the system falls
below a threshold, automatic working set trimming is
performed to restore the amount of free memory.
Working set trimming removes pages from processes that
have pages in excess of their working set minimum.
Silberschatz, Galvin and Gagne 2002 10.54 Operating System Concepts
Solaris 2
Maintains a list of free pages to assign faulting processes.
Lotsfree threshold parameter to begin paging.
Paging is peformed by pageout process.
Pageout scans pages using modified clock algorithm.
Scanrate is the rate at which pages are scanned. This
ranged from slowscan to fastscan.
Pageout is called more frequently depending upon the
amount of free memory available.
Silberschatz, Galvin and Gagne 2002 10.55 Operating System Concepts
Solar Page Scanner