Chapter 3- Memory Managment and Virtual Memory
Chapter 3- Memory Managment and Virtual Memory
Registers <1
nsec
2 nsec
Cache Memory
10 nsec
Main Memory
10 msec
Magnetic Disk
Magnetic Tape 100 sec
User Program
User Program
User program
OS in RAM OS in RAM
0
Palm tops, Early PC w/r
Formerly in main portion of a
embedded
frames and system is called
systems and
minicomputers BIOS
Smart cards
In all cases only one process can run at a time
◦ No Swapping and Paging (ex. Three level scheduling in batch
system)
Multiprogramming with Fixed Partitions
• An easy way to achieve MP is to
divide Memory in to Unequal
partitions.
• For efficient CPU utilization
• Partitioning can be done
manually.
• Fixed memory partitions
• Some space may not be used by a
job hence will be lost
– Multiple input queue
• Dis advantageous in the case of
P3 and P1
– Single input queue
• Small Jobs can be unworthy of
having the whole partitions.
• Another approach is implemented
– Always reserve a small partition
• Modeling multiprogramming
• Analysis of multiprogramming system
performance
• Relocation and protection
Swapping
a) A part of memory with five processes and three holes. The tick marks show the
memory allocation units. The shaded regions (0 in the bitmap) are free.
(b) The corresponding bitmap.
(c) The same information as a list.
MM using Linked List
• Four neighbor combinations for the
terminating process, X.
Virtual Memory
Formerly Overlays were used as a virtual memory.
◦ Splitting done manually by the programmer
◦ Swapping done by the system
But some overlay systems were so complex and
expensive to work with. And the first task, by nature, is
time consuming and boring.
Hence in 1961 a method of doing every thing using
system is advised.
◦ i.e. Virtual Memory.
The main idea is to put currently used data, program
and stack in the main memory and the rest in the disk.
◦ i.e. X MB Program can run on YMB machine where X>>Y
and X and Y are size of power of 2
Paging
• VM uses a technique called paging.
– For instance- the instruction MOV REG,1000 –
copy the content of memory address 1000 in to
REG
Paging…
Pages and page frames are always
equal. Here 4KB
◦ How much pages and
page frames can we get
from 64 KB of Virtual
address space and 32 KB
of physical memory?
Lets do the following instruction.
MOV REG 0
MOV REG 8192
will be transformed in to ___,
and ____, output will be
moved to bus
What happens if the program
tries to use MOV REG,
32780
Paging … page tables
Purpose : map virtual pages
onto page Frames.
Major issues to be faced
1. The page table can be
extremely large
2. The mapping must be fast.
Paging … page tables
Page table Entry Structure
What happens if there is no free frame?
• Page replacement – find some page in memory,
but not really in use, swap it out.
– Algorithm- want an algorithm which will result in
minimum number of page faults.
– performance – reduce overhead
• Same page may be brought into memory several
times.
• Same with cache memory cleaning and removing
heavily used web pages from the server
Page Replacement
• Prevent over-allocation of memory by modifying page-
fault service routine to include page replacement.
– A process may have 10 pages but only 5 are in use. Demand
paging only brings in those 5. This allows us to bring more
programs into memory – increase degree of multiprogramming
or over-allocating memory. If have 40 frames, run 8 processes
using 5 pages each instead of 4 processes using 10 pages. What
happens when a process suddenly needs all 10 pages? All
memory is in use.
– Terminate process – why, it is running normally
– Swap out a process – will be considered later
– Page replacement
Need For Page Replacement
Basic Page Replacement
1. Find the location of the desired page on disk.
2. Find a free frame:
- If there is a free frame, use it.
- If there is no free frame, use a page replacement
algorithm to select a victim frame.
3. Read the desired page into the (newly) free frame.
Update the page and frame tables.
4. Restart the process.
Use modify (dirty) bit to reduce overhead of page
transfers – only modified pages are written to disk.
Page replacement completes separation between logical
memory and physical memory – large virtual memory
can be provided on a smaller physical memory.
Page Replacement
Page Replacement Algorithms
• Want lowest page-fault rate.
• Evaluate algorithm by running it on a
particular string of memory references
(reference string) and computing the number
of page faults on that string.
• In all our examples, the reference string is
What happens when we have 4 frames?
Replace page that will not be used for longest period of time.