YouTube2Text

[CS61C FA20] Lecture 29.4 - Virtual Memory I: Paged Memory — Transcript

by CS 61C Departmental · 1,735 words · 317 segments · language en · Watch on YouTube

Full transcript

  1. 0:00[Music]
  2. 0:11hello
  3. 0:12and welcome back to our os and virtual
  4. 0:14memory module
  5. 0:16in the previous segment we have talked
  6. 0:18about the
  7. 0:19concept of a memory manager
  8. 0:22our memory manager has three roles one
  9. 0:26to provide translation between the
  10. 0:28virtual addresses and the physical
  11. 0:29addresses
  12. 0:30to to provide protection between the
  13. 0:32processes so then
  14. 0:34they don't overrun each other in the
  15. 0:36memory
  16. 0:38and three it provides a mechanism for
  17. 0:41swapping some chunks of data
  18. 0:45from the dram to the disk
  19. 0:49let's take a look at how does this
  20. 0:52swapping actually work and how is it is
  21. 0:54is being performed generally
  22. 0:57it is a good idea to always move um
  23. 1:00a constant amount of data constant chunk
  24. 1:03of data fixed chunk of data between
  25. 1:05the dram and the disk remember
  26. 1:07simplicity is what we strive for
  27. 1:10in computer architecture so we don't
  28. 1:12want to have some
  29. 1:13variable amount of data it will be
  30. 1:15difficult to address we don't want to
  31. 1:16have a fixed amount of data
  32. 1:18that we are going to move between the
  33. 1:22the memory and the disk and
  34. 1:27that chunk of data is going to be
  35. 1:30called a page in most modern modern
  36. 1:32operating systems it is called
  37. 1:34the page so what we are dealing with is
  38. 1:37a concept of a page
  39. 1:38memory system how large is a page
  40. 1:42well um it shouldn't be very small
  41. 1:46because we don't want to go too
  42. 1:48frequently
  43. 1:50to the disk because operations with this
  44. 1:53are expensive in terms of time
  45. 1:54on the other end we want don't want to
  46. 1:56have too large of a chunk that we would
  47. 1:58like to move
  48. 2:00most modern operating systems pick a
  49. 2:03page size of 4 kb
  50. 2:074 kilobytes
  51. 2:10and that also is conveniently a multiple
  52. 2:12of the minimum
  53. 2:15addressable block in hard disk drives
  54. 2:19which is 512 bytes
  55. 2:21so four kilobits is the minimum amount
  56. 2:25of data we can
  57. 2:27retrieve from a hard disk so
  58. 2:30the page size is said to be 4 kilobytes
  59. 2:33or 4 kb
  60. 2:37remember risk 5 is a byte
  61. 2:41addressable isa so every byte within the
  62. 2:44page should be
  63. 2:46addressable how many by how many bits do
  64. 2:49we need to
  65. 2:49address uh four um kilobytes
  66. 2:53uh 4096 words well we need 12 bits for
  67. 2:57that
  68. 2:58so if you have a 32-bit address space
  69. 3:02uh we should split it into two parts in
  70. 3:05uh in our virtual addresses the lower 12
  71. 3:09bits will be used for addressing
  72. 3:11bits within the page and the upper 20
  73. 3:14bits
  74. 3:15will be the addresses of the pages or
  75. 3:18the page numbers
  76. 3:19how many pages can we have well
  77. 3:23whatever 20 bits gets us which is 2 to
  78. 3:26the 20 or a million pages so 32-bit
  79. 3:29address space gives us a million pages
  80. 3:31and 4096
  81. 3:35bytes within each of the pages
  82. 3:38all right
  83. 3:42so let's see how does this work with our
  84. 3:44memory manager remember our conceptual
  85. 3:46memory manager assigns some part
  86. 3:50of the memory to each of these processes
  87. 3:53all every single process has access to
  88. 3:56the full memory but
  89. 3:57they generally don't use all of the
  90. 3:59memory
  91. 4:01each process often has the big donut
  92. 4:04hole
  93. 4:04that is in between the heap and the
  94. 4:06stack that is
  95. 4:07empty unused memory in this concept here
  96. 4:11it is shown
  97. 4:12that it is using continuous memory that
  98. 4:14is allocating continuous memory chunks
  99. 4:16to each of the processes but in the
  100. 4:18practice when we look at it
  101. 4:20the page memory essentially shuffles
  102. 4:22these pages
  103. 4:23as it likes as it is convenient to it
  104. 4:27so the address
  105. 4:30translation happens here through the
  106. 4:32page tables there are each
  107. 4:35process is assigned a page table
  108. 4:40to it that is managed by the operating
  109. 4:43system
  110. 4:44so all virtual addresses
  111. 4:48are essentially point to the page table
  112. 4:50page table entries are the physical
  113. 4:52addresses
  114. 4:53of the memory that is in dram
  115. 4:56so if this first process is the orange
  116. 4:58or california gold process
  117. 5:00that is using three pages
  118. 5:03three 4096
  119. 5:06byte chunks then these
  120. 5:10california gold pages can be spread
  121. 5:14across the memory
  122. 5:20the yellow process may be using four
  123. 5:22pages
  124. 5:23that can be in their different locations
  125. 5:26in the memory and finally the blue
  126. 5:27process may be just using
  127. 5:29um a blue one blue
  128. 5:33uh page and obviously these pages don't
  129. 5:36need to be consec
  130. 5:38located consecutively in the memory it
  131. 5:41is up to the os
  132. 5:42where does it find it convenient to put
  133. 5:45them
  134. 5:46and not all of them need to be in dram
  135. 5:49some of them may be swapped to the disk
  136. 5:56again these page tables are managed by
  137. 5:59the operating system
  138. 6:02let's take a look at this first role of
  139. 6:04the memory manager
  140. 6:06the memory manager here provides
  141. 6:10the memory address translation this
  142. 6:12memory address
  143. 6:13translation is happening from the
  144. 6:15virtual address
  145. 6:16space to the physical address space and
  146. 6:20it is done by retaining the offset the
  147. 6:22offset stays untouched
  148. 6:24the page table entry is used as a lookup
  149. 6:28to the page
  150. 6:29table to produce the actual page number
  151. 6:33or the physical address of the page
  152. 6:36now notice that physical addresses may
  153. 6:40but don't have to have more or fewer
  154. 6:43bits than the virtual addresses
  155. 6:44remember in my computer um virtual
  156. 6:48addresses are 48 bits physical addresses
  157. 6:50are 39 bits
  158. 6:51so let's take a look a little bit uh in
  159. 6:54a little bit more detail into this
  160. 6:55process of address
  161. 6:56translation so operating system
  162. 6:59keeps track of which process is active
  163. 7:02when the process takes
  164. 7:04[Music]
  165. 7:05takes over the the the processor
  166. 7:10its page table becomes active as well it
  167. 7:12is a part of the state
  168. 7:14that corresponds to that process so
  169. 7:18then memory manager extracts the page
  170. 7:21number
  171. 7:21from the virtual address it takes the
  172. 7:23top 20 bits
  173. 7:24from the virtual address and retains the
  174. 7:2812 bits and saves the the lower 12 bits
  175. 7:31so looks up that page table
  176. 7:34entry in the in the page table
  177. 7:38and computes the physical memory address
  178. 7:40from the sum
  179. 7:41of the page address and the offset or
  180. 7:44actually
  181. 7:46concatenation of the page number
  182. 7:49page address and the
  183. 7:5212 offset bits okay
  184. 7:56let's take a look at how does it perform
  185. 7:58its second role
  186. 7:59a protection so
  187. 8:02assigning different pages in dram to
  188. 8:04processes
  189. 8:05keeps them from accessing each other's
  190. 8:08memory
  191. 8:09so this allows processes to be isolated
  192. 8:12from each other
  193. 8:13and these page tables are not handled by
  194. 8:15the by the processing themselves they're
  195. 8:17managed by the os
  196. 8:20in the supervisory mode
  197. 8:23now you may ask what happens if we need
  198. 8:26to
  199. 8:26share the data between two multiple
  200. 8:29processes
  201. 8:31well that's possible there would be a
  202. 8:33bit that would flag that a particular
  203. 8:35page
  204. 8:36is shareable between the processes
  205. 8:40so the os will assign the same physical
  206. 8:43page to two different uh virtual
  207. 8:46addresses in two different processes
  208. 8:50and that will permit us to share data
  209. 8:52between the processes
  210. 8:55okay how do we make sure that we do not
  211. 8:58write
  212. 8:59over certain pages that should not be
  213. 9:03writable
  214. 9:03well generally there would be a
  215. 9:06bit that indicates that the page
  216. 9:10is right protected so if we can do that
  217. 9:13with a single bit
  218. 9:14that would be somewhere in this page
  219. 9:16table so page tables in addition
  220. 9:18to these physical addresses as their
  221. 9:20entries are going to have some
  222. 9:22flags single bits that will be indicated
  223. 9:25think something about the status of that
  224. 9:27page
  225. 9:27so for example those that are right
  226. 9:29protected may have their bits set
  227. 9:31to one so if you try
  228. 9:34to write to a write protected page
  229. 9:40that would draw an exception and
  230. 9:43then the os would be handling that
  231. 9:46exception
  232. 9:47we'll let you know about that okay now
  233. 9:50another important thing here we
  234. 9:52understand how
  235. 9:53uh understand how does this whole
  236. 9:55translation happen in the
  237. 9:56the protection how does the how is the
  238. 9:58protection implemented
  239. 10:01but where are these page tables are they
  240. 10:04inside the processor are they yet
  241. 10:06another separate
  242. 10:08chunk of memory let's think a little bit
  243. 10:12about that
  244. 10:14um how many pages are there
  245. 10:18and how big are these pages so if you
  246. 10:22have a 32-bit virtual address
  247. 10:23with 4 kb pages a single page table
  248. 10:28will have 2 to the 20 entries and each
  249. 10:30entry will be four bytes
  250. 10:32wide so this is four megabytes four
  251. 10:35maybe
  252. 10:36um that's not a lot
  253. 10:40for a laptop like this if if a laptop
  254. 10:43has four gigabytes of memory
  255. 10:45then that will be just 0.1 percent of
  256. 10:47the
  257. 10:48on the physical memory space
  258. 10:51but that's typically just too much for a
  259. 10:54cache
  260. 10:56that's you know comparable to the size
  261. 10:57of a cache cache would not be containing
  262. 10:59anything else
  263. 11:00other than the current page
  264. 11:05page table so
  265. 11:10we can store pages inside the processor
  266. 11:13we can't store them in
  267. 11:14a cache they're too big they would have
  268. 11:16to reside in the memory
  269. 11:18there is a consequence of that in order
  270. 11:20to
  271. 11:22perform a load or a store
  272. 11:25we need to now make two trips to the
  273. 11:28memory
  274. 11:29we first need to
  275. 11:33get the the
  276. 11:36page table from the memory
  277. 11:40and then when we have that when we have
  278. 11:42the actual physical address
  279. 11:43we can perform the load or a store
  280. 11:50well that's inconvenient we remember
  281. 11:52accesses to the
  282. 11:55to the memory are expensive there these
  283. 11:58are compensated by the use of a cache
  284. 12:00page tables not the entire page tables
  285. 12:03but parts of the page tables
  286. 12:05will be cached those that are frequently
  287. 12:07accessed that frequently accessed
  288. 12:09entries
  289. 12:10in the page table will be cached because
  290. 12:14our cache replacement policy is going to
  291. 12:16support that
  292. 12:17so that is what is going to to speed up
  293. 12:19so most of the time
  294. 12:21we are not we don't need to make two
  295. 12:23trips
  296. 12:24to the dram in order to
  297. 12:27load or store data
  298. 12:30it is going to be residing in the cache
  299. 12:33so
  300. 12:33both our data and the the the page
  301. 12:37entries
  302. 12:38page table entries are going to be
  303. 12:39residing in the cache
  304. 12:45so um just in a quick summary our page
  305. 12:48tables
  306. 12:49are going to be stored in the memory so
  307. 12:51whenever we are
  308. 12:53referencing something uh some
  309. 12:56some data in the memory we are going to
  310. 12:58first reference the page table
  311. 13:00and that page table is going to
  312. 13:02reference the actual page
  313. 13:04and that is going to happen for every
  314. 13:07process
  315. 13:10we're going to take a look in a little
  316. 13:12bit more detail of what else is in these
  317. 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.