Virtual Memory: 4 How Does Virtual Memory Work? - 双语字幕
Now, let's talk about how virtual memory works, and we're going to introduce two concepts here, virtual and physical addresses and some acronyms for them.
So how does virtual memory work?
The basic idea is we have these separate memory spaces.
So virtual memory is what a program sees.
Physical memory is the physical RAM in the computer.
When you install memory in your computer or you buy a computer with memory, this is what you're paying for.
What the program sees, the virtual memory, this is what the ISA promises.
So remember in MIPS, this promises the virtual address.
So if we do a load R4,024 R0, this is going to access a virtual address 1,024.
So the MIPS ISA promises a certain virtual memory address space, but the physical memory is what you have in your machine.
So if you have two gigabytes of RAM installed,
you're going to have physical addresses from 0 to 2 to the 31 minus 1, that's 2 billion bytes of memory.
So virtual addresses or VA,
we're going to abbreviate the virtual addresses VA, this is what the program uses, and in MIPS it's a 32-bit address space.
The physical addresses or PA, is what the hardware uses, or And this is determined by how much RAM you have installed.
If you only have a little bit of RAM installed, your physical address space, or your PA, is going to be small.
If you have a lot of RAM, it's going to be big.
But now we have separate address spaces here.
So each program is going to have its own virtual address space, and we have a physical address space for our memory.
So how do we make this work?
How does a program work?
So, the program executes a load, and the load is going to specify a virtual address because that's the way programs work.
So, here's our processor, it's running the program virtual address space, and here's our load.
So, load R3, 1024 R0.
What's the physical address going to be here?
Sorry, virtual address?
Well, it's just going to be a thing.
So the processor is going to access a virtual address 1024.
That's what this instruction is going to do.
Now, the computer is going to translate this virtual address to the physical address in the memory.
So we're going to have a translation here.
This is our map from virtual address to physical address.
And it's going to tell us how to get the data over here.
So here's the data we want for R3.
This map is going to tell us how to get this.
So we go ahead and tell the translation or the map here, we want virtual address 1,024.
It looks it up in its map, it oh, virtual address 1,024 maps to physical address 2.
So it goes over here to physical address 2,
and it goes over here Now, if the data is not in memory, it goes and loads it from disk.
In this case, it is in memory, so we're going to take this data here and we're going to return it.
So we took virtual address 1024, translated it to physical address 2, and now we send this back so we get the data.
Now, we go ahead and do another instruction.
This instruction here is going to load virtual address 512.
So we go over to our translation, ask it where 512 goes, it hey, it to physical address 12.
So we get on to physical address 12 here, go ahead and get our data, and we send it back.
Now we do another instruction, this is an add instruction, it's just using registers.
So we don't need to do any translation here.
And then we go and we have another instruction, this is going to access virtual address 700.
Sorry, 786.
So we go to virtual address 786.
The map tells us it's on disk.
It's not in memory.
Okay, it's on disk.
So what do we need to do with to get it?
Well, we need to load it into memory.
So we go ahead and load this data into memory.
Once we've loaded in memory, now we go and update the translation.
Okay, so now we no longer want to translate address 786 to disk.
We want to translate address 786 to disk location and memory.
So update that to 4.
Now when we put in virtual address 786, we get out physical address 4.
We ahead and load it from data from the memory and we return the value.
So, program executes and load with a virtual address, the computer translates it into the
physical address,
if it's not in memory,
we it from disk, and then the computer reads the RAM using the physical address and returns it to the program.
That's how virtual memory works.
So a question.
What address is located here, so address r12 has the add, sorry, value and the program issues this load.
What location in RAM is going to be accessed?
Well, we need more information here.
The program is accessing virtual address 1536,
that's what this is going to do here, but we don't know what physical address that's going to be.
So here's our processor.
It's in the program's virtual address space and we do this load.
This load is going to generate virtual address 1536,
but we're going to have a map and the map's going to tell us which physical address it is.
Now, if I don't tell you what the mapping here is, you have no idea what location in RAM this address is going to access.
So we need more information to know what memory we're actually going to access when we issue this instruction.
There's another question about using too much If a program uses more data that can fit into RAM, where does the data go?
Well, it's going to go to disk.
If it doesn't fit into the memory, we're going to use virtual memory to map it to disk.
So here's a load.
So this load's going into our table and we didn't have enough space and memory in physical memory for this virtual address.
The translation table, the map here, will tell us that it's on disk and we'll know it's on the disk.
And so you can put the data on disk if it doesn't fit into memory.
解锁更多功能
安装 Trancy 扩展,可以解锁更多功能,包括AI字幕、AI单词释义、AI语法分析、AI口语等

兼容主流视频平台
Trancy 不仅提供对 YouTube, Netflix, Udemy, Disney+, TED, edX, Kehan, Coursera 等平台的双语字幕支持,还能实现对普通网页的 AI 划词/划句翻译、全文沉浸翻译等功能,真正的语言学习全能助手。

支持全平台浏览器
Trancy 支持全平台使用,包括iOS Safari浏览器扩展
多种观影模式
支持剧场、阅读、混合等多种观影模式,全方位双语体验
多种练习模式
支持句子精听、口语测评、选择填空、默写等多种练习方式
AI 视频总结
使用 OpenAI 对视频总结,快速视频概要,掌握关键内容
AI 字幕
只需3-5分钟,即可生成 YouTube AI 字幕,精准且快速
AI 单词释义
轻点字幕中的单词,即可查询释义,并有AI释义赋能
AI 语法分析
对句子进行语法分析,快速理解句子含义,掌握难点语法
更多网页功能
Trancy 支持视频双语字幕同时,还可提供网页的单词翻译和全文翻译功能