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 支持視頻雙語字幕同時,還可提供網頁的單詞翻譯和全文翻譯功能