![Page 1: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/1.jpg)
Virtual Memory
Lei LiCS147
![Page 2: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/2.jpg)
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."
![Page 3: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/3.jpg)
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
![Page 4: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/4.jpg)
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.
![Page 5: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/5.jpg)
Virtual memory
![Page 6: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/6.jpg)
The memory pyramid
![Page 7: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/7.jpg)
How Does VM Work ?• Two memory “spaces”
– 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
![Page 8: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/8.jpg)
Example: Virtual and Physical Address Spaces
Virtual Address Space Physical Address Space
bne 0x00
add r10,r1,r2
sub r3,r4,r1
sw r5,0x0c
0x00
0x04
0x08
0x0C
0x10
0x14
0x18
0x1C
0x00
0x04
0x08
0x0C
add r1,r2,r3
sub r2,r3,r4
lw r2, 0x04
mult r3,r4,r5
add r1,r2,r3
sub r2,r3,r4
lw r2, 0x04
mult r3,r4,r5
![Page 9: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/9.jpg)
Example (con'td): Need VA to PA mappings
bne 0x00
add r10,r1,r2
sub r3,r4,r1
sw r5,0x0c
0x00
0x04
0x08
0x0C
0x10
0x14
0x18
0x1C
0x00
0x04
0x08
0x0C
add r1,r2,r3
sub r2,r3,r4
lw r2, 0x04
mult r3,r4,r5
add r1,r2,r3
sub r2,r3,r4
lw r2, 0x04
mult r3,r4,r5
Virtual Address Space Physical Address Space
0x00 0x000x04 0x040x08 0x080x0c 0x0c0x10 Disk0x14 Disk0x18 Disk0x1c Disk
VA->PA
![Page 10: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/10.jpg)
Example (con'td): After handling a page fault
bne 0x00
add r10,r1,r2
sub r3,r4,r1
sw r5,0x0c
0x00
0x04
0x08
0x0C
0x10
0x14
0x18
0x1C
0x00
0x04
0x08
0x0C
add r1,r2,r3
sub r2,r3,r4
lw r2, 0x04
mult r3,r4,r5
bne 0x00
sub r2,r3,r4
lw r2, 0x04
mult r3,r4,r5
Virtual Address Space Physical Address Space
0x00 Disk0x04 0x040x08 0x080x0c 0x0c0x10 0x000x14 Disk0x18 Disk0x1c Disk
VA->PA
![Page 11: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/11.jpg)
Example (con'td): After a second page fault
bne 0x00
add r10,r1,r2
sub r3,r4,r1
sw r5,0x0c
0x00
0x04
0x08
0x0C
0x10
0x14
0x18
0x1C
0x00
0x04
0x08
0x0C
add r1,r2,r3
sub r2,r3,r4
lw r2, 0x04
mult r3,r4,r5
bne 0x00
add r1,r2,r3
lw r2, 0x04
mult r3,r4,r5
Virtual Address Space Physical Address Space
0x00 0x040x04 Disk0x08 0x080x0c 0x0c0x10 0x000x14 Disk0x18 Disk0x1c Disk
VA->PA
![Page 12: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/12.jpg)
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
RAM0x00 0x000x04 0x040x08 0x080x0c 0x0c0x10 Disk0x14 Disk0x18 Disk0x1c Disk
VA->PA
Processor(running program)
Instructions(or data)
Virtualaddress
![Page 13: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/13.jpg)
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?
0x00
0x04
0x08
0x0C
add r1,r2,r3
sub r2,r3,r4
lw r2, 0x04
mult r3,r4,r5
RAM0x00 0x000x04 0x040x08 0x080x0c 0x0c0x10 Disk0x14 Disk0x18 Disk0x1c Disk
VA->PA
Processor(running program)
Instructions(or data)
Virtualaddress
![Page 14: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/14.jpg)
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 # Page Offset
Translation
VirtualAddress
PhysicalAddress
0111231
0111224
![Page 15: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/15.jpg)
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.
![Page 16: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/16.jpg)
My system virtual memory
![Page 17: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/17.jpg)
![Page 18: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/18.jpg)
![Page 19: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/19.jpg)
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
![Page 20: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/20.jpg)
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.)
![Page 21: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/21.jpg)
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.
![Page 22: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/22.jpg)
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.
![Page 23: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/23.jpg)
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.
![Page 24: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/24.jpg)
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.
![Page 25: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/25.jpg)
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.
![Page 26: Virtual Memory Lei Li CS147. What’s Virtual Memory? Virtual memory is a combination of RAM (physical system memory) and reserved hard disk space. The](https://reader036.vdocuments.net/reader036/viewer/2022062314/56649f325503460f94c4dfc3/html5/thumbnails/26.jpg)
• For more information, please go towww.intel.com and search on virtual memory