SlideShare a Scribd company logo
1 of 19
Virtual Memory
Sak haw at Ali Baltis tani
• Three memory problems:
– Not enough RAM
– Holes in our address
space
– Programs writing over
each other
• What is virtual memory?
– Indirection
– How does it solve the
problems
– Page Tables and
Translation
• Implementing Virtual
Memory
– Why do we store the
page tables?
Contents
• Paging
– Why we do paging ?
– Page Faults
– Demand Paging
• Page Replacement
and its Algorithms
– What is Page
Replacement?
– FIFO Replacement
Algo
– Optimal
Replacement Algo
– LRU Algorithm
Three Problems with Memory
• Architecture: 32-bit address space
• Programs: any byte in 32-bit address space
• What if you don’t have 4GB of memory?
#1: What if we don’t have enough memory?
32-bit program
address space
(4GB)
30-bit RAM
address space
(1GB)
Address 0x00000000
Address 0xFFFFFFFF
…to… ??
Crash if we try to access
more than 1GB
Q: How much memory can you access with 32-
bit address?
A. 230
bytes = 1GB
B. 232 bytes = 4GB
C. 232
words = 16GB
• How do programs share the memory?
• Where do we put them?
#2: Holes in our address space?
32-bit RAM
address space (4GB)
1. Program 1 and 2 fit
(They use 3GB of memory, leaving 1 GB free)
2. Quit Program 1
(Program 2 uses 2GB of memory, leaving 2GB free)
3. Can’t run Program 3
(Even though we have enough free space!)
Memory Fragmentation
• Each program can access any 32-bit memory address.
• What if multiple programs access the same address?
– MOV [1024], AH Write to address 1024 regardless of the program that’s running
• They can corrupt or crash each other: security and reliability.
#3: How do we keep programs secure?
32-bit RAM
address space (4GB)
1. Program 1 stores your bank
balance at address 1024
2. Program 2 stores your game
score at address 1024.
3. Profit? Loss? Not Good!
• If all programs have access to the same 32-bit memory space:
• How do we solve this?
– Key to the problem: “same memory space”
– Can we give each program its own virtual memory space?
– If so, we can:
• Separately map each program’s memory space to the RAM memory space
• (and even move it to disk if we run out of memory)
Problems with memory?
What is Virtual Memory?
( H int: Indir ec tion)
“Any problem in computer science can be solved by adding indirection”
Virtual Memory takes program addresses and maps them to RAM
addresses
Virtual Memory is a layer of indirection
Without Virtual Memory
Program Address = RAM Address
32-bit program
address space
(4GB)
30-bit RAM
address space
(1GB)
0
1
…
??
With Virtual Memory
Program Address Maps to RAM Address
32-bit program
address space
(4GB)
30-bit RAM
address space
(1GB)
0
1
…
Disk
Map
0
1
2
VM: Mapping gives us
flexibility in how we
use the RAM
Solving the problem: #1 not enough memory?
With Virtual Memory
Program Address Maps to RAM Address
32-bit program
address space
(4GB)
30-bit RAM
address space
(1GB)
Disk
Map
• Map some of the program’s address space to the disk
• When we need it, we bring it into memory
Solving the problem: #2 holes in the address space?
With Virtual Memory
Program Address Maps to RAM Address
Each program has its own
mapping.
Mappings let us put our
program data wherever we want
in the RAM
32-bit program
address space
(4GB)
Map
• How do we use the holes left when programs quit?
• We can map a program’s addresses to RAM addresses however we like
Solving the problem: #3 keeping programs secure?
Map
• Program 1’s and Program 2’s addresses map to different RAM addresses.
• Because each program has its own address space, they cannot access each
other’s data: security and reliability!
With Virtual Memory
Program Address Maps to RAM Address
1. Program 1 stores your bank
balance at address 1024
1A. VM maps it to RAM Address 1.
2. Program 2 stores your video
game score at address 1024
2B. VM maps it to RAM address 5.
3. Neither can touch the other’s
data.
How does VM work?
Vir tual and Phys ic al Addr es s es
How does VM work?
• Basic idea: separate memory spaces
– Virtual memory: what the program sees
• E.g. MOV [1024], AX accesses virtual address 1024
– Physical memory: the physical RAM in the computer
• E.g. if you have 2GB of RAM installed, you have physical addresses: 0 to 𝟐 𝟑𝟏
-1
• Virtual Addresses (VA)
– What the program uses
– In our example, this was full 32 bit address space: 0 to 𝟐 𝟑𝟏-1
• Physical Addresses (PA)
– What the hardware uses to talk to the RAM
– Address space determined by how much RAM is installed.
Page Tables
Keeping tr ac k of VA - > PA mappings
Page Tables
• The map from Virtual Address to Physical Address is the Page
Table
First in First out Algorithm
• Reference string: 7,0,1,2,0,3,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1
• 3 frames (3 pages can be in memory at a time per process)
• How to track ages of pages?
– What the hardware uses to talk to the RAM
– Address space determined by how much RAM is installed.
• How to track ages of pages?
– Just use a FIFO queue
1 7 2 4 0 7
2 0 3 2 1 0
3 1 0 3 2 1
Optimal Algorithm
• Replace page that will not be used for longest period of time
• How do you know this?
– Can’t read the future
– Theoreticians refer to this as an “oracle”
– Not resizeable
• Used for measuring how well your algo performs?
Least Recently Used (LRU) Algorithm
• Use past knowledge rather than future
• Replace page that has not been used in the most amount of
time?
• Associate time of last use with each page
• 12 faults – better than FIFO but worse than OPT
• Generally good algo and frequently used

