Mar 19
Mar 19
B.Ramamurthy
Chapter 8
Virtual memory
Consider a typical, large application:
There are many components that are mutually
rarely used.
Most programs exhibit a slowly changing locality
Co
st /b Sto
yte cap rage
Acacity
ces
Desirable s ti
m e
increasing
Demand paging
Main memory (physical address space) as well as user
address space (virtual address space) are logically
partitioned into equal chunks known as pages. Main
memory pages (sometimes known as frames) and
virtual memory pages are of the same size.
Virtual address (VA) is viewed as a pair (virtual page
number, offset within the page). Example: Consider a
virtual space of 16K , with 2K page size and an
address 3045. What the virtual page number and
offset corresponding to this VA?
Virtual Page Number and
Offset
3045 / 2048 = 1
3045 % 2048 = 3045 - 2048 = 997
VP# = 1
Offset within page = 997
Page Size is always a power of 2? Why?
Page Size Criteria
Consider the binary value of address 3045 :
1011 1110 0101
for 16K address space the address will be 14
bits. Rewrite:
00 1011 1110 0101
A 2K address space will have offset range 0 -
2047 (11 bits)
001 011 1110 0101
Page# Offset within page
Demand paging (contd.)
There is only one physical address space but as many
virtual address spaces as the number of processes in
the system. At any time physical memory may
contain pages from many process address space.
Pages are brought into the main memory when
needed and “rolled out” depending on a page
replacement policy.
Consider a 8K main (physical) memory and three
virtual address spaces of 2K, 3K and 4K each. Page
size of 1K. The status of the memory mapping at
some time is as shown.
Demand Paging (contd.)
Executable
0 code space
1
2
3 LAS 0
4
5
6
7
LAS 1
Main memory
(Physical Address Space -PAS)
LAS 2
LAS - Logical Address Space
Issues in demand paging
How to keep track of which logical page goes
where in the main memory? More specifically,
what are the data structures needed?
Page table, one per logical address space.
How to translate logical address into physical
address and when?
Address translation algorithm applied every time a
memory reference is needed.
How to avoid repeated translations?
After all most programs exhibit good locality. “cache
recent translations”
Issues in demand paging
(contd.)
What if main memory is full and your process
demands a new page? What is the policy for
page replacement? LRU, MRU, FIFO, random?
Do we need to roll out every page that goes
into main memory? No, only the ones that
are modified. How to keep track of this info
and such other memory management
information? In the page table as special bits.
Support Needed for
Virtual Memory
Memory management hardware must support
paging and/or segmentation
OS must be able to manage the movement of
pages and/or segments between secondary
memory and main memory