Professional Documents
Culture Documents
2
Virtual Memory
• Virtual Memory is a storage allocation scheme in which secondary memory
can addressed thought it were part of the RAM
• The size of virtual memory is only limited by the size of the addressing
scheme of the computer system and by the amount of secondary memory
available
• The addresses assigned to a location in virtual memory to allow that location
to be accessed as though it were part of main memory is called virtual
address
3
Virtual Memory Terminology
4
Execution of a Process
• Operating system brings into main memory a few pieces of the program
this includes the initial program piece and the initial data piece to which
those instructions refer
• The portion of a process that is actually in main memory at any time is
defined to be the resident set of the process
• As the process executes, things proceed smoothly as long as all
memory references are to locations that are in the resident set
• Using the segment or page table, the processor is always able to
determine whether this is so
• An interrupt is generated when an address is needed that is not in main
memory
5
Implications
• More processes may be maintained in main memory
– Because only some of the pieces of any particular process are loaded,
there is room for more processes
– This leads to more efficient utilisation of the processor because it is more
likely that at least one of the more numerous processes will be in a Ready
state at any particular time
6
Implications
• A process may be larger than all of main memory
– If no virtual memory, if the program being written is too large, the
programmer must devise ways to structure the program into pieces that
can be loaded separately in some sort of overlay strategy
– With virtual memory based on paging, that job is left to the OS and the
hardware
– The OS automatically loads pieces of a process into main memory as
required
7
Real and Virtual Memory
Real Virtual
Memory Memory
8
Thrashing
9
Principle of Locality
• Program and data references within a process tend to cluster
• Only a few pieces of a process will be needed over a short period of time
• Therefore it is possible to make intelligent guesses about which pieces will be
needed in the future
• This helps to avoid thrashing
10
Support Needed for Virtual Memory
11
Paging
• The term virtual memory is usually associated with systems that employ
paging
• Each process has its own page table
– Each page table entry (PTE) contains the frame number of the corresponding page
in main memory
• A page table is needed for a virtual memory scheme based on paging
12
Paging
• Paging provides an alternative solution to compaction
• Although compaction solves external fragmentation it has a significant CPU
overhead
• Paging and segmentation are two ways which allow a processes physical
address space to be non-contiguous
• This enables us to place processes in spare address spaces regardless of
their location
13
Page Tables
• Page tables rely on two
important things: Memory Address
– Page size
RAM
– Frame size 0 Divided into equal size
(2MB)
• Page size and Frame size
Frames Size
will always be equal
• The blocks inside the RAM Page Size =
Frame Size
are referred to as frames
• Pages are block inside our
logical address space
14
Paging
15
Paging
This is difficult for the CPU as
pages are in non-contiguous
order
RAM
0 Processes in non-
Page 0 (P1) contiguous allocattion
Process 1 Logical
Occupied
0 Address Space
Page 0 Page 1 (P1)
Page 1 Occupied
Page 2 Page 2 (P1)
Page 3 Ocupied
Page 3 (P1)
16
Page Table
• With a page table we can store the mapping between virtual addresses and
physical addresses
• For every process we maintain a page table
RAM
Process 1 Logical
Address Space 0 Page 0 (P1)
0
Page 0 1 Occupied
Page 1 2 Page 1 (P1)
Page 2 3 Occupied
Page 3 4 Page 2 (P1)
5 Ocupied
6 Page 3 (P1)
Page Table of P1
Page # Frame #
Paging Example
Summary
• In this session we have covered:
– Virtual memory terminology
– Hardware control structures
– Execution of a process
– Thrashing
– Paging and why its used
– Page tables
20