More Related Content

What's hot

Virtual memory ppt
Virtual memory pptVirtual memory ppt
Virtual memory pptRITULDE
 
basics of virtual memory
basics of virtual memorybasics of virtual memory
basics of virtual memoryAdarsh Patel
 
Virtual Memory ,Direct memory addressing and indirect memory addressing prese...
Virtual Memory ,Direct memory addressing and indirect memory addressing prese...Virtual Memory ,Direct memory addressing and indirect memory addressing prese...
Virtual Memory ,Direct memory addressing and indirect memory addressing prese...ITM University
 
Virtual memory
Virtual memoryVirtual memory
Virtual memoryAsif Iqbal
 
Virtual memory
Virtual memoryVirtual memory
Virtual memoryAnuj Modi
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual MemoryArchith777
 
Virtual Memory Management
Virtual Memory ManagementVirtual Memory Management
Virtual Memory Managementprimeteacher32
 
Operating Systems - Virtual Memory
Operating Systems - Virtual MemoryOperating Systems - Virtual Memory
Operating Systems - Virtual MemoryDamian T. Gordon
 
Virtual memory managment
Virtual memory managmentVirtual memory managment
Virtual memory managmentSantu Kumar
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memoryvampugani
 
Chapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryChapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryWayne Jones Jnr
 
Virtual Memory vs Cache Memory
Virtual Memory vs Cache MemoryVirtual Memory vs Cache Memory
Virtual Memory vs Cache MemoryAshik Iqbal
 

What's hot (20)

Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memory
 
Virtual memory ppt
Virtual memory pptVirtual memory ppt
Virtual memory ppt
 
VIRTUAL MEMORY
VIRTUAL MEMORYVIRTUAL MEMORY
VIRTUAL MEMORY
 
Virtual memory (testing)
Virtual memory (testing)Virtual memory (testing)
Virtual memory (testing)
 
basics of virtual memory
basics of virtual memorybasics of virtual memory
basics of virtual memory
 
Virtual Memory ,Direct memory addressing and indirect memory addressing prese...
Virtual Memory ,Direct memory addressing and indirect memory addressing prese...Virtual Memory ,Direct memory addressing and indirect memory addressing prese...
Virtual Memory ,Direct memory addressing and indirect memory addressing prese...
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Virtual memory ppt
Virtual memory pptVirtual memory ppt
Virtual memory ppt
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memory
 
Virtual Memory Management
Virtual Memory ManagementVirtual Memory Management
Virtual Memory Management
 
Operating Systems - Virtual Memory
Operating Systems - Virtual MemoryOperating Systems - Virtual Memory
Operating Systems - Virtual Memory
 
Virtual memory managment
Virtual memory managmentVirtual memory managment
Virtual memory managment
 
virtual memory
virtual memoryvirtual memory
virtual memory
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memory
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
 
Chapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryChapter 9 - Virtual Memory
Chapter 9 - Virtual Memory
 
Virtual Memory vs Cache Memory
Virtual Memory vs Cache MemoryVirtual Memory vs Cache Memory
Virtual Memory vs Cache Memory
 
Virtual memory
Virtual memory Virtual memory
Virtual memory
 

Similar to Virtual memory

C++ Advanced Memory Management With Allocators
C++ Advanced Memory Management With AllocatorsC++ Advanced Memory Management With Allocators
C++ Advanced Memory Management With AllocatorsGlobalLogic Ukraine
 
Chapter 2 part 1
Chapter 2 part 1Chapter 2 part 1
Chapter 2 part 1rohassanie
 
Memory management in sql server
Memory management in sql serverMemory management in sql server
Memory management in sql serverPrashant Kumar
 
