Professional Documents
Culture Documents
Chapter 4
• The impact that virtual memory had on
multiprogramming
1 2
Concept
Introduction
• Evolution of virtual memory • Virtual memory – separation of user logical
memory from physical memory.
– Paged, segmented, segmented / demand paging
– Foundation for current virtual memory methods
– Only part of the program needs to be in memory
• Improvement areas for execution
– Need for placement of entire program in memory – Logical address space can therefore be much
during execution larger than physical address space
– Fragmentation – Allows address spaces to be shared by several
processes
Chapter 4
Chapter 4
3 4
• Advantages:
– Job size not restricted to size of main memory
– Memory used more efficiently
– Allows an unlimited amount of multiprogramming
– Eliminates external fragmentation and minimizes
Chapter 4
Chapter 4
internal fragmentation
– Allows the sharing of code and data
5 6
1
Operating Systems Operating Systems
Chapter 4
(Not cover in this course)
7 8
Demand Paging
• Allowed for wide availability of virtual memory
concept
– Provides appearance of almost infinite or nonfinite
Virtual Memory: physical memory
Demand Paging – Jobs run with less main memory than required in
paged memory allocation scheme
• Disadvantage(s):
– Increased overhead Solution: Swapping
caused by tables and page • how and when pages
passed in memory
Chapter 4
Chapter 4
interrupts • Depends on
– Requires high-speed direct predefined policies
access storage device
9 10
Chapter 4
11 12
2
Operating Systems Operating Systems
D E
valid but is currently
• Initially valid–invalid bit is set to i on all entries on the disk.
G H
• Access to a page
Chapter 4
Chapter 4
marked invalid Backing Store
Chapter 4
Chapter 4
Backing Store
4. Restart the process;
17 18
3
Operating Systems Operating Systems
– Reference string 4
2
– Number of frames
Chapter 4
Chapter 4
1 2 3 4 5 6
Number of Frames
19 20
Chapter 4
1 4 1 6 1 6 1 6 1 6 1 Frame #2 6
Chapter 4
4
Operating Systems Operating Systems
Chapter 4
• Best page to remove is least recently accessed • Most Frequently Used (MFU)
– Optimal Page Replacement (OPT) policy
25 26
• Efficiency
– Ratio of page interrupts to page requests
• Not so good
Chapter 4
Chapter 4
• FIFO anomaly
– More memory does not lead to better performance
27 28
Chapter 4
29 30
5
Operating Systems Operating Systems
• Efficiency
– Causes either decrease in or same number of
interrupts
Chapter 4
Chapter 4
– Slightly better (compared to FIFO)
31 32
• Two implementations:
– Counter
• Every page entry has a counter;
• Every time page is referenced through this entry,
Chapter 4
Chapter 4
Chapter 4
35 36
6
Operating Systems Operating Systems
Chapter 4
37 38
Page Replacement
• Global Replacement:
– Choose frames from all sets of frames in the system;
– Process cannot control page-fault rate by itself;
Virtual Memory:
• Local Replacement:
Demand Paging
– Choose frames already allocated to the process;
– Effect – a process may keep pages that are seldom
used while other process that need more frames has
a high page fault rate;
(Some Issues)
Chapter 4
Chapter 4
Thrashing …Thrashing
• Why does this happen?
– An excessive amount of page swapping or – If CPU utilization is low, OS increase the degree of
paging activity (in & out) between main memory multiprogramming;
and secondary storage; – The number of programs increases while the number
– A process is thrashing if it spends more time on of frames remains the same;
paging than executing; – Therefore, page fault will occur more frequently;
CPU Utilization
Thrashing
• Consequences:
Chapter 4
Chapter 4
7
Operating Systems Operating Systems
Example :
How to prevent thrashing?
Page fault due to program structure
• Program structure
Ø Int[128,128] data;
Ø Each row is stored in one page
Ø Program 1
Two Techniques
for (j = 0; j <128; j++)
for (i = 0; i < 128; i++)
data[i,j] = 0;
Chapter 4
for (j = 0; j < 128; j++)
data[i,j] = 0;
Upper bound
Increase number of frames
• If page-fault rate > upper bound, allocate more
frames
• If page-fault rate < lower bound, reduce frame Lower bound
allocation Decrease number of frames
Chapter 4
Chapter 4
Number of Frames
45 46
• System decides:
– Number of pages comprising working set;
– Maximum number of pages allowed for a working
set;
Chapter 4
• Working-Set à the set of pages in the most – If ∆ too large à may overlap page several localities;
recent ∆ page references;
47 48
8
Operating Systems Operating Systems
Tutorial Summary
Consider the following page reference string:
• Segmented / demand paged memory
1 2 3 4 2 1 5 6 2 1 2 3 7 6 3 2 1 2 3 6 – Problems solved
• Compaction, external fragmentation
Chapter 4
• FIFO replacement.
• LRU replacement.
• OPT replacement.
49 50
Chapter 4
51 52