Presentation is loading. Please wait.

Presentation is loading. Please wait.

Virtual Memory Lei Li CS147.

Similar presentations


Presentation on theme: "Virtual Memory Lei Li CS147."— Presentation transcript:

1 Virtual Memory Lei Li CS147

2 What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The word virtual means "appearing to exist, but not really there."

3 Virtual memory vs. physical memory
During the execution of a program, parts of the program are in physical RAM and other parts are swapped out to the hard disk. Virtual Memory = RAM + hard disk Why is VM important? Cheap ­ no longer have to buy lots of RAM Removes burden of memory resource management from the programmer Other benefits

4 Virtual memory > RAM
Because virtual memory is a combination of RAM and hard disk space, it's possible to have more virtual memory in your system than you have RAM installed. Because Windows uses virtual memory to run programs, it's possible to run more applications simultaneously than would be possible if Windows used only physical memory to run programs.

5 Virtual memory

6 The memory pyramid

7 How Does VM Work ? Two memory “spaces” On program startup
Virtual memory space ­ what the program “sees” Physical memory space ­ what the program runs in (size of RAM) On program startup OS copies program into RAM If there is not enough RAM, OS stops copying program and starts it running with only a portion of the program loaded in RAM When the program touches a part of the program not in physical memory (RAM), OS catches the memory abort (called a page fault) and copies that part of the program from disk into RAM In order to copy some of the program from disk to RAM, OS must evict parts of the program already in RAM OS copies the evicted parts of the program back to disk

8 Example: Virtual and Physical Address Spaces
Virtual Address Space Physical Address Space 0x00 0x04 0x08 0x0C 0x10 0x14 0x18 0x1C add r1,r2,r3 0x00 0x04 0x08 0x0C add r1,r2,r3 sub r2,r3,r4 sub r2,r3,r4 lw r2, 0x04 lw r2, 0x04 mult r3,r4,r5 mult r3,r4,r5 bne 0x00 add r10,r1,r2 sub r3,r4,r1 sw r5,0x0c

9 Example (con'td): Need VA­to­PA mappings
Virtual Address Space Physical Address Space VA->PA 0x00 0x04 0x08 0x0C 0x10 0x14 0x18 0x1C add r1,r2,r3 0x00 0x04 0x08 0x0C add r1,r2,r3 sub r2,r3,r4 sub r2,r3,r4 lw r2, 0x04 lw r2, 0x04 mult r3,r4,r5 mult r3,r4,r5 bne 0x00 add r10,r1,r2 sub r3,r4,r1 sw r5,0x0c

10 Example (con'td): After handling a page fault
Virtual Address Space Physical Address Space VA->PA 0x00 0x04 0x08 0x0C 0x10 0x14 0x18 0x1C add r1,r2,r3 0x00 0x04 0x08 0x0C bne 0x00 sub r2,r3,r4 sub r2,r3,r4 lw r2, 0x04 lw r2, 0x04 mult r3,r4,r5 mult r3,r4,r5 bne 0x00 add r10,r1,r2 sub r3,r4,r1 sw r5,0x0c

11 Example (con'td): After a second page fault
Virtual Address Space Physical Address Space VA->PA 0x00 0x04 0x08 0x0C 0x10 0x14 0x18 0x1C add r1,r2,r3 0x00 0x04 0x08 0x0C bne 0x00 sub r2,r3,r4 add r1,r2,r3 lw r2, 0x04 lw r2, 0x04 mult r3,r4,r5 mult r3,r4,r5 bne 0x00 add r10,r1,r2 sub r3,r4,r1 sw r5,0x0c

12 Basic VM Algorithm Program asks for virtual address
Computer translates virtual address (VA) to physical address (PA) Computer reads PA from RAM, returning it to program 0x00 0x04 0x08 0x0C add r1,r2,r3 sub r2,r3,r4 lw r2, 0x04 mult r3,r4,r5 RAM VA->PA Processor (running program) Instructions (or data) Virtual address

13 Page Tables Table which holds VA ­> PA translations is called the page table In our current scheme, each word is translated from a virtual address to a physical address How big is the page table? VA->PA RAM 0x00 0x04 0x08 0x0C add r1,r2,r3 Processor (running program) sub r2,r3,r4 Virtual address lw r2, 0x04 mult r3,r4,r5 Instructions (or data)

14 Real Page Tables Instead of the fine­grained VM where any virtual word can map to any RAM word location, partition memory into chunks called pages Typical page size today is 4 or 8 KBytes This reduces the number of VA­> PA translation entries Only one translation per page For a 4 KByte page, that's one VA­> PA translation for every 1,024 words Within a page, the virtual address == physical address Virtual Page Number Page Offset Physical Page # Translation Virtual Address Physical 11 12 31 24

15 How Can I Find Out How Much Virtual Memory My System Has?
Windows can tell you the amount of virtual memory available at any given time and the percentage of your total system resources that are currently available for applications. To get this information, switch to Program Manager, and choose Help/About Program Manager.... At the bottom of the display box, your free memory (virtual memory) and % of free resources are listed. The amount of free memory should be 12 megabytes or more, i.e., 12,000 KB. It is also recommended that your % free be as high as possible.

16 My system virtual memory

17

18

19 What Causes Free Memory to Decrease?
Every time you run an application program under Windows, that program uses some of your free virtual memory to run program code, and to store and display data. Programs use additional memory as they: open new documents execute utility programs (like a spell-checker) perform other related program operations

20 Optimizing Memory for Use with Windows*
optimize your use of existing memory so that the maximum possible amount is available for Windows to access directly: 1, close down some (or all) applications that are running in the background or running minimized. In some cases, you'll need to close and restart Windows to achieve the maximum available virtual memory your system can have. (This is because some applications don't de-allocate memory after they're closed.)

21 Optimizing Memory for Use with Windows* (con)
2, unload memory-resident programs and drivers that load into conventional or extended memory. Note: address range in the system memory Conventional memory: 0-640K upper memory: 640K-1M Extended memory: above 1M.

22 Optimizing Memory for Use with Windows* (con)
Since Windows* can access extended memory directly, and since extended memory is normally available in the largest quantities, freeing up extended memory is usually the most efficient way to gain virtual memory for Windows to use. To free up extended memory, check your system for RAM disks or disk caches that are created from extended memory. Eliminating these or reducing their size will provide more virtual memory for Windows applications.

23 Increasing the Amount of Virtual Memory in the System
Besides optimizing the system memory, we can also increase the amount of virtual memory in the system. There are two ways: Increase the amount of system RAM available. Create a permanent or temporary swap file.

24 Increasing the Amount of Virtual Memory in the System(cont)
To increase available system RAM, purchase additional memory chips and install them in your computer. To increase the amount of hard disk space allocated as virtual memory, you need to create a Windows swap file, or increase the size of your current Windows swap file.

25 How to Create, Delete, or Change the Size of a Swap File
Open the Windows Control Panel by double clicking the 'Control Panel' icon (usually located in Windows' 'Main' program group). Double-Click on the 386 Enhanced icon in the Control Panel window. Click on Virtual Memory. Click on Change. In the 'New Settings' box, select Permanent or Temporary (See: Permanent Swap Files) from the 'Type' box. Select 'None' to delete an existing swap file. Enter a size in the 'New Size' box. (Skip this step when deleting a swap file). Click on OK. Click on Yes to tell Windows you're sure about making changes to virtual memory. Click on OK to confirm the message that the swap file has been created. Restart Windows when prompted.

26 For more information, please go to
and search on virtual memory


Download ppt "Virtual Memory Lei Li CS147."

Similar presentations


Ads by Google