Virtual Memory




                 - Ishwar Dhumal
Virtual Memory

       In a computer system, virtual memory is something that
  appears to be exist, but actually does not exist. Virtual memory is a
  technique , which allows execution of the process , that are not
  completely present in the memory.

Advantages:
1] The program can be larger than physical memory.
2] This frees programmers from the concerns of memory limitations.
3] Virtual memory provides efficient mechanism for discontinuous
  memory allocation.
Virtual Memory
      The basic idea behind virtual memory is that the combined size of the program
code , data , stack may exceed the amount of physical memory available for it . The
OS keeps only those parts of the program which are currently needed by the CPU in
main memory , and rest on the disk.


For e.g.-
      A 16 MB program can run in 4 MB space by carefully choosing which 4 MB
to keep in memory at each instance , with pieces of the program being swapped
between disk and memory as needed.


       Virtual memory concept can also work in multiprogramming system , with
pieces of many programs in memory at a time. And while one process is swapping
its pieces(pages) the CPU can be given to another process.
The fundamental approach used in implementing virtual memory
system is demand paging.

Demand Paging :

         Consider the situation that an executable program is to be loaded
from the disk into memory. Now , one option for this is to load the entire
program in memory at a time . Now , the problem with this approach is
that we may not have the sufficient memory to load the full program OR
if memory is available still initially we do not need the entire program in
the memory.
         Consider a program that starts with a list of available options
from which user has to select one option . So , loading the entire program
results in loading the executable code for all options , regardless of user
selection. So , this approach is wasting system time and memory space.
Demand Paging :
      So, an alternative strategy is used i.e. only those pages which
      are initially required for the execution are loaded . This
      technique is called as Demand Paging . So, in demand paging
      pages are only loaded when they are demanded during
      program execution .Pages that are never accessed are thus
      never loaded into memory.
            Main Memory

                                                      Disk


Program
                              Swap Out
   A

                              Swap In
Demand Paging
  A Demand paging system is similar to a paging system with
  swapping. When we want to execute a process, we swap it
  into memory. Rather than swapping the entire process into
  memory, however, we use a swapper. This swapper never
  swaps a page into memory unless it is demanded by the
  process. Such a swapper is called lazy swapper and such
  demand paging is called Pure demand paging.

Conclusion:
  The virtual memory is nothing but the space provided on
  secondary memory to store the parts of processes which is
  accessed just as if it is the main memory.

Virtual memory

  • 1.
    Virtual Memory - Ishwar Dhumal
  • 2.
    Virtual Memory In a computer system, virtual memory is something that appears to be exist, but actually does not exist. Virtual memory is a technique , which allows execution of the process , that are not completely present in the memory. Advantages: 1] The program can be larger than physical memory. 2] This frees programmers from the concerns of memory limitations. 3] Virtual memory provides efficient mechanism for discontinuous memory allocation.
  • 3.
    Virtual Memory The basic idea behind virtual memory is that the combined size of the program code , data , stack may exceed the amount of physical memory available for it . The OS keeps only those parts of the program which are currently needed by the CPU in main memory , and rest on the disk. For e.g.- A 16 MB program can run in 4 MB space by carefully choosing which 4 MB to keep in memory at each instance , with pieces of the program being swapped between disk and memory as needed. Virtual memory concept can also work in multiprogramming system , with pieces of many programs in memory at a time. And while one process is swapping its pieces(pages) the CPU can be given to another process.
  • 4.
    The fundamental approachused in implementing virtual memory system is demand paging. Demand Paging : Consider the situation that an executable program is to be loaded from the disk into memory. Now , one option for this is to load the entire program in memory at a time . Now , the problem with this approach is that we may not have the sufficient memory to load the full program OR if memory is available still initially we do not need the entire program in the memory. Consider a program that starts with a list of available options from which user has to select one option . So , loading the entire program results in loading the executable code for all options , regardless of user selection. So , this approach is wasting system time and memory space.
  • 5.
    Demand Paging : So, an alternative strategy is used i.e. only those pages which are initially required for the execution are loaded . This technique is called as Demand Paging . So, in demand paging pages are only loaded when they are demanded during program execution .Pages that are never accessed are thus never loaded into memory. Main Memory Disk Program Swap Out A Swap In
  • 6.
    Demand Paging A Demand paging system is similar to a paging system with swapping. When we want to execute a process, we swap it into memory. Rather than swapping the entire process into memory, however, we use a swapper. This swapper never swaps a page into memory unless it is demanded by the process. Such a swapper is called lazy swapper and such demand paging is called Pure demand paging. Conclusion: The virtual memory is nothing but the space provided on secondary memory to store the parts of processes which is accessed just as if it is the main memory.