AWS re:Invent 2016| GAM302 | Sony PlayStation: Breaking the Bandwidth Barrier...
AWS re:Invent 2016| GAM302 | Sony PlayStation: Breaking the Bandwidth Barrier...AWS re:Invent 2016| GAM302 | Sony PlayStation: Breaking the Bandwidth Barrier...
AWS re:Invent 2016| GAM302 | Sony PlayStation: Breaking the Bandwidth Barrier...Amazon Web Services
 
UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...
UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...
UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...LeahRachael
 
Memory organization (Computer architecture)
Memory organization (Computer architecture)Memory organization (Computer architecture)
Memory organization (Computer architecture)Sandesh Jonchhe
 
Bt0070 operating systems 2
Bt0070 operating systems  2Bt0070 operating systems  2
Bt0070 operating systems 2Techglyphs
 
MongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: ShardingMongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: ShardingMongoDB
 
Computer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.1 primary MemoryComputer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.1 primary MemoryBudditha Hettige
 
Software development slides
Software development slidesSoftware development slides
Software development slidesiarthur
 
Data oriented design and c++
Data oriented design and c++Data oriented design and c++
Data oriented design and c++Mike Acton
 

Similar to Virtual memory (20)

C++ Advanced Memory Management With Allocators
C++ Advanced Memory Management With AllocatorsC++ Advanced Memory Management With Allocators
C++ Advanced Memory Management With Allocators
 
Operating system
Operating systemOperating system
Operating system
 
Chapter 2 part 1
Chapter 2 part 1Chapter 2 part 1
Chapter 2 part 1
 
Memory management in sql server
Memory management in sql serverMemory management in sql server
Memory management in sql server
 
AWS re:Invent 2016| GAM302 | Sony PlayStation: Breaking the Bandwidth Barrier...
AWS re:Invent 2016| GAM302 | Sony PlayStation: Breaking the Bandwidth Barrier...AWS re:Invent 2016| GAM302 | Sony PlayStation: Breaking the Bandwidth Barrier...
AWS re:Invent 2016| GAM302 | Sony PlayStation: Breaking the Bandwidth Barrier...
 
Virtual memory 20070222-en
Virtual memory 20070222-enVirtual memory 20070222-en
Virtual memory 20070222-en
 
Os4
Os4Os4
Os4
 
Os4
Os4Os4
Os4
 
Lecture 23 p1
Lecture 23 p1Lecture 23 p1
Lecture 23 p1
 
UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...
UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...
UNIT 3-EXPLAINING THE MEMORY MANAGEMENT LOGICAL AND AND PHYSICAL DATA FLOW DI...
 
Memory organization (Computer architecture)
Memory organization (Computer architecture)Memory organization (Computer architecture)
Memory organization (Computer architecture)
 
Bt0070 operating systems 2
Bt0070 operating systems  2Bt0070 operating systems  2
Bt0070 operating systems 2
 
Memory management
Memory managementMemory management
Memory management
 
MongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: ShardingMongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: Sharding
 
Computer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.1 primary MemoryComputer System Architecture Lecture Note 8.1 primary Memory
Computer System Architecture Lecture Note 8.1 primary Memory
 
Microprocessors and memory concepts
Microprocessors and memory conceptsMicroprocessors and memory concepts
Microprocessors and memory concepts
 
Software development slides
Software development slidesSoftware development slides
Software development slides
 
Basic course
Basic courseBasic course
Basic course
 
Vm
VmVm
Vm
 
Data oriented design and c++
Data oriented design and c++Data oriented design and c++
Data oriented design and c++
 

Recently uploaded

UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college projectTonystark477637
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSRajkumarAkumalla
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 

Recently uploaded (20)

UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
result management system report for college project
result management system report for college projectresult management system report for college project
result management system report for college project
 
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service NashikCall Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
Call Girls Service Nashik Vaishnavi 7001305949 Independent Escort Service Nashik
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICSHARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
HARDNESS, FRACTURE TOUGHNESS AND STRENGTH OF CERAMICS
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 

