YouTube2Text

[CS61C FA20] Lecture 29.1 - Virtual Memory I: Virtual Memory Concepts — Transcript

by CS 61C Departmental · 2,279 words · 415 segments · language en · Watch on YouTube

Full transcript

  1. 0:00[Music]
  2. 0:08hi
  3. 0:09welcome back to the module that deals
  4. 0:12with
  5. 0:13operating system and virtual memory
  6. 0:16where we left it off was at the point
  7. 0:19where we discussed
  8. 0:20the role of the operating system and
  9. 0:23specifically we talked about
  10. 0:25multi-programming
  11. 0:26and the way how operating system through
  12. 0:30a supervisor mode supports
  13. 0:33multiple processes that are running on
  14. 0:35the same core
  15. 0:36there can be many many processes that
  16. 0:39are running on a microprocessor
  17. 0:41and they're all sharing the
  18. 0:45processor core in time by taking turns
  19. 0:48and the supervisor mode is there to
  20. 0:52support that
  21. 0:53to interrupt one process and let another
  22. 0:56one
  23. 0:56run but
  24. 0:59in order for all of that to work we also
  25. 1:03have to have a way to share the memory
  26. 1:05uh we started with one processor we
  27. 1:07figured out how to share it
  28. 1:08and we also have one this giant vision
  29. 1:11of memory
  30. 1:12we need to figure out what is a good way
  31. 1:14to share the memory
  32. 1:17so there comes the concept of virtual
  33. 1:20memory we kind of
  34. 1:21hinted at what it is but let's
  35. 1:25dive into it in a bit more detail
  36. 1:29so virtual memory is the next level in
  37. 1:32memory hierarchy
  38. 1:33um it is something that is in the memory
  39. 1:36hierarchy
  40. 1:36that is beyond our caches
  41. 1:40it is there to provide every process and
  42. 1:43every program an
  43. 1:44illusion that it has a very very large
  44. 1:47memory
  45. 1:48available to itself at any time
  46. 1:53it is organized about a concept around
  47. 1:56the concept of
  48. 1:57pages and these pages of memory
  49. 2:01will reside either in dram but some of
  50. 2:04them
  51. 2:05will be put on a disk those that are
  52. 2:07more active
  53. 2:08uh more recently being used are going to
  54. 2:11be in the memory
  55. 2:13those that are not used so much or
  56. 2:15haven't been used in a while
  57. 2:16will be put on a disk remember our dram
  58. 2:20our main memory is faster a lot faster
  59. 2:24than the disk
  60. 2:28so the concept around these
  61. 2:31pages is called the paging or demand
  62. 2:34paging
  63. 2:35it provides the ability to run program
  64. 2:37programs that are
  65. 2:38larger than the primary memory because
  66. 2:40we can
  67. 2:41swap some of these pages
  68. 2:44to the disk so we can use disk as our
  69. 2:48extended
  70. 2:50d-ram very cool
  71. 2:53it is also another important there is
  72. 2:55another concept about that
  73. 2:56is different machines when we build a
  74. 2:59different pc or buy a different pc they
  75. 3:01come with different amounts of memory
  76. 3:03you've seen that you know some of them
  77. 3:05have eight gigabytes some of them may
  78. 3:07have 16 gigabytes some may have 64
  79. 3:09gigabytes
  80. 3:11but all programs see them the same way
  81. 3:14because they will extend some of their
  82. 3:16memory
  83. 3:17into the disk through paging and the
  84. 3:20concept of
  85. 3:21virtual memory
  86. 3:25another important concept that is
  87. 3:27associated with virtual memory
  88. 3:29is that enables the operating system
  89. 3:32to protect processes from each other
  90. 3:36which what does this mean this
  91. 3:38protection is something that is really
  92. 3:40important we don't want
  93. 3:42programs to accidentally or maliciously
  94. 3:46run over each other's memory space so
  95. 3:48everybody sees
  96. 3:50its own world every process is its own
  97. 3:52world and
  98. 3:54the os is there to orchestrate that
  99. 3:57virtual memory supports that
  100. 4:02such that at the time when it is running
  101. 4:04when it got
  102. 4:05the processor time on the processor
  103. 4:08it thinks that it has all the memory to
  104. 4:10itself
  105. 4:12all right and another important thing to
  106. 4:14to
  107. 4:15keep in mind virtual memory is a very
  108. 4:18old concept it predates the caches it
  109. 4:20was
  110. 4:21i believe introduced in ibm 360
  111. 4:24processors
  112. 4:24long long time ago like in the 60s
  113. 4:28and has been expanded
  114. 4:32through the time remember back then
  115. 4:34there was not a big
  116. 4:36speed gap between the processors and the
  117. 4:38memory they were running at about the
  118. 4:40same
  119. 4:40same speed so we really didn't need
  120. 4:42caches but we needed to support
  121. 4:44multiple processes running and that's
  122. 4:47how the concept of virtual memory
  123. 4:50came about now
  124. 4:53let's take a look at this pyramid of
  125. 4:56that
  126. 4:56describes our principles of locality and
  127. 4:58memory hierarchy
  128. 5:00at the very top what we have seen before
  129. 5:02we have the cpu
  130. 5:04its registers are blazingly fast but
  131. 5:05there is very few of them in risk five
  132. 5:07there are 32
  133. 5:09general purpose registers then our
  134. 5:12physical memory is our
  135. 5:13random access memory and there is a gap
  136. 5:16in speed
  137. 5:16between the speed of the processor core
  138. 5:19and the physical memory
  139. 5:24bridge that gap we built multiple
  140. 5:27layers of cache each one of them being
  141. 5:31larger than the previous and
  142. 5:34a little bit slower
  143. 5:37then when we talk about
  144. 5:41our concept of virtual memory it is
  145. 5:44there
  146. 5:45built around the physical memory that
  147. 5:46typically lives in dram
  148. 5:48and there are different types of dram
  149. 5:50like ddr 3 4
  150. 5:52or 5 that is coming out and then
  151. 5:55hbm same technology this is all
  152. 5:58dynamic random access memory technology
  153. 6:00just in
  154. 6:02packaged around different types of
  155. 6:03packages and different protocols that
  156. 6:06access it
  157. 6:07but then below that our virtual memory
  158. 6:09extends
  159. 6:10into the solid-state drives and hard
  160. 6:13disk drives
  161. 6:15they're blazingly fast but not
  162. 6:18as fast as the as our
  163. 6:22um physical memory as our dram are
  164. 6:25not nearly as fast as our registers
  165. 6:29how much not fast well you know like a
  166. 6:32million times
  167. 6:34but it is really cheap so we can have
  168. 6:37it is there to provide this illusion of
  169. 6:40really having
  170. 6:41infinite amount of memory so cpu
  171. 6:44can by working through the memory
  172. 6:46hierarchy can have an illusion that
  173. 6:48everything is really really fast as fast
  174. 6:51as the registers or the cache
  175. 6:52and yet as big as our virtual memory
  176. 6:55space
  177. 6:58in order to support that we need to
  178. 7:00expand our picture
  179. 7:02of how does the processor core with the
  180. 7:04cache
  181. 7:05work with the memory so
  182. 7:09there is a layer of abstraction that we
  183. 7:11have added in here
  184. 7:13each process sir each program that we
  185. 7:16write
  186. 7:17has its own view of the memory space and
  187. 7:20if you're writing a c
  188. 7:22program or assembly code we have we get
  189. 7:24used to having these different regions
  190. 7:26of memory
  191. 7:27that we have but one important thing is
  192. 7:30that we see all of that to ourselves so
  193. 7:33we have a
  194. 7:34region where we're going to keep our
  195. 7:35code we'll
  196. 7:37keep some of our static data and then
  197. 7:40heap and stack are going to grow
  198. 7:41into the unused space into the
  199. 7:45into the frame memory um
  200. 7:50naturally or the way how we we allocate
  201. 7:52it
  202. 7:54we always think we have the entire
  203. 7:56memory to us
  204. 7:57um you know all the addresses from zero
  205. 7:59to ffffffff
  206. 8:02and when you're writing programs we
  207. 8:04really can't
  208. 8:05you know do this kind of stuff
  209. 8:07negotiating with someone else
  210. 8:08hey dan you know which part of the
  211. 8:10memory are you using can i take
  212. 8:12from you know zero bb ffff to
  213. 8:15ffffffff oh yeah sure no you we can't do
  214. 8:18that i mean if
  215. 8:19we get these we download the
  216. 8:20applications from the internet from the
  217. 8:22from app stores and so on you know we
  218. 8:25can't
  219. 8:26you know fragment the memory into small
  220. 8:28chunks so everybody has their
  221. 8:29little piece of a memory that will be
  222. 8:31very inefficient
  223. 8:34we just have to have a way how we map
  224. 8:37these different processes
  225. 8:38into different parts of a physical
  226. 8:40memory so there is this
  227. 8:42step that the virtual memory system
  228. 8:44needs to support which is translation of
  229. 8:46virtual addresses
  230. 8:47which is what the program sees to
  231. 8:49physical addresses which are the
  232. 8:51physical addresses
  233. 8:53of things that are on the
  234. 8:58in the memory in the dram and the disk
  235. 9:03so there will be many processes
  236. 9:07and that are running um you know
  237. 9:10and many processor cores that are
  238. 9:11running independently
  239. 9:13supporting all running in the same
  240. 9:16virtual memory space
  241. 9:18and then there will be one main memory
  242. 9:20where our operating system and the
  243. 9:22virtual our virtual memory system is
  244. 9:24going to help us
  245. 9:25translate them to
  246. 9:28when we talk about the address spaces
  247. 9:31there are two types of address spaces
  248. 9:33that we see address space
  249. 9:35is a set of addresses for all available
  250. 9:37memory
  251. 9:38uh locations there are now two different
  252. 9:41address spaces one of them
  253. 9:43is the virtual address space the other
  254. 9:45one is the physical address space
  255. 9:48virtual other space is a set of
  256. 9:51addresses
  257. 9:52that the user program knows about
  258. 9:56physical address space is the one that
  259. 9:59exists
  260. 10:00in a particular computer that is set
  261. 10:03by the amount of dram and eventually
  262. 10:06disk
  263. 10:06that we may have users don't know
  264. 10:10programs don't know that
  265. 10:11that is one of the roles of the virtual
  266. 10:13memory system to hide that so that we
  267. 10:15can run programs in different
  268. 10:16configurations
  269. 10:18of of pcs for example
  270. 10:22and there is a memory manager manager
  271. 10:24that translates between these two spaces
  272. 10:27so when we talk about these two
  273. 10:29different address spaces
  274. 10:30they don't have to be exactly the same
  275. 10:33if you
  276. 10:33look at bora's laptop that you know i'm
  277. 10:35running this on
  278. 10:36you'll find out you know maybe a bit of
  279. 10:39a surprise but you'll see it's not
  280. 10:41really a surprise
  281. 10:42that they have 39 bits of physical
  282. 10:44addresses and 48 bits
  283. 10:46of virtual addresses so my virtual
  284. 10:49address space on this laptop is bigger
  285. 10:51than the physical space
  286. 10:54both of them are huge so it may not
  287. 10:56matter
  288. 10:57that much i think what you will find out
  289. 11:00if you run the same command on your
  290. 11:02uh ls cpu on on your laptop you'll find
  291. 11:05out what is it
  292. 11:05in your case it's usually going to be 39
  293. 11:08physical bits
  294. 11:10um if you have a xeon it may be 40.
  295. 11:13okay so when we talk a little bit about
  296. 11:17understanding differences in this
  297. 11:19translation from
  298. 11:21the virtual space to the physical space
  299. 11:25of addresses or virtual range of
  300. 11:27addresses the physical range of
  301. 11:28addresses
  302. 11:29there are some useful analogies that we
  303. 11:31can come up with
  304. 11:36and we can we have to think about you
  305. 11:39know it's like it's a really good
  306. 11:40analogy when we think about
  307. 11:41the libraries and how things work in a
  308. 11:44library
  309. 11:45um in a physical library with like
  310. 11:48library cards
  311. 11:49and library call numbers
  312. 11:52but you know that works also in a
  313. 11:54virtual world i'm just going to describe
  314. 11:56this
  315. 11:57assuming that we still actually go to
  316. 11:59the physical library where there are
  317. 12:01physical books
  318. 12:03the way what we can think about uh as a
  319. 12:06book title
  320. 12:07um it's like a virtual address for
  321. 12:10example our
  322. 12:11patterson and hennessy textbook may have
  323. 12:14different versions of it
  324. 12:15um you know there is a risk 5 version
  325. 12:18there is an
  326. 12:18armed version there are different
  327. 12:20editions and so on
  328. 12:23but the actual version that we are using
  329. 12:25in this book
  330. 12:26is unique in in this class the actual
  331. 12:28version that we're using in this class
  332. 12:30is unique
  333. 12:31um it has one unique number
  334. 12:34which is associated with this library of
  335. 12:36congress
  336. 12:37call number that is our physical address
  337. 12:42so if you want to go to a library and
  338. 12:44find that particular book
  339. 12:47there are these drawers with the
  340. 12:50cards in there and each card points to a
  341. 12:54particular location in the library where
  342. 12:56we can find that book on which kind of
  343. 12:58which shelf is it going to be so this
  344. 13:00card catalog
  345. 13:01is like a page table that
  346. 13:05maps from the book title because that's
  347. 13:07where we search by the author name or
  348. 13:09the title of a book
  349. 13:11to the actual call number that
  350. 13:12corresponds to this library of congress
  351. 13:15call numbers on
  352. 13:18this card when we pull it out in front
  353. 13:21of us
  354. 13:22in the library um in our local library
  355. 13:25is going to tell us on which shelf it is
  356. 13:27but in another branch but it may
  357. 13:31say that it is it exists in this library
  358. 13:34or it's another branch
  359. 13:35in some reserves somewhere uh where we
  360. 13:38would have to
  361. 13:40uh to to retrieve it from so that means
  362. 13:42it may be available
  363. 13:44locally like in the memory or maybe
  364. 13:48on a disk which is really what happens
  365. 13:50with the books that
  366. 13:51are much frequent much less frequently
  367. 13:54used and there is another important part
  368. 13:58of
  369. 13:58analogy that corresponds to the virtual
  370. 14:01memory
  371. 14:02systems it will tell us
  372. 14:05how much how long can we borrow that
  373. 14:08from so some of them may be restricted
  374. 14:11to be read within the library for two
  375. 14:13hours
  376. 14:14or some of them may be able to be
  377. 14:16checked out for two weeks or some of
  378. 14:18them may be
  379. 14:19available to be checked out for the
  380. 14:20semester that is what we are going to
  381. 14:22call the access rights
  382. 14:23i'm going to repeat this slide if it did
  383. 14:25not make too much sense
  384. 14:27and we're i'm going to repeat this slide
  385. 14:29slide
  386. 14:30a bit later when we really introduce the
  387. 14:33corresponding memory concepts
  388. 14:37so one final thing to recap here
  389. 14:41what is the role of the virtual memory
  390. 14:44and these requirements in supporting the
  391. 14:46memory hierarchy
  392. 14:48it is there that the whole system of
  393. 14:51translation is there to allow multiple
  394. 14:53processes to simultaneously occupy
  395. 14:56all of the memory or almost all of the
  396. 14:58memory and provide protection from each
  397. 15:00other
  398. 15:01we don't want somebody you know dan's
  399. 15:04program to run
  400. 15:05over mine and overwrite my data or
  401. 15:08overwrite my code
  402. 15:10um and
  403. 15:12it is really important because there are
  404. 15:15many many programs that are
  405. 15:17independently developed um and we do
  406. 15:20want to make sure that each one of them
  407. 15:22has at the time when it has a processor
  408. 15:25also an illusion that it has all
  409. 15:28of the memory available to itself
  410. 15:31so we're going to take a quick break
  411. 15:33here after a break we're going to talk
  412. 15:35about
  413. 15:36how does this physical memory dram
  414. 15:39and disk actually look like
  415. 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.