You are on page 1of 14

Virtual Memory

LECTURE 4
 places the incoming segment in the
smallest hole large enough to
accommodate the segment
 requires scanning the entire physical
memory thus slowing down the entire
Best Fit operation
 also suffers badly from external
fragmentation because of holes of small
sizes scattered throughout the physical
memory
 places the incoming segment in the
largest hole available
 creates relatively larger holes that can
be used to satisfy future segment
Worst Fit requests without frequent garbage
collection
 has drawback of scanning entire
memory to make a final decision
 starts scanning physical memory from
beginning and places the segment in
the first available hole large enough to
First Fit hold the segment
 Fast
 Outperforms all other policies
 A variation of first fit except that it scans
Next Fit memory from the address where the
most recently placed segment ends.
Address
Translation
 Combines advantages of both the worlds
 Virtual address space is divided into
segments by programmers

Paged  Segments then divided into fixed size pages


by the system

Segments  Physical memory is divided into page frames


 A segment is now composed of multiple
pages and hence, there’s no requirement of
contiguous placement of segment in
physical memory
Addressing in Paged Segmentation

 Now we have a page table per segment of a process


 Segment table is indexed by segment number
 Contains the address of the page table of that segment
 Page table is indexed by the page number of that segment
 Page table entry has the associated frame number
 Virtual Address division:

Segment # Page # Offset within the page


Virtual address

An example
Paging Segmentation Paged-Segments
Virtual Address Space is divided into fixed-size Virtual Address Space is divided into Virtual Address Space is divided into variable-
pages by the system. variable-sized segments by programmer. sized segments by programmer. These segments
are further divided into fixed-size pages by the
system.
Physical Memory is divided into fixed-size page No division of physical memory Physical Memory is divided into fixed-size page
frames by the system. frames by the system.
A page of a process can occupy any available The segments of a process can be The pages of a segment can occupy any
frames in any order. The only restriction is that placed anywhere. However, a segment available frames in any order. This simplifies the
one page needs to be contiguous in physical needs to be contiguous in physical job of placing a segment in physical memory.
memory. memory. The only restriction is that one page needs to be
contiguous in physical memory
Placing a page into a page frame is quite An intelligent placement algorithm Placing a page into a page frame is quite
straight forward as all pages and page frames needs to be in place because of straight forward as all pages and page frames
are of same size. variable-size segments. are of same size.
No external fragmentation but suffers from No internal fragmentation but suffers No external fragmentation but suffers from
internal fragmentation. from external fragmentation. internal fragmentation.
Paging and Segmentation

How are these similar: How are these different:


 Both allow programs to run despite
insufficient memory Pages Segments

 Both pages and segments are stored on Fixed sized Variable sized
disk Made to fit frames Complete
 Both pages and segments are transferred of main memory sections of a
to main memory when needed program
Problem with both: Physical divisions Logical division
 Thrashing
VM Problems

Problem 1
 Determine the page size, number of pages
in VAS and PAS, size of VAS and PAS from
the figure.
12 bit page offset field
Page # field =
20 b
Frame # field =
18 b
VAS = 232 B
PAS = 230 B
VM Problems

Solution
 Page Size
= 4KB
 #Frames
= 218
 #Pages
= 220
 Size of Main Memory (PAS)
= 1 GB
 Size of VAS
= 4 GB

You might also like