Virtual memory

  • 1. Virtual Memory Sak haw at Ali Baltis tani
  • 2. • Three memory problems: – Not enough RAM – Holes in our address space – Programs writing over each other • What is virtual memory? – Indirection – How does it solve the problems – Page Tables and Translation • Implementing Virtual Memory – Why do we store the page tables? Contents • Paging – Why we do paging ? – Page Faults – Demand Paging • Page Replacement and its Algorithms – What is Page Replacement? – FIFO Replacement Algo – Optimal Replacement Algo – LRU Algorithm
  • 4. • Architecture: 32-bit address space • Programs: any byte in 32-bit address space • What if you don’t have 4GB of memory? #1: What if we don’t have enough memory? 32-bit program address space (4GB) 30-bit RAM address space (1GB) Address 0x00000000 Address 0xFFFFFFFF …to… ?? Crash if we try to access more than 1GB Q: How much memory can you access with 32- bit address? A. 230 bytes = 1GB B. 232 bytes = 4GB C. 232 words = 16GB
  • 5. • How do programs share the memory? • Where do we put them? #2: Holes in our address space? 32-bit RAM address space (4GB) 1. Program 1 and 2 fit (They use 3GB of memory, leaving 1 GB free) 2. Quit Program 1 (Program 2 uses 2GB of memory, leaving 2GB free) 3. Can’t run Program 3 (Even though we have enough free space!) Memory Fragmentation
  • 6. • Each program can access any 32-bit memory address. • What if multiple programs access the same address? – MOV [1024], AH Write to address 1024 regardless of the program that’s running • They can corrupt or crash each other: security and reliability. #3: How do we keep programs secure? 32-bit RAM address space (4GB) 1. Program 1 stores your bank balance at address 1024 2. Program 2 stores your game score at address 1024. 3. Profit? Loss? Not Good!
  • 7. • If all programs have access to the same 32-bit memory space: • How do we solve this? – Key to the problem: “same memory space” – Can we give each program its own virtual memory space? – If so, we can: • Separately map each program’s memory space to the RAM memory space • (and even move it to disk if we run out of memory) Problems with memory?
  • 8. What is Virtual Memory? ( H int: Indir ec tion)
  • 9. “Any problem in computer science can be solved by adding indirection” Virtual Memory takes program addresses and maps them to RAM addresses Virtual Memory is a layer of indirection Without Virtual Memory Program Address = RAM Address 32-bit program address space (4GB) 30-bit RAM address space (1GB) 0 1 … ?? With Virtual Memory Program Address Maps to RAM Address 32-bit program address space (4GB) 30-bit RAM address space (1GB) 0 1 … Disk Map 0 1 2 VM: Mapping gives us flexibility in how we use the RAM
  • 10. Solving the problem: #1 not enough memory? With Virtual Memory Program Address Maps to RAM Address 32-bit program address space (4GB) 30-bit RAM address space (1GB) Disk Map • Map some of the program’s address space to the disk • When we need it, we bring it into memory
  • 11. Solving the problem: #2 holes in the address space? With Virtual Memory Program Address Maps to RAM Address Each program has its own mapping. Mappings let us put our program data wherever we want in the RAM 32-bit program address space (4GB) Map • How do we use the holes left when programs quit? • We can map a program’s addresses to RAM addresses however we like
  • 12. Solving the problem: #3 keeping programs secure? Map • Program 1’s and Program 2’s addresses map to different RAM addresses. • Because each program has its own address space, they cannot access each other’s data: security and reliability! With Virtual Memory Program Address Maps to RAM Address 1. Program 1 stores your bank balance at address 1024 1A. VM maps it to RAM Address 1. 2. Program 2 stores your video game score at address 1024 2B. VM maps it to RAM address 5. 3. Neither can touch the other’s data.
  • 13. How does VM work? Vir tual and Phys ic al Addr es s es
  • 14. How does VM work? • Basic idea: separate memory spaces – Virtual memory: what the program sees • E.g. MOV [1024], AX accesses virtual address 1024 – Physical memory: the physical RAM in the computer • E.g. if you have 2GB of RAM installed, you have physical addresses: 0 to 𝟐 𝟑𝟏 -1 • Virtual Addresses (VA) – What the program uses – In our example, this was full 32 bit address space: 0 to 𝟐 𝟑𝟏-1 • Physical Addresses (PA) – What the hardware uses to talk to the RAM – Address space determined by how much RAM is installed.
  • 15. Page Tables Keeping tr ac k of VA - > PA mappings
  • 16. Page Tables • The map from Virtual Address to Physical Address is the Page Table
  • 17. First in First out Algorithm • Reference string: 7,0,1,2,0,3,4,2,3,0,3,0,3,2,1,2,0,1,7,0,1 • 3 frames (3 pages can be in memory at a time per process) • How to track ages of pages? – What the hardware uses to talk to the RAM – Address space determined by how much RAM is installed. • How to track ages of pages? – Just use a FIFO queue 1 7 2 4 0 7 2 0 3 2 1 0 3 1 0 3 2 1
  • 18. Optimal Algorithm • Replace page that will not be used for longest period of time • How do you know this? – Can’t read the future – Theoreticians refer to this as an “oracle” – Not resizeable • Used for measuring how well your algo performs?
  • 19. Least Recently Used (LRU) Algorithm • Use past knowledge rather than future • Replace page that has not been used in the most amount of time? • Associate time of last use with each page • 12 faults – better than FIFO but worse than OPT • Generally good algo and frequently used