Tác giả giữ toàn bộ bản quyền (All Rights Reserved) — không phải giấy phép mở. Bạn vẫn xem và học miễn phí trên OpenER; muốn tái sử dụng cần xin phép tác giả.
[MUSIC PLAYING] PROFESSOR: Hi, welcome back to the module that deals with operating system and virtual memory.
Where we left it off was at the point where we discussed the role of the operating system, and specifically, we talked about multiple programming and the way how operating system — through its supervisor mode — supports multiple processes that are running on the same core.
There can be many, many processes that are running on a microprocessor and they are all sharing the processor core in time by taking turns.
And the supervisor mode is there to support that, to interrupt one process and let another one run.
But in order for all of that to work, we also have to have a way to share the memory.
We started with one processor, we figured out how to share it, and we also have one, this giant vision of memory.
We need to figure out what is a good way to share the memory. So there comes the concept of virtual memory.
We hinted at what it is, but let's dive into it in a bit more detail. So virtual memory is the next level in memory hierarchy.
It is something that is in the memory hierarchy that is beyond our caches.
It is there to provide every process and every program and illusion that it has a very, very large memory available to itself at any time.
It is organized about a concept around the concept of pages, and these pages of memory will reside either in DRAM, but some of them will be put on a disk.
Those that are more active, more recently being used, are going to be in the memory.
Those that are not used so much or haven't been used in a while will be put on a disk.
Remember, our DRAM, our main memory, is faster — a lot faster — than the disk.
So a concept around these pages is called the paging or demand paging.
It provides the ability to run programs that are larger than the primary memory, because we can swap some of these pages to the disk.
So we can use disk as our extended DRAM. Very cool. It is also another important.
There is another concept about that is different machines when we build a different PC or buy a different PC, they come with different amounts of memory. You've seen that.
Some of them have 8 gigabytes, some of them may have 16 gigabytes, some may have 64 gigabytes, but all programs see them the same way, because they will extend some of their memory into the disk through paging and the concept of virtual memory.
Another important concept that is associated with virtual memory is that enables the operating system to protect processes from each other, which what does this mean?
This protection is something that is really important. We don't want programs to accidentally or maliciously run over each other's memory space.
So everybody sees its own world, every process is its own world, and the OS is there to orchestrate that. Virtual memory supports that.
Such that at the time when it is running, when it got the processor, time and the processor, it thinks that it has all the memory to itself.
All right, and another important thing to keep in mind. Virtual memory is a very old concept. It predates the caches.
It was — I believe — introduced in IBM 360 processors a long, long time ago, in the '60s, and has been expanded through the time.
Remember, back then, there was not a big speed gap between the processors and the memory. They were running at about the same speed, so we really didn't need caches.
But we need to support multiple processes running, and that's how the concept of virtual memory came about.
Now, let's take a look at this pyramid that describes our principles of locality and memory hierarchy. At the very top, what we have seen before we have the CPU.
Its registers are blazingly fast, but there is very few of them. In RISC-V, there are 32 general purpose registers.
Then our physical memory is our random access memory, and there is a gap in speed between the speed of the processor core and the physical memory.
To bridge that gap, we build multiple layers of cash. Each one of them being larger than the previous and a little bit slower.
Then when we talk about our concept of virtual memory, it is there built around the physical memory that typically lives DRAM, and there are different types of DRAM like DDR3, 4, or 5 that is coming out, and then HBM.
Same technology. This is all dynamic random access memory technology just in package around different types of packages and different protocols that access it.
But then below that, our virtual memory extends into the solid state drives and hard disk drives.
They're blazingly fast, but not as fast as our physical memory, as our DRAM are not nearly as fast as our registers.
How much not fast, well, like a million times. But it is really cheap, so it is there to provide this illusion of really having infinite amount of memory.
So CPU can — by working through the memory hierarchy, can have an illusion that everything is really, really fast, as fast as the registers or the cache.
And yet, as big as our virtual memory space.
In order to support that, we need to expand our picture of how does the processor core with the cache work with the memory.
So there is a layer of abstraction that we have added in here.
Each processor, each program that we write has its own view of the memory space, and if you're writing a C program or assembly code, we get used to having these different regions of memory that we have.
But one important thing is that we see all of that to ourselves. So we have a region where we're going to keep our code.
We'll keep some of our static data, and then heap and stack are going to grow into the unused space into the free memory naturally or the way how we allocate it.
We always think we have the entire memory to us. All the others is from 0 to a fffff.
And when we are writing programs, we really can't do this kind of stuff, negotiating with someone else. Hey, Dan, which part of the memory are you using? Can I take from 0bbff to ffff.
Oh, yeah, sure. No, we can't do that. I mean, we get these we download applications from the internet, from app stores, and so on.
We can't fragment the memory into small chunks so everybody has their little piece of my memory. It would be very inefficient.
We just have to have a way how we map these different processes into different parts of a physical memory.
So there is this step that the virtual memory system needs to support, which is translation of virtual addresses, which is what the program sees, the physical addresses, which are the physical addresses of things that are in the memory in the DRAM and the disk.
So there will be many processes and data running and many processor cores that are running independently, supporting all, running in the same virtual memory space and then there will be one main memory, where our operating system and our virtual memory system
is going to help us translate. When we talk about the address spaces there are two types of other spaces that we see.
Address space is a set of addresses for all available memory locations. There are now two different address spaces, one of them is the virtual address space, the other one is the physical address space.
Virtual address space is a set of addresses that the user program knows about.
Physical address space is the one that exists in a particular computer that is set by the amount of DRAM and eventually disk that we may have.
Users programs don't know that. That is one of the roles of the virtual memory system to hide that so that we can run programs in different configurations of PCs, for example.
And there is a memory manager that translates between these two spaces. So when we talk about these two different address spaces, they don't have to be exactly the same.
If you look at bora's laptop that I'm running this on, you'll find out maybe a bit of a surprise, but you'll see it's not really a surprise.
But they have 39 bits of physical addresses and 48 bits of virtual addresses. So my virtual address space on this laptop is bigger than the physical space.
Both of them are huge, so it may not matter that much.
I think what you will find out if you're on the same command on your LSCPU on your laptop, you'll find out what is it in your case.
It's usually going to be 39 physical bits. If you have a [INAUDIBLE],, maybe 40.
Okay, so when we talk a little bit about understanding differences in this translation from the virtual space to the physical space of addresses or virtual range of addresses to physical range of addresses, there are some useful analogies that we can come up with.
We have to think about — it's a really good analogy when we think about the libraries and how things work in a library.
In a physical library, we like library cards and library card numbers, but you know? That works also in a virtual world.
I'm just going to describe this, assuming that we still actually go to the physical library where there are physical books.
The way what we can think about as a book title, it's like a virtual address. For example, our Patterson and Hennessy textbook may have different versions of it.
There is a RISC-V version, there is an armed version, there are different editions and so on. But the actual version that we are using in this book is unique.
In this class, the actual version that we're using in this class is unique. It has one unique number, which is associated with this library of congress call number.
That is our physical address. So if you want to go to a library and find that particular book, there are these drawers with the cards in there.
And each card points to a particular location in the library where we can find that book on which shelf is it going to be.
So this card catalog is like a page table that maps from the book title, because that's where we search by the author name or the title of a book to the actual call number that corresponds to these library of call numbers.
This card, when we pull it out in front of us in the library, in our local library is going to tell us on which shelf it is.
But in another branch, it may say that it exists in this library or it's another branch in some reserves somewhere, where we would have to retrieve it from.
So that means it may be available locally, like in the memory, or maybe on a disk, which is really what happens with the books that are much, much less frequently used.
And there is another important part of our knowledge that corresponds to the virtual memory systems. It will tell us how long can we borrow that book from.
So some of them may be restricted to be read within the library for two hours or some of them may be able to be checked out for two weeks or some of them may be available to be checked out for the semester.
That is what we are going to call the access rights. I'm going to repeat this slide.
If it did not make too much sense, I mean to repeat this slide a bit later when we really introduce the corresponding memory concepts.
So one final thing to recap here, what is the role of the virtual memory and these requirements in supporting the memory hierarchy?
The whole system of translation is there to allow multiple processes to simultaneously occupy all of the memory or almost all of the memory and provide protection from each other.
We don't want somebody — dance program to run over mind and overwrite my data or overwrite my code.
And it is really important, because there are many, many programs that are independently developed, and we do want to make sure that each one of them has had the time and it has a processor, also an illusion that it has all of the memory available to itself.
So we're going to take a quick break here. After the break, we are going to talk about how does this physical memory theorem and disk actually look like.
See you after our break.
Đăng nhập để đánh giá học liệu này.
Đăng nhập để bình luận — chưa ai bình luận về học liệu này.
Không có khóa học liên quan.