VIRTUAL MEMORY
V.V.SUBRAHMANYAM
SOCIS, IGNOU
DATE: 02-09-07
TIME: 14-30 TO 15-15
Introduction
 Storage allocation has always been an
important consideration in computer
programming due to the high cost of
the main memory and the relative
abundance and lower cost of
secondary storage.
 Program code and data required for
execution of a process must reside in
the main memory but the main memory
may not be large enough to
accommodate the needs of an entire
process.
 Early computer programmers divided
programs into the sections that were
transferred into the main memory for
the period of processing time.
 Early computer programmers divided
programs into the sections that were
transferred into the main memory for
the period of processing time.
 As the program proceeded, new
sections moved into the main memory
and replaced sections that were not
needed at that time.
 In this early era of computing, the
programmer was responsible for
devising this overlay system.
 As higher-level languages became
popular for writing more complex
programs and the programmer became
less familiar with the machine, the
efficiency of complex programs
suffered from poor overlay systems.
The problem of storage allocation
became more complex.
 Two theories for solving the problem of
inefficient memory management
emerged - static and dynamic
allocation.
 Static allocation assumes that the
availability of memory resources and
the memory reference string of a
program can be predicted.
 Dynamic allocation relies on memory
usage increasing and decreasing with
actual program needs, not on
predicting memory needs.
 Program objectives and machine
advancements in the 1960s made the
predictions required for static
allocation difficult, if not impossible.
 Therefore, the dynamic allocation
solution was generally accepted, but
opinions about implementation were
still divided.
 One group believed the programmer
should continue to be responsible for
storage allocation, which would be
accomplished by system calls to
allocate or deal locate memory.
 The second group supported automatic
storage allocation performed by the
operating system, because of
increasing complexity of storage
allocation and emerging importance of
multiprogramming.
Virtual Memory
 In 1961, two groups proposed a one-
level memory store.
 One proposal called for a very large
main memory to alleviate any need for
storage allocation. This solution was
not possible due to its very high cost.
 The second proposal is known as
virtual memory.
Definition
 Virtual memory is a technique that allows the
execution of processes that may not be
completely in memory.
 One major advantage of this scheme is that
the program can be larger than physical
memory.
 Of course, in order to do this sensibly it is
highly desirable to have a protection scheme
that restricts a process to be able to access
only those blocks that are assigned to it.
 Virtual memory enables a program to ignore
the physical location of any desired block of
its address space; a process can simply seek
to access any block of its address space
without concern for where that block might
be located.
 If the block happens to be located in the main
memory, access is carried out smoothly and
quickly; else, the virtual memory has to bring
the block in from secondary storage and
allow it to be accessed by the program.
Virtual Memory Vs Cache
 The technique of virtual memory is similar to
a degree with the use of processor caches.
 However, the differences lie in the block size
of virtual memory being typically much larger
(64 kilobytes and up) as compared with the
typical processor cache (128 bytes and up).
 The hit time, the miss penalty (the time taken
to retrieve an item that is not in the cache or
primary storage), and the transfer time are all
larger in case of virtual memory.
 However, the miss rate is typically much
smaller.
Advantages
 It often reduces the time taken to launch a
program, since not all the program code and
data need to be in physical memory before
the program execution can be started.
 Virtual memory automatically manages two
levels of the memory hierarchy, representing
the main memory and the secondary storage,
in a manner that is invisible to the program
that is running.
Types of Virtual Memory Systems
 Virtual memory systems are of two
basic kinds—those using fixed-size
blocks called pages, and those that use
variable-sized blocks called segments.
Principles of Operation
 To facilitate copying virtual memory into real
memory, the operating system divides virtual
memory into pages, each of which contains a
fixed number of addresses.
 Each page is stored on a disk until it is
needed.
 When the page is needed, the operating
system copies it from disk to main memory,
translating the virtual addresses into real
addresses.
Contd…
 Addresses generated by programs are virtual
addresses.
 The actual memory cells have physical
addresses.
 A piece of hardware called a memory
management unit (MMU) translates virtual
addresses to physical addresses at run-time.
 The process of translating virtual addresses
into real addresses is called mapping. The
copying of virtual pages from disk to main
memory is known as paging or swapping.
Contd…
 Some physical memory is used to keep
a list of references to the most recently
accessed information on an I/O
(input/output) device, such as the hard
disk.
 The optimization it provides is that it is
faster to read the information from
physical memory than use the relevant
I/O channel to get that information. This
is called caching. It is implemented
inside the OS.
Virtual Memory Manager
 Virtual memory provides the services
to map the logical and physical
address spaces to one another and
when it is required.
Functions of Virtual memory manager
It is responsible to:
 Make portions of the logical address
space resident in physical RAM
 Make portions of the logical address
space immovable in physical RAM
 Map logical to physical addresses
 Defer execution of application-defined
