Virtual Memory

If you think it’s there, and it’s there…it’s real.

If you think it’s not there, and it’s there…it’s transparent.

If you think it’s there, and it’s not there…it’s imaginary.

If you think it’s not there, and it’s not there…it’s nonexistent.
  • Virtual memory is imaginary memory: it gives you the illusion of a memory arrangement that’s not physically there.
  • If your computer lacks the random access memory (RAM) needed to run a program or operation, Windows uses virtual memory to compensate.
  • Virtual memory combines your computer’s RAM with temporary space on your hard disk. 
  • When RAM runs low, virtual memory moves data from RAM to a space called apaging file
  • Moving data to and from the paging file frees up RAM to complete its work.
  • You can think of virtual memory as an alternate set of memory addresses. Programs use these virtual addresses rather than real addresses to store instructions and data.
  • When the program is actually executed, the virtual addresses are converted into real memory addresses.
  • The purpose of virtual memory is to enlarge the address space, the set of addresses a
  • program can utilize.
  • A program using all of virtual memory, therefore, would not be able to fit in main memory all at once.
  • 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.
  • 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.
  • Virtual memory is a memory management technique developed for multitasking kernels. 
  • This technique virtualizes the main storage available to a process or task, as a contiguous address space which is unique to each running process, or virtualizes the main storage available to all processes or tasks on the system as a contiguous global address space.
  • The CPU automatically translates virtual addresses to physical addresses using special memory management hardware, often referred to as a memory management unit. 
  • As long as virtual addresses are resolved to real memory locations the process runs uninterrupted. 
  • When translation fails, the operating system takes over and moves the desired memory page from backing store to main memory, returning control to the interrupted process.

History of Virtual Memory

         Virtual memory is an old concept. Before computers had cache, they had virtual memory.
For a long time, virtual memory only appeared on mainframes. Personal computers in the
1980s did not use virtual memory.
         Initially, virtual memory meant the idea of using disk to extend RAM. Programs wouldn't
have to care whether the memory was "real" memory (i.e., RAM) or disk. The operating
system and hardware would figure that out.
         Later on, virtual memory was used as a means of memory protection. Every program uses
a range of addressed called the address space.

How Virtual Memory Works

  • When a computer is running, many programs are simultaneously sharing the CPU. 
  • Each running program, plus the data structures needed to manage it, is called a process.
  • Each process is allocated an address space.
  • This address space can be changed dynamically.
  • If a process tries to access an address that is not part of its address space, an error occurs, and the operating system takes over, usually killing the process (core dumps, etc).
  • Addresses are generated (for RISC machines) in one of three ways:
    1. A load instruction
    2. A store instruction
    3. Fetching an instruction
  • Load/store create data addresses, while fetching an instruction creates instruction addresses.
  • Each address generated by a program is considered virtual. 
  • It must be translated to a real physical address. Thus, address tranlation is occuring all the time.

Comments

Popular posts from this blog

Pentium microprocessors

Multilevel Organization of Cache Memory