PROJECT
DATE 4 MAY 2011 CLIENT OPERATING SYSTEM
VIRTUAL MEMORY -
10TH WEEK
References
Abraham Silberchatz, Peter Baer Galvin, Greg Gagne, “Operating System Concepts with
Java 6th Edition“, Wiley International
Publisher : Chapter 10
http://www.linux.com/news/software/
applications/8208-all-about-linux-swap-space http://www.linuxjournal.com/article/8178
Outline
•
Introduction•
Virtual Memory Management:•
Demand Paging•
Copy on Write•
Page ReplacementOutline
•
Introduction•
Virtual Memory Management:•
Demand Paging•
Copy on Write•
Page ReplacementCharacteristics of
User Program
•
Error Handling, executed not so frequently•
Unused allocation for array, lists, and tables - ex. : string name[10000];•
Certain features and options are usedrarely
•
It means, even though all parts of a program are loaded in main memory, we usuallyMemory sharing
•
We have common library that is used together•
No more constraint from physical memory•
Run multiple programs at the same timeVirtual Memory
•
Virtual memory – separation of user logical memory fromphysical memory
•
Virtual memory allows user to see extremely large logical memory address compared to the ‘real’ physical memory address•
Only part of the program needs to be in memory for execution•
Allows address spaces to be shared by several processesVirtual Address Space
Known as sparse address space
useful for dynamic memory allocation
Outline
•
Introduction•
Virtual Memory Management:•
Demand Paging•
Copy on Write•
Page ReplacementSwapping in Virtual Memory
Swap the whole process (conventional memory
management)
Swap only parts of process (virtual memory)
Demand Paging
•
Paged processes are loaded only when they are needed•
Lazy swapper: never swaps a page intomemory unless that page will be needed. Thus we use term pager instead of
swapper.
•
Memory I/O time and physical memory requirement decreases.Valid and Invalid Flags
•
How to know, whether our process is in memory or hard disk?Err...what about if you
can’t find your pages in
Page-fault Trap
> invalid?
> valid but not available
Pure Demand Paging
•
Extreme scenario: Faulting any page request, start executing a process with no pages, only load page when it’s needed, commonly named as puredemand paging
•
Hardware: page table and secondary disk•
You can save memory usage, but you have to go through page-fault trap mechanism whenyou need to start your process
Outline
•
Introduction•
Virtual Memory Management:•
Demand Paging•
Copy on Write•
Page ReplacementCopy on Write
•
Some processes can create child process (i.e. system call called fork() ).•
fork() bypasses demand paging mechanism•
Many child processes, OS uses shared pages.•
Should not copy parent’s pages to reduce memory usage:copy on write strategy
•
A copy of shared page is created when a process write a shared pageProcess 1 modifies “copy of page C” not the original “page C”
BEFORE
Outline
•
Introduction•
Virtual Memory Management:•
Demand Paging•
Copy on Write•
Page ReplacementPage replacement
•
Page ~ part/unit of logical memory•
Frames ~ part/unit of physical memory•
Over-Allocation: a page fault occurs when a processis executed because all spaces in memory are in use (no free frames).
•
Over-Allocation sometime occurs because ofmultiprogramming (multiple processes access the memory)
•
We have to get-rid of a ‘victim’ page using page replacement mechanism.0-1: OS’ frames 2-7: user’s frames
Page Replacement Algorithm
1. Find the location of the desired page on the disk 2. Find a free frame:
a. If there’s a free frame, use it.
b. If no free frame, use page replacement
c. Write the victim frame to disk, change the page and frame tables accordingly (valid invalid) 3. Read the desired page into the newly freed frame,
change the page and frame tables 4. Restart the user process
We want to replace frame with address f
Outline
•
Introduction•
Virtual Memory Management:•
Demand Paging•
Copy on Write•
Page ReplacementThrashing
•
If a process does not have “enough” pages, the page-fault rate is very high caused by massive page-replacement.This leads to:
# Low CPU utilization (the process is swapped around rather than executed)
# 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, so that it spends more time for paging thanexecuting
•
The effective memory time increases, no work getting done3. Multiple page-faults occur
1. CPU utilization low -
add the degree of mulitprogramming 2. A process starts to ask more frames
Prevent Thrashing
•
Local Replacement Algorithm: if one process starts thrashing, it cannot steal frames from another process.•
The problem hasn’t been solved yet, since thrashing process increases queueing time.•
We have to know, how many frames that aprocess needs? We observe the locality model of process execution. OS provides a
Locality
Locality: a set of pages that are actively used together by an executed process
Do not allocate fewer pages than a process’ current
Locality
•
Locality model: an executed process moves from locality to locality•
A program is generally composed of several different localities that may overlap•
Localities are defined by observing the program structure and its data structures(how the program uses the memory)
Working-set model
• Δ ≡ working-set window ≡ a fixed number of page references Example: Δ = 10,000 references
• WSSi (Working Set Size of Process Pi) =
Total number of pages referenced in the most recent Δ
(varies in time). The size should be carefully estimated, because: ~ if Δ too small will not reach entire locality
~ if Δ too large will overlap several localities ~ if Δ = ∞ will encompass entire program
• D = Σ WSSi ≡ total demand for frames
• m = total number of available frames
• if D > m Thrashing
Working-set model
Δ = working set window
Working set is an approximation of the program’s locality Keep the locality, even though smaller frames are used in a process
(note that in WS1 we use {1, 2, 5, 6, 7} and in WS2 we use {3, 4})
Virtual Memory in Linux
Monitoring Virtual Memory
(DEMO)