[CS61C FA20] Lecture 29.1 - Virtual Memory I: Virtual Memory Concepts — Transcript
Full transcript
- 0:00[Music]
- 0:08hi
- 0:09welcome back to the module that deals
- 0:12with
- 0:13operating system and virtual memory
- 0:16where we left it off was at the point
- 0:19where we discussed
- 0:20the role of the operating system and
- 0:23specifically we talked about
- 0:25multi-programming
- 0:26and the way how operating system through
- 0:30a supervisor mode supports
- 0:33multiple processes that are running on
- 0:35the same core
- 0:36there can be many many processes that
- 0:39are running on a microprocessor
- 0:41and they're all sharing the
- 0:45processor core in time by taking turns
- 0:48and the supervisor mode is there to
- 0:52support that
- 0:53to interrupt one process and let another
- 0:56one
- 0:56run but
- 0:59in order for all of that to work we also
- 1:03have to have a way to share the memory
- 1:05uh we started with one processor we
- 1:07figured out how to share it
- 1:08and we also have one this giant vision
- 1:11of memory
- 1:12we need to figure out what is a good way
- 1:14to share the memory
- 1:17so there comes the concept of virtual
- 1:20memory we kind of
- 1:21hinted at what it is but let's
- 1:25dive into it in a bit more detail
- 1:29so virtual memory is the next level in
- 1:32memory hierarchy
- 1:33um it is something that is in the memory
- 1:36hierarchy
- 1:36that is beyond our caches
- 1:40it is there to provide every process and
- 1:43every program an
- 1:44illusion that it has a very very large
- 1:47memory
- 1:48available to itself at any time
- 1:53it is organized about a concept around
- 1:56the concept of
- 1:57pages and these pages of memory
- 2:01will reside either in dram but some of
- 2:04them
- 2:05will be put on a disk those that are
- 2:07more active
- 2:08uh more recently being used are going to
- 2:11be in the memory
- 2:13those that are not used so much or
- 2:15haven't been used in a while
- 2:16will be put on a disk remember our dram
- 2:20our main memory is faster a lot faster
- 2:24than the disk
- 2:28so the concept around these
- 2:31pages is called the paging or demand
- 2:34paging
- 2:35it provides the ability to run program
- 2:37programs that are
- 2:38larger than the primary memory because
- 2:40we can
- 2:41swap some of these pages
- 2:44to the disk so we can use disk as our
- 2:48extended
- 2:50d-ram very cool
- 2:53it is also another important there is
- 2:55another concept about that
- 2:56is different machines when we build a
- 2:59different pc or buy a different pc they
- 3:01come with different amounts of memory
- 3:03you've seen that you know some of them
- 3:05have eight gigabytes some of them may
- 3:07have 16 gigabytes some may have 64
- 3:09gigabytes
- 3:11but all programs see them the same way
- 3:14because they will extend some of their
- 3:16memory
- 3:17into the disk through paging and the
- 3:20concept of
- 3:21virtual memory
- 3:25another important concept that is
- 3:27associated with virtual memory
- 3:29is that enables the operating system
- 3:32to protect processes from each other
- 3:36which what does this mean this
- 3:38protection is something that is really
- 3:40important we don't want
- 3:42programs to accidentally or maliciously
- 3:46run over each other's memory space so
- 3:48everybody sees
- 3:50its own world every process is its own
- 3:52world and
- 3:54the os is there to orchestrate that
- 3:57virtual memory supports that
- 4:02such that at the time when it is running
- 4:04when it got
- 4:05the processor time on the processor
- 4:08it thinks that it has all the memory to
- 4:10itself
- 4:12all right and another important thing to
- 4:14to
- 4:15keep in mind virtual memory is a very
- 4:18old concept it predates the caches it
- 4:20was
- 4:21i believe introduced in ibm 360
- 4:24processors
- 4:24long long time ago like in the 60s
- 4:28and has been expanded
- 4:32through the time remember back then
- 4:34there was not a big
- 4:36speed gap between the processors and the
- 4:38memory they were running at about the
- 4:40same
- 4:40same speed so we really didn't need
- 4:42caches but we needed to support
- 4:44multiple processes running and that's
- 4:47how the concept of virtual memory
- 4:50came about now
- 4:53let's take a look at this pyramid of
- 4:56that
- 4:56describes our principles of locality and
- 4:58memory hierarchy
- 5:00at the very top what we have seen before
- 5:02we have the cpu
- 5:04its registers are blazingly fast but
- 5:05there is very few of them in risk five
- 5:07there are 32
- 5:09general purpose registers then our
- 5:12physical memory is our
- 5:13random access memory and there is a gap
- 5:16in speed
- 5:16between the speed of the processor core
- 5:19and the physical memory
- 5:24bridge that gap we built multiple
- 5:27layers of cache each one of them being
- 5:31larger than the previous and
- 5:34a little bit slower
- 5:37then when we talk about
- 5:41our concept of virtual memory it is
- 5:44there
- 5:45built around the physical memory that
- 5:46typically lives in dram
- 5:48and there are different types of dram
- 5:50like ddr 3 4
- 5:52or 5 that is coming out and then
- 5:55hbm same technology this is all
- 5:58dynamic random access memory technology
- 6:00just in
- 6:02packaged around different types of
- 6:03packages and different protocols that
- 6:06access it
- 6:07but then below that our virtual memory
- 6:09extends
- 6:10into the solid-state drives and hard
- 6:13disk drives
- 6:15they're blazingly fast but not
- 6:18as fast as the as our
- 6:22um physical memory as our dram are
- 6:25not nearly as fast as our registers
- 6:29how much not fast well you know like a
- 6:32million times
- 6:34but it is really cheap so we can have
- 6:37it is there to provide this illusion of
- 6:40really having
- 6:41infinite amount of memory so cpu
- 6:44can by working through the memory
- 6:46hierarchy can have an illusion that
- 6:48everything is really really fast as fast
- 6:51as the registers or the cache
- 6:52and yet as big as our virtual memory
- 6:55space
- 6:58in order to support that we need to
- 7:00expand our picture
- 7:02of how does the processor core with the
- 7:04cache
- 7:05work with the memory so
- 7:09there is a layer of abstraction that we
- 7:11have added in here
- 7:13each process sir each program that we
- 7:16write
- 7:17has its own view of the memory space and
- 7:20if you're writing a c
- 7:22program or assembly code we have we get
- 7:24used to having these different regions
- 7:26of memory
- 7:27that we have but one important thing is
- 7:30that we see all of that to ourselves so
- 7:33we have a
- 7:34region where we're going to keep our
- 7:35code we'll
- 7:37keep some of our static data and then
- 7:40heap and stack are going to grow
- 7:41into the unused space into the
- 7:45into the frame memory um
- 7:50naturally or the way how we we allocate
- 7:52it
- 7:54we always think we have the entire
- 7:56memory to us
- 7:57um you know all the addresses from zero
- 7:59to ffffffff
- 8:02and when you're writing programs we
- 8:04really can't
- 8:05you know do this kind of stuff
- 8:07negotiating with someone else
- 8:08hey dan you know which part of the
- 8:10memory are you using can i take
- 8:12from you know zero bb ffff to
- 8:15ffffffff oh yeah sure no you we can't do
- 8:18that i mean if
- 8:19we get these we download the
- 8:20applications from the internet from the
- 8:22from app stores and so on you know we
- 8:25can't
- 8:26you know fragment the memory into small
- 8:28chunks so everybody has their
- 8:29little piece of a memory that will be
- 8:31very inefficient
- 8:34we just have to have a way how we map
- 8:37these different processes
- 8:38into different parts of a physical
- 8:40memory so there is this
- 8:42step that the virtual memory system
- 8:44needs to support which is translation of
- 8:46virtual addresses
- 8:47which is what the program sees to
- 8:49physical addresses which are the
- 8:51physical addresses
- 8:53of things that are on the
- 8:58in the memory in the dram and the disk
- 9:03so there will be many processes
- 9:07and that are running um you know
- 9:10and many processor cores that are
- 9:11running independently
- 9:13supporting all running in the same
- 9:16virtual memory space
- 9:18and then there will be one main memory
- 9:20where our operating system and the
- 9:22virtual our virtual memory system is
- 9:24going to help us
- 9:25translate them to
- 9:28when we talk about the address spaces
- 9:31there are two types of address spaces
- 9:33that we see address space
- 9:35is a set of addresses for all available
- 9:37memory
- 9:38uh locations there are now two different
- 9:41address spaces one of them
- 9:43is the virtual address space the other
- 9:45one is the physical address space
- 9:48virtual other space is a set of
- 9:51addresses
- 9:52that the user program knows about
- 9:56physical address space is the one that
- 9:59exists
- 10:00in a particular computer that is set
- 10:03by the amount of dram and eventually
- 10:06disk
- 10:06that we may have users don't know
- 10:10programs don't know that
- 10:11that is one of the roles of the virtual
- 10:13memory system to hide that so that we
- 10:15can run programs in different
- 10:16configurations
- 10:18of of pcs for example
- 10:22and there is a memory manager manager
- 10:24that translates between these two spaces
- 10:27so when we talk about these two
- 10:29different address spaces
- 10:30they don't have to be exactly the same
- 10:33if you
- 10:33look at bora's laptop that you know i'm
- 10:35running this on
- 10:36you'll find out you know maybe a bit of
- 10:39a surprise but you'll see it's not
- 10:41really a surprise
- 10:42that they have 39 bits of physical
- 10:44addresses and 48 bits
- 10:46of virtual addresses so my virtual
- 10:49address space on this laptop is bigger
- 10:51than the physical space
- 10:54both of them are huge so it may not
- 10:56matter
- 10:57that much i think what you will find out
- 11:00if you run the same command on your
- 11:02uh ls cpu on on your laptop you'll find
- 11:05out what is it
- 11:05in your case it's usually going to be 39
- 11:08physical bits
- 11:10um if you have a xeon it may be 40.
- 11:13okay so when we talk a little bit about
- 11:17understanding differences in this
- 11:19translation from
- 11:21the virtual space to the physical space
- 11:25of addresses or virtual range of
- 11:27addresses the physical range of
- 11:28addresses
- 11:29there are some useful analogies that we
- 11:31can come up with
- 11:36and we can we have to think about you
- 11:39know it's like it's a really good
- 11:40analogy when we think about
- 11:41the libraries and how things work in a
- 11:44library
- 11:45um in a physical library with like
- 11:48library cards
- 11:49and library call numbers
- 11:52but you know that works also in a
- 11:54virtual world i'm just going to describe
- 11:56this
- 11:57assuming that we still actually go to
- 11:59the physical library where there are
- 12:01physical books
- 12:03the way what we can think about uh as a
- 12:06book title
- 12:07um it's like a virtual address for
- 12:10example our
- 12:11patterson and hennessy textbook may have
- 12:14different versions of it
- 12:15um you know there is a risk 5 version
- 12:18there is an
- 12:18armed version there are different
- 12:20editions and so on
- 12:23but the actual version that we are using
- 12:25in this book
- 12:26is unique in in this class the actual
- 12:28version that we're using in this class
- 12:30is unique
- 12:31um it has one unique number
- 12:34which is associated with this library of
- 12:36congress
- 12:37call number that is our physical address
- 12:42so if you want to go to a library and
- 12:44find that particular book
- 12:47there are these drawers with the
- 12:50cards in there and each card points to a
- 12:54particular location in the library where
- 12:56we can find that book on which kind of
- 12:58which shelf is it going to be so this
- 13:00card catalog
- 13:01is like a page table that
- 13:05maps from the book title because that's
- 13:07where we search by the author name or
- 13:09the title of a book
- 13:11to the actual call number that
- 13:12corresponds to this library of congress
- 13:15call numbers on
- 13:18this card when we pull it out in front
- 13:21of us
- 13:22in the library um in our local library
- 13:25is going to tell us on which shelf it is
- 13:27but in another branch but it may
- 13:31say that it is it exists in this library
- 13:34or it's another branch
- 13:35in some reserves somewhere uh where we
- 13:38would have to
- 13:40uh to to retrieve it from so that means
- 13:42it may be available
- 13:44locally like in the memory or maybe
- 13:48on a disk which is really what happens
- 13:50with the books that
- 13:51are much frequent much less frequently
- 13:54used and there is another important part
- 13:58of
- 13:58analogy that corresponds to the virtual
- 14:01memory
- 14:02systems it will tell us
- 14:05how much how long can we borrow that
- 14:08from so some of them may be restricted
- 14:11to be read within the library for two
- 14:13hours
- 14:14or some of them may be able to be
- 14:16checked out for two weeks or some of
- 14:18them may be
- 14:19available to be checked out for the
- 14:20semester that is what we are going to
- 14:22call the access rights
- 14:23i'm going to repeat this slide if it did
- 14:25not make too much sense
- 14:27and we're i'm going to repeat this slide
- 14:29slide
- 14:30a bit later when we really introduce the
- 14:33corresponding memory concepts
- 14:37so one final thing to recap here
- 14:41what is the role of the virtual memory
- 14:44and these requirements in supporting the
- 14:46memory hierarchy
- 14:48it is there that the whole system of
- 14:51translation is there to allow multiple
- 14:53processes to simultaneously occupy
- 14:56all of the memory or almost all of the
- 14:58memory and provide protection from each
- 15:00other
- 15:01we don't want somebody you know dan's
- 15:04program to run
- 15:05over mine and overwrite my data or
- 15:08overwrite my code
- 15:10um and
- 15:12it is really important because there are
- 15:15many many programs that are
- 15:17independently developed um and we do
- 15:20want to make sure that each one of them
- 15:22has at the time when it has a processor
- 15:25also an illusion that it has all
- 15:28of the memory available to itself
- 15:31so we're going to take a quick break
- 15:33here after a break we're going to talk
- 15:35about
- 15:36how does this physical memory dram
- 15:39and disk actually look like
- 15:42see you after a break
About this transcript
This page contains the full transcript of [CS61C FA20] Lecture 29.1 - Virtual Memory I: Virtual Memory Concepts by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 2,279 words across 415 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to translate the transcript into 100+ languages.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.