SlideShare a Scribd company logo
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
Virtual MemoryVirtual Memory
Virtual Memory
sanjana mun
 
Virtual memory ppt
Virtual memory pptVirtual memory ppt
Virtual memory ppt
RITULDE
 
VIRTUAL MEMORY
VIRTUAL MEMORYVIRTUAL MEMORY
VIRTUAL MEMORY
Kamran Ashraf
 
Virtual memory (testing)
Virtual memory (testing)Virtual memory (testing)
Virtual memory (testing)
Jamaludin Sallim
 
basics of virtual memory
basics of virtual memorybasics of virtual memory
basics of virtual memory
Adarsh 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 memory
Asif Iqbal
 
Virtual memory ppt
Virtual memory pptVirtual memory ppt
Virtual memory
Virtual memoryVirtual memory
Virtual memory
Anuj Modi
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memory
Archith777
 
Virtual Memory Management
Virtual Memory ManagementVirtual Memory Management
Virtual Memory Management
primeteacher32
 
Operating Systems - Virtual Memory
Operating Systems - Virtual MemoryOperating Systems - Virtual Memory
Operating Systems - Virtual Memory
Damian T. Gordon
 
Virtual memory managment
Virtual memory managmentVirtual memory managment
Virtual memory managment
Santu Kumar
 
virtual memory
virtual memoryvirtual memory
virtual memory
surbhisinghal90
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
aaina_katyal
 
Virtual Memory
Virtual MemoryVirtual Memory
Virtual Memory
vampugani
 
Virtual memory
Virtual memoryVirtual memory
Virtual memory
aaina_katyal
 
Chapter 9 - Virtual Memory
Chapter 9 - Virtual MemoryChapter 9 - Virtual Memory
Chapter 9 - Virtual Memory
Wayne Jones Jnr
 
Virtual Memory vs Cache Memory
Virtual Memory vs Cache MemoryVirtual Memory vs Cache Memory
Virtual Memory vs Cache Memory
Ashik Iqbal
 
Virtual memory
Virtual memory Virtual memory
Virtual memory
Mohammad Sadiq
 

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 Allocators
GlobalLogic Ukraine
 
Operating system
Operating systemOperating system
Operating system
Muhammad Baqar Kazmi
 
Chapter 2 part 1
Chapter 2 part 1Chapter 2 part 1
Chapter 2 part 1
rohassanie
 
Memory management in sql server
Memory management in sql serverMemory management in sql server
Memory management in sql server
Prashant 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
 
Virtual memory 20070222-en
Virtual memory 20070222-enVirtual memory 20070222-en
Virtual memory 20070222-en
Tetsuyuki Kobayashi
 
Os4
Os4Os4
Os4
Os4Os4
Lecture 23 p1
Lecture 23 p1Lecture 23 p1
Lecture 23 p1
Skillspire LLC
 
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 2
Techglyphs
 
Memory management
Memory managementMemory management
Memory management
Mohammad Sadiq
 
MongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: ShardingMongoDB for Time Series Data: Sharding
MongoDB for Time Series Data: Sharding
MongoDB
 
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
Budditha Hettige
 
Microprocessors and memory concepts
Microprocessors and memory conceptsMicroprocessors and memory concepts
Microprocessors and memory concepts
Prof. Dr. K. Adisesha
 
Software development slides
Software development slidesSoftware development slides
Software development slides
iarthur
 
Basic course
Basic courseBasic course
Basic course
Rabin Debnath
 
Vm
VmVm
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

哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
insn4465
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
MDSABBIROJJAMANPAYEL
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
171ticu
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
architagupta876
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
Prakhyath Rai
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
Madan Karki
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
co23btech11018
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
Mahmoud Morsy
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
Madan Karki
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
IJECEIAES
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
IJECEIAES
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
ecqow
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
KrishnaveniKrishnara1
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
Hitesh Mohapatra
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
UReason
 
integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
gaafergoudaay7aga
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
Madan Karki
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
PKavitha10
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
21UME003TUSHARDEB
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
Nada Hikmah
 

Recently uploaded (20)

哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
哪里办理(csu毕业证书)查尔斯特大学毕业证硕士学历原版一模一样
 
Properties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptxProperties Railway Sleepers and Test.pptx
Properties Railway Sleepers and Test.pptx
 
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样学校原版美国波士顿大学毕业证学历学位证书原版一模一样
学校原版美国波士顿大学毕业证学历学位证书原版一模一样
 
AI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptxAI assisted telemedicine KIOSK for Rural India.pptx
AI assisted telemedicine KIOSK for Rural India.pptx
 
Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...Software Engineering and Project Management - Introduction, Modeling Concepts...
Software Engineering and Project Management - Introduction, Modeling Concepts...
 
Manufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptxManufacturing Process of molasses based distillery ppt.pptx
Manufacturing Process of molasses based distillery ppt.pptx
 
Computational Engineering IITH Presentation
Computational Engineering IITH PresentationComputational Engineering IITH Presentation
Computational Engineering IITH Presentation
 
Certificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi AhmedCertificates - Mahmoud Mohamed Moursi Ahmed
Certificates - Mahmoud Mohamed Moursi Ahmed
 
Seminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptxSeminar on Distillation study-mafia.pptx
Seminar on Distillation study-mafia.pptx
 
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
Redefining brain tumor segmentation: a cutting-edge convolutional neural netw...
 
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
Electric vehicle and photovoltaic advanced roles in enhancing the financial p...
 
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
一比一原版(CalArts毕业证)加利福尼亚艺术学院毕业证如何办理
 
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.pptUnit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
Unit-III-ELECTROCHEMICAL STORAGE DEVICES.ppt
 
Generative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of contentGenerative AI leverages algorithms to create various forms of content
Generative AI leverages algorithms to create various forms of content
 
Data Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason WebinarData Driven Maintenance | UReason Webinar
Data Driven Maintenance | UReason Webinar
 
integral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdfintegral complex analysis chapter 06 .pdf
integral complex analysis chapter 06 .pdf
 
spirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptxspirit beverages ppt without graphics.pptx
spirit beverages ppt without graphics.pptx
 
CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1CEC 352 - SATELLITE COMMUNICATION UNIT 1
CEC 352 - SATELLITE COMMUNICATION UNIT 1
 
Mechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdfMechanical Engineering on AAI Summer Training Report-003.pdf
Mechanical Engineering on AAI Summer Training Report-003.pdf
 
Curve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods RegressionCurve Fitting in Numerical Methods Regression
Curve Fitting in Numerical Methods Regression
 

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