[CS61C FA20] Lecture 29.4 - Virtual Memory I: Paged Memory — Transcript
Full transcript
- 0:00[Music]
- 0:11hello
- 0:12and welcome back to our os and virtual
- 0:14memory module
- 0:16in the previous segment we have talked
- 0:18about the
- 0:19concept of a memory manager
- 0:22our memory manager has three roles one
- 0:26to provide translation between the
- 0:28virtual addresses and the physical
- 0:29addresses
- 0:30to to provide protection between the
- 0:32processes so then
- 0:34they don't overrun each other in the
- 0:36memory
- 0:38and three it provides a mechanism for
- 0:41swapping some chunks of data
- 0:45from the dram to the disk
- 0:49let's take a look at how does this
- 0:52swapping actually work and how is it is
- 0:54is being performed generally
- 0:57it is a good idea to always move um
- 1:00a constant amount of data constant chunk
- 1:03of data fixed chunk of data between
- 1:05the dram and the disk remember
- 1:07simplicity is what we strive for
- 1:10in computer architecture so we don't
- 1:12want to have some
- 1:13variable amount of data it will be
- 1:15difficult to address we don't want to
- 1:16have a fixed amount of data
- 1:18that we are going to move between the
- 1:22the memory and the disk and
- 1:27that chunk of data is going to be
- 1:30called a page in most modern modern
- 1:32operating systems it is called
- 1:34the page so what we are dealing with is
- 1:37a concept of a page
- 1:38memory system how large is a page
- 1:42well um it shouldn't be very small
- 1:46because we don't want to go too
- 1:48frequently
- 1:50to the disk because operations with this
- 1:53are expensive in terms of time
- 1:54on the other end we want don't want to
- 1:56have too large of a chunk that we would
- 1:58like to move
- 2:00most modern operating systems pick a
- 2:03page size of 4 kb
- 2:074 kilobytes
- 2:10and that also is conveniently a multiple
- 2:12of the minimum
- 2:15addressable block in hard disk drives
- 2:19which is 512 bytes
- 2:21so four kilobits is the minimum amount
- 2:25of data we can
- 2:27retrieve from a hard disk so
- 2:30the page size is said to be 4 kilobytes
- 2:33or 4 kb
- 2:37remember risk 5 is a byte
- 2:41addressable isa so every byte within the
- 2:44page should be
- 2:46addressable how many by how many bits do
- 2:49we need to
- 2:49address uh four um kilobytes
- 2:53uh 4096 words well we need 12 bits for
- 2:57that
- 2:58so if you have a 32-bit address space
- 3:02uh we should split it into two parts in
- 3:05uh in our virtual addresses the lower 12
- 3:09bits will be used for addressing
- 3:11bits within the page and the upper 20
- 3:14bits
- 3:15will be the addresses of the pages or
- 3:18the page numbers
- 3:19how many pages can we have well
- 3:23whatever 20 bits gets us which is 2 to
- 3:26the 20 or a million pages so 32-bit
- 3:29address space gives us a million pages
- 3:31and 4096
- 3:35bytes within each of the pages
- 3:38all right
- 3:42so let's see how does this work with our
- 3:44memory manager remember our conceptual
- 3:46memory manager assigns some part
- 3:50of the memory to each of these processes
- 3:53all every single process has access to
- 3:56the full memory but
- 3:57they generally don't use all of the
- 3:59memory
- 4:01each process often has the big donut
- 4:04hole
- 4:04that is in between the heap and the
- 4:06stack that is
- 4:07empty unused memory in this concept here
- 4:11it is shown
- 4:12that it is using continuous memory that
- 4:14is allocating continuous memory chunks
- 4:16to each of the processes but in the
- 4:18practice when we look at it
- 4:20the page memory essentially shuffles
- 4:22these pages
- 4:23as it likes as it is convenient to it
- 4:27so the address
- 4:30translation happens here through the
- 4:32page tables there are each
- 4:35process is assigned a page table
- 4:40to it that is managed by the operating
- 4:43system
- 4:44so all virtual addresses
- 4:48are essentially point to the page table
- 4:50page table entries are the physical
- 4:52addresses
- 4:53of the memory that is in dram
- 4:56so if this first process is the orange
- 4:58or california gold process
- 5:00that is using three pages
- 5:03three 4096
- 5:06byte chunks then these
- 5:10california gold pages can be spread
- 5:14across the memory
- 5:20the yellow process may be using four
- 5:22pages
- 5:23that can be in their different locations
- 5:26in the memory and finally the blue
- 5:27process may be just using
- 5:29um a blue one blue
- 5:33uh page and obviously these pages don't
- 5:36need to be consec
- 5:38located consecutively in the memory it
- 5:41is up to the os
- 5:42where does it find it convenient to put
- 5:45them
- 5:46and not all of them need to be in dram
- 5:49some of them may be swapped to the disk
- 5:56again these page tables are managed by
- 5:59the operating system
- 6:02let's take a look at this first role of
- 6:04the memory manager
- 6:06the memory manager here provides
- 6:10the memory address translation this
- 6:12memory address
- 6:13translation is happening from the
- 6:15virtual address
- 6:16space to the physical address space and
- 6:20it is done by retaining the offset the
- 6:22offset stays untouched
- 6:24the page table entry is used as a lookup
- 6:28to the page
- 6:29table to produce the actual page number
- 6:33or the physical address of the page
- 6:36now notice that physical addresses may
- 6:40but don't have to have more or fewer
- 6:43bits than the virtual addresses
- 6:44remember in my computer um virtual
- 6:48addresses are 48 bits physical addresses
- 6:50are 39 bits
- 6:51so let's take a look a little bit uh in
- 6:54a little bit more detail into this
- 6:55process of address
- 6:56translation so operating system
- 6:59keeps track of which process is active
- 7:02when the process takes
- 7:04[Music]
- 7:05takes over the the the processor
- 7:10its page table becomes active as well it
- 7:12is a part of the state
- 7:14that corresponds to that process so
- 7:18then memory manager extracts the page
- 7:21number
- 7:21from the virtual address it takes the
- 7:23top 20 bits
- 7:24from the virtual address and retains the
- 7:2812 bits and saves the the lower 12 bits
- 7:31so looks up that page table
- 7:34entry in the in the page table
- 7:38and computes the physical memory address
- 7:40from the sum
- 7:41of the page address and the offset or
- 7:44actually
- 7:46concatenation of the page number
- 7:49page address and the
- 7:5212 offset bits okay
- 7:56let's take a look at how does it perform
- 7:58its second role
- 7:59a protection so
- 8:02assigning different pages in dram to
- 8:04processes
- 8:05keeps them from accessing each other's
- 8:08memory
- 8:09so this allows processes to be isolated
- 8:12from each other
- 8:13and these page tables are not handled by
- 8:15the by the processing themselves they're
- 8:17managed by the os
- 8:20in the supervisory mode
- 8:23now you may ask what happens if we need
- 8:26to
- 8:26share the data between two multiple
- 8:29processes
- 8:31well that's possible there would be a
- 8:33bit that would flag that a particular
- 8:35page
- 8:36is shareable between the processes
- 8:40so the os will assign the same physical
- 8:43page to two different uh virtual
- 8:46addresses in two different processes
- 8:50and that will permit us to share data
- 8:52between the processes
- 8:55okay how do we make sure that we do not
- 8:58write
- 8:59over certain pages that should not be
- 9:03writable
- 9:03well generally there would be a
- 9:06bit that indicates that the page
- 9:10is right protected so if we can do that
- 9:13with a single bit
- 9:14that would be somewhere in this page
- 9:16table so page tables in addition
- 9:18to these physical addresses as their
- 9:20entries are going to have some
- 9:22flags single bits that will be indicated
- 9:25think something about the status of that
- 9:27page
- 9:27so for example those that are right
- 9:29protected may have their bits set
- 9:31to one so if you try
- 9:34to write to a write protected page
- 9:40that would draw an exception and
- 9:43then the os would be handling that
- 9:46exception
- 9:47we'll let you know about that okay now
- 9:50another important thing here we
- 9:52understand how
- 9:53uh understand how does this whole
- 9:55translation happen in the
- 9:56the protection how does the how is the
- 9:58protection implemented
- 10:01but where are these page tables are they
- 10:04inside the processor are they yet
- 10:06another separate
- 10:08chunk of memory let's think a little bit
- 10:12about that
- 10:14um how many pages are there
- 10:18and how big are these pages so if you
- 10:22have a 32-bit virtual address
- 10:23with 4 kb pages a single page table
- 10:28will have 2 to the 20 entries and each
- 10:30entry will be four bytes
- 10:32wide so this is four megabytes four
- 10:35maybe
- 10:36um that's not a lot
- 10:40for a laptop like this if if a laptop
- 10:43has four gigabytes of memory
- 10:45then that will be just 0.1 percent of
- 10:47the
- 10:48on the physical memory space
- 10:51but that's typically just too much for a
- 10:54cache
- 10:56that's you know comparable to the size
- 10:57of a cache cache would not be containing
- 10:59anything else
- 11:00other than the current page
- 11:05page table so
- 11:10we can store pages inside the processor
- 11:13we can't store them in
- 11:14a cache they're too big they would have
- 11:16to reside in the memory
- 11:18there is a consequence of that in order
- 11:20to
- 11:22perform a load or a store
- 11:25we need to now make two trips to the
- 11:28memory
- 11:29we first need to
- 11:33get the the
- 11:36page table from the memory
- 11:40and then when we have that when we have
- 11:42the actual physical address
- 11:43we can perform the load or a store
- 11:50well that's inconvenient we remember
- 11:52accesses to the
- 11:55to the memory are expensive there these
- 11:58are compensated by the use of a cache
- 12:00page tables not the entire page tables
- 12:03but parts of the page tables
- 12:05will be cached those that are frequently
- 12:07accessed that frequently accessed
- 12:09entries
- 12:10in the page table will be cached because
- 12:14our cache replacement policy is going to
- 12:16support that
- 12:17so that is what is going to to speed up
- 12:19so most of the time
- 12:21we are not we don't need to make two
- 12:23trips
- 12:24to the dram in order to
- 12:27load or store data
- 12:30it is going to be residing in the cache
- 12:33so
- 12:33both our data and the the the page
- 12:37entries
- 12:38page table entries are going to be
- 12:39residing in the cache
- 12:45so um just in a quick summary our page
- 12:48tables
- 12:49are going to be stored in the memory so
- 12:51whenever we are
- 12:53referencing something uh some
- 12:56some data in the memory we are going to
- 12:58first reference the page table
- 13:00and that page table is going to
- 13:02reference the actual page
- 13:04and that is going to happen for every
- 13:07process
- 13:10we're going to take a look in a little
- 13:12bit more detail of what else is in these
- 13:15page tables after the break see you then
About this transcript
This page contains the full transcript of [CS61C FA20] Lecture 29.4 - Virtual Memory I: Paged Memory by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 1,735 words across 317 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.