interrupt code until a safe time.
Abstract model of Virtual to Physical address mapping
VPFN 7
VPFN 6
VPFN 5
VPFN 4
VPFN 3
VPFN 2
VPFN 1
VPFN 0
Process Y
VPFN 7
VPFN 6
VPFN 5
VPFN 4
VPFN 3
VPFN 2
VPFN 1
VPFN 0
Process X
PFN 4
PFN 3
PFN 2
PFN 1
PFN 0
Process X
Page Table
Process Y
Page Table
VIRTUAL MEMORY PHYSICAL MEMORY VIRTUAL MEMORY
Protection and Sharing
Paging scheme supporting the sharing of program code
editor 1
editor 2
editor 3
data 1
3
4
6
1
editor 1
editor 2
editor 3
data 3
3
4
6
2
editor 1
editor 2
editor 3
data 2
3
4
6
7
Process 1
Page table 1
Process 3
Page table 3
Page table 2
Process 2
…
data 1
data 3
editor 1
editor 2
….
editor 3
data 2
…
…
Physical memory
Pure Demand Paging
 In the extreme case, a process without pages
in memory could be executed.
 Page fault trap would occur with the first
instruction. After this page was brought into
memory, the process would continue to
execute.
 In this way, page fault trap would occur
further until every page that is needed was in
memory. This kind of paging is called pure
demand paging. Pure demand paging says
that “never bring a page into memory until it
is required”.
Page Replacement Policy
 When a process needs a non-resident
page, the operating system must
decide which resident page is to be
replaced by the requested page. The
part of the virtual memory which makes
this decision is called the replacement
policy.
Page Replacement Policies
 First in first out (FIFO)
 Second Chance (SC)
 Least Recently Used (LRU)
 Optimal Algorithm (OPT)
 Least Frequently Used (LFU)
Thrashing
 Thrashing occurs when a system
spends more time processing page
faults than executing transactions.
 While processing page faults it is
necessary to be in order to appreciate
the benefits of virtual memory,
thrashing has a negative effect on the
system.
 As the page fault rate increases, more
transactions need processing from the
paging device.
 The queue at the paging device
increases, resulting in increased
service time for a page fault.
 While the transactions in the system
are waiting for the paging device, CPU
utilisation, system throughput and
system response time decrease,
resulting in below optimal performance
of a system.
Thrashing becomes a greater threat as the degree of
multiprogramming of the system increases.
Demand Segmentation
 Same idea as demand paging applied
to segments.
Combined Systems
The combined systems are of two types.
They are:
 Segmented Paging
 Paged Segmentation
Thank You

Virtual Memory

  • 1.
  • 2.
    Introduction  Storage allocationhas always been an important consideration in computer programming due to the high cost of the main memory and the relative abundance and lower cost of secondary storage.
  • 3.
     Program codeand data required for execution of a process must reside in the main memory but the main memory may not be large enough to accommodate the needs of an entire process.  Early computer programmers divided programs into the sections that were transferred into the main memory for the period of processing time.
  • 4.
     Early computerprogrammers divided programs into the sections that were transferred into the main memory for the period of processing time.  As the program proceeded, new sections moved into the main memory and replaced sections that were not needed at that time.  In this early era of computing, the programmer was responsible for devising this overlay system.
  • 5.
     As higher-levellanguages became popular for writing more complex programs and the programmer became less familiar with the machine, the efficiency of complex programs suffered from poor overlay systems. The problem of storage allocation became more complex.
  • 6.
     Two theoriesfor solving the problem of inefficient memory management emerged - static and dynamic allocation.  Static allocation assumes that the availability of memory resources and the memory reference string of a program can be predicted.  Dynamic allocation relies on memory usage increasing and decreasing with actual program needs, not on predicting memory needs.
  • 7.
     Program objectivesand machine advancements in the 1960s made the predictions required for static allocation difficult, if not impossible.  Therefore, the dynamic allocation solution was generally accepted, but opinions about implementation were still divided.
  • 8.
     One groupbelieved the programmer should continue to be responsible for storage allocation, which would be accomplished by system calls to allocate or deal locate memory.  The second group supported automatic storage allocation performed by the operating system, because of increasing complexity of storage allocation and emerging importance of multiprogramming.
  • 9.
    Virtual Memory  In1961, two groups proposed a one- level memory store.  One proposal called for a very large main memory to alleviate any need for storage allocation. This solution was not possible due to its very high cost.  The second proposal is known as virtual memory.
  • 10.
    Definition  Virtual memoryis a technique that allows the execution of processes that may not be completely in memory.  One major advantage of this scheme is that the program can be larger than physical memory.  Of course, in order to do this sensibly it is highly desirable to have a protection scheme that restricts a process to be able to access only those blocks that are assigned to it.
  • 11.
     Virtual memoryenables a program to ignore the physical location of any desired block of its address space; a process can simply seek to access any block of its address space without concern for where that block might be located.  If the block happens to be located in the main memory, access is carried out smoothly and quickly; else, the virtual memory has to bring the block in from secondary storage and allow it to be accessed by the program.
  • 12.
    Virtual Memory VsCache  The technique of virtual memory is similar to a degree with the use of processor caches.  However, the differences lie in the block size of virtual memory being typically much larger (64 kilobytes and up) as compared with the typical processor cache (128 bytes and up).  The hit time, the miss penalty (the time taken to retrieve an item that is not in the cache or primary storage), and the transfer time are all larger in case of virtual memory.  However, the miss rate is typically much smaller.
  • 13.
    Advantages  It oftenreduces the time taken to launch a program, since not all the program code and data need to be in physical memory before the program execution can be started.  Virtual memory automatically manages two levels of the memory hierarchy, representing the main memory and the secondary storage, in a manner that is invisible to the program that is running.
  • 14.
    Types of VirtualMemory Systems  Virtual memory systems are of two basic kinds—those using fixed-size blocks called pages, and those that use variable-sized blocks called segments.
  • 15.
    Principles of Operation To facilitate copying virtual memory into real memory, the operating system divides virtual memory into pages, each of which contains a fixed number of addresses.  Each page is stored on a disk until it is needed.  When the page is needed, the operating system copies it from disk to main memory, translating the virtual addresses into real addresses.
  • 16.
    Contd…  Addresses generatedby programs are virtual addresses.  The actual memory cells have physical addresses.  A piece of hardware called a memory management unit (MMU) translates virtual addresses to physical addresses at run-time.  The process of translating virtual addresses into real addresses is called mapping. The copying of virtual pages from disk to main memory is known as paging or swapping.
  • 17.
    Contd…  Some physicalmemory is used to keep a list of references to the most recently accessed information on an I/O (input/output) device, such as the hard disk.  The optimization it provides is that it is faster to read the information from physical memory than use the relevant I/O channel to get that information. This is called caching. It is implemented inside the OS.
  • 18.
    Virtual Memory Manager Virtual memory provides the services to map the logical and physical address spaces to one another and when it is required.
  • 19.
    Functions of Virtualmemory manager It is responsible to:  Make portions of the logical address space resident in physical RAM  Make portions of the logical address space immovable in physical RAM  Map logical to physical addresses  Defer execution of application-defined interrupt code until a safe time.
  • 20.
    Abstract model ofVirtual to Physical address mapping VPFN 7 VPFN 6 VPFN 5 VPFN 4 VPFN 3 VPFN 2 VPFN 1 VPFN 0 Process Y VPFN 7 VPFN 6 VPFN 5 VPFN 4 VPFN 3 VPFN 2 VPFN 1 VPFN 0 Process X PFN 4 PFN 3 PFN 2 PFN 1 PFN 0 Process X Page Table Process Y Page Table VIRTUAL MEMORY PHYSICAL MEMORY VIRTUAL MEMORY
  • 21.
  • 22.
    Paging scheme supportingthe sharing of program code editor 1 editor 2 editor 3 data 1 3 4 6 1 editor 1 editor 2 editor 3 data 3 3 4 6 2 editor 1 editor 2 editor 3 data 2 3 4 6 7 Process 1 Page table 1 Process 3 Page table 3 Page table 2 Process 2 … data 1 data 3 editor 1 editor 2 …. editor 3 data 2 … … Physical memory
  • 23.
    Pure Demand Paging In the extreme case, a process without pages in memory could be executed.  Page fault trap would occur with the first instruction. After this page was brought into memory, the process would continue to execute.  In this way, page fault trap would occur further until every page that is needed was in memory. This kind of paging is called pure demand paging. Pure demand paging says that “never bring a page into memory until it is required”.
  • 24.
    Page Replacement Policy When a process needs a non-resident page, the operating system must decide which resident page is to be replaced by the requested page. The part of the virtual memory which makes this decision is called the replacement policy.
  • 25.
    Page Replacement Policies First in first out (FIFO)  Second Chance (SC)  Least Recently Used (LRU)  Optimal Algorithm (OPT)  Least Frequently Used (LFU)
  • 26.
    Thrashing  Thrashing occurswhen a system spends more time processing page faults than executing transactions.  While processing page faults it is necessary to be in order to appreciate the benefits of virtual memory, thrashing has a negative effect on the system.
  • 27.
     As thepage fault rate increases, more transactions need processing from the paging device.  The queue at the paging device increases, resulting in increased service time for a page fault.  While the transactions in the system are waiting for the paging device, CPU utilisation, system throughput and system response time decrease, resulting in below optimal performance of a system.
  • 28.
    Thrashing becomes agreater threat as the degree of multiprogramming of the system increases.
  • 29.
    Demand Segmentation  Sameidea as demand paging applied to segments.
  • 30.
    Combined Systems The combinedsystems are of two types. They are:  Segmented Paging  Paged Segmentation
  • 31.