YouTube2Text

[CS61C FA20] Lecture 24.3 - Caches I: Memory Hierarchy — Transcript

by CS 61C Departmental · 3,539 words · 567 segments · language en · Watch on YouTube

Full transcript

  1. 0:00and welcome back in this series of
  2. 0:02slides
  3. 0:04we're going to take a look at what we
  4. 0:06understood the memory hierarchy to be
  5. 0:07which before was just i got registers in
  6. 0:10memory
  7. 0:10are there more elements that we were
  8. 0:12hiding from you in terms that we were so
  9. 0:13we're going to reveal
  10. 0:14kind of some of the layers of the onion
  11. 0:16to you in this set of lectures
  12. 0:18so again let's go back to our library
  13. 0:19analogy i'm writing a report
  14. 0:21using the library books i'm going to the
  15. 0:22stacks it's uh
  16. 0:24some english class it's i'm freshmen and
  17. 0:27i've got to report the works of jd
  18. 0:28salinger
  19. 0:30so i could go to the library what i
  20. 0:32probably do by the way what i probably
  21. 0:33do
  22. 0:34is i go to the library i look up the
  23. 0:35books i fetch
  24. 0:37all of the books from the stacks i have
  25. 0:39a stack you know everybody sees that the
  26. 0:40picture of people walking back after the
  27. 0:42collector all the books they're supposed
  28. 0:43to get
  29. 0:44and then i'll find a desk in the library
  30. 0:46near enough that if i need to go back
  31. 0:47it's not too far
  32. 0:49and then what i'll do is i'll open all
  33. 0:51the books and i'll have them all open on
  34. 0:53my table and i'll be able to reference
  35. 0:54this book
  36. 0:55you've probably seen this you've
  37. 0:56probably seen your classmates have that
  38. 0:57well you have the books all around the
  39. 0:58table
  40. 0:59and you're kind of up you're writing
  41. 1:00you're writing a report on jd salinger
  42. 1:02yep
  43. 1:03i remember writing that last year yep
  44. 1:04thanks so much that kind of thing you're
  45. 1:05having no conversations with your
  46. 1:06friends
  47. 1:08now if you need more you go check them
  48. 1:10out now you check them out until
  49. 1:12your desk kind of gets full and maybe
  50. 1:14they say you know sorry you can't stack
  51. 1:16the books or something so
  52. 1:17maybe there's a limit so then you have
  53. 1:18to put some of those books back and you
  54. 1:19have
  55. 1:20kind of a working set in a way like you
  56. 1:22have a working set of
  57. 1:23books that are all laid out there if
  58. 1:25they don't let you because they're
  59. 1:26damaged to the books that means you
  60. 1:28can't stack the books up so you have a
  61. 1:30certain fixed limit as for a certain
  62. 1:32size on your desk
  63. 1:33but you're able to really save a lot of
  64. 1:35time imagine
  65. 1:36if i were to make much smaller desks how
  66. 1:38much more painful that would be for you
  67. 1:40to only have one or two books and i have
  68. 1:41to
  69. 1:42keep running back and forth to the
  70. 1:43stacks so actually we like the idea of
  71. 1:44having a really large desk
  72. 1:46i can open more of these things i
  73. 1:47actually like the idea that they can let
  74. 1:48me stack them but let's say i couldn't
  75. 1:50do that
  76. 1:50so this idea this analogy of
  77. 1:54maybe that the 10 books that i have on
  78. 1:56the desk are enough
  79. 1:57to cover most of what i need in the rare
  80. 2:00case i need an 11th or 12th book i'll be
  81. 2:02able to do that
  82. 2:03but but for the most part my working set
  83. 2:05of books that i have working set of data
  84. 2:07that i have
  85. 2:08is able to be very very efficient and
  86. 2:09the time to reach it is
  87. 2:11got it that's how fast it took me to
  88. 2:12grab something rather than get up go
  89. 2:14look it up again go find it walk
  90. 2:16walk the stacks come back get it and
  91. 2:18bring it back and do the same
  92. 2:19that would be painful so this distance
  93. 2:21the time ready one two three
  94. 2:23grabbing it and that was about a second
  95. 2:25to grab the book and open it up
  96. 2:26that was great we like that we like the
  97. 2:28idea of having stuff that we're going to
  98. 2:29use often
  99. 2:30close to us and that's a great analogy
  100. 2:32it's close to us and that close to us
  101. 2:34physically but close to us in time as
  102. 2:35well
  103. 2:36it's great stuff that's the idea
  104. 2:39memory caching is exactly the same idea
  105. 2:41that
  106. 2:42that desk is in a way a local
  107. 2:46it's a very fast to access but smaller
  108. 2:50certainly not smaller than all the books
  109. 2:51in the library smaller
  110. 2:53collection of the data that i'm going to
  111. 2:55be using and so
  112. 2:57based on the idea that these the you
  113. 2:59know the cpu versus dram speed curve
  114. 3:02just got larger and larger that was
  115. 3:03crazy we don't want that
  116. 3:05we're going to introduce the idea of a
  117. 3:07memory cache and this is by the way
  118. 3:09a big idea in computer science if you
  119. 3:11talk about computational thinking
  120. 3:13and in fact i'm on some national
  121. 3:15committees to talk about computational
  122. 3:16thinking
  123. 3:18and my perspective what computational
  124. 3:19thinking is it's thinking like a
  125. 3:21computer scientist it's thinking
  126. 3:22of the world in a lens in the glasses
  127. 3:25that computer scientists
  128. 3:26all walk around with all the time and
  129. 3:29caching is one of those big ideas
  130. 3:32i have it on my phone you have a
  131. 3:33favorites list you have a recently
  132. 3:35called list favorites is where you get
  133. 3:36to specify what's it what's in your
  134. 3:38faster access but the recently called
  135. 3:40list if it only shows 10
  136. 3:42that is in a way recently called it's
  137. 3:44exactly the idea of what we're talking
  138. 3:46about here it's like the recently used
  139. 3:47books that i had
  140. 3:49so typically the way we implement we're
  141. 3:52going to build these caches are going to
  142. 3:54be done with the same ic technology the
  143. 3:56same processing technology as the cpus
  144. 3:58and even sometimes on the same chip
  145. 4:00that's great
  146. 4:01same chip really the farther even
  147. 4:04physically the farther you go from the
  148. 4:05cpu from the registers
  149. 4:07the farther you go physically and
  150. 4:08distance the slower it's going to be to
  151. 4:10get there
  152. 4:10probably the bigger you're going to have
  153. 4:11but the slower it's going to be to get
  154. 4:12there i've got my hard drive
  155. 4:14with a long cable across the room i got
  156. 4:15a network of computers
  157. 4:17in the cloud all those things farther
  158. 4:19away larger but
  159. 4:20really small and fast so you want to
  160. 4:23have
  161. 4:24the caches be on chip if you can if you
  162. 4:27can do that you get great speed
  163. 4:29the important idea boy we put it in
  164. 4:31yellow here and i can't emphasize it
  165. 4:32enough
  166. 4:34a cache and this is by the way with the
  167. 4:36library analogy falls down
  168. 4:38i grabbed the single copy of the book
  169. 4:39and now it's on my table so it wasn't
  170. 4:40there but in digital versions
  171. 4:42it's not like one version of those bits
  172. 4:44so i the cache is always
  173. 4:47a copy a subset of what memory had
  174. 4:49memory has
  175. 4:50in a way the reference copy the
  176. 4:53reference values
  177. 4:54and the cash is always a copy it's
  178. 4:57always a copy in fact for the first
  179. 4:58couple of lectures we're going to talk
  180. 4:59about
  181. 4:59cash reads where i'm only reading values
  182. 5:02only when you have storage do you have
  183. 5:03conversations of
  184. 5:04keeping the copy consistent so for now
  185. 5:06just think they're always consistent
  186. 5:07until i tell you otherwise
  187. 5:09and i'm only ever reading from a cache
  188. 5:10just to just for now let's make it easy
  189. 5:12okay
  190. 5:13important so say this to yourself cache
  191. 5:15is a subset and it's a copy of what was
  192. 5:18in memory that's the important idea
  193. 5:20and by the way this is also something
  194. 5:22we're going to see when i show you
  195. 5:23pictures of the cpu later
  196. 5:25most processors actually separate caches
  197. 5:28for instructions and data
  198. 5:30you remember in the place where code
  199. 5:32lived instructions were down here
  200. 5:34and data was up here right you know
  201. 5:36whether the data is static
  202. 5:37you know growing up from the heap or
  203. 5:39going down from the stack
  204. 5:40that's still a different place than the
  205. 5:42instructions
  206. 5:44so rather than kind of corrupt them
  207. 5:47and put them all in one place it
  208. 5:48actually makes a little bit more sense
  209. 5:49to have separate caches
  210. 5:50for only instructions which are all the
  211. 5:52stuff down here and the data which
  212. 5:54all could be a large group of you know
  213. 5:56data could come from a large
  214. 5:58range of memory addresses where the
  215. 6:00restrictions probably come from smaller
  216. 6:02but separating them actually keeps it
  217. 6:03more clean it's kind of interesting so
  218. 6:04think about having two caches at least
  219. 6:06an instruction and a data cache
  220. 6:08pretty cool this is the picture this is
  221. 6:11the picture memory hierarchy that you've
  222. 6:13seen
  223. 6:13up till now you got a cpu the core is
  224. 6:15there the fastest
  225. 6:17smallest fastest and most expensive
  226. 6:20storage there are registers they're
  227. 6:22amazingly fast blisteringly speeds
  228. 6:25but they're really small not that many
  229. 6:26of them and they're really close to the
  230. 6:28cpu so i can get to them an easily one
  231. 6:30clock cycle
  232. 6:31fractions usually have a clock cycle
  233. 6:33farther away and down in this triangle
  234. 6:36is physical memory the dram chip when
  235. 6:39you say i want to upgrade the memory
  236. 6:40you're talking about that the dram is
  237. 6:42the dynamic ram
  238. 6:43and dynamic means you have to refresh it
  239. 6:45uh that's the dynamic means
  240. 6:46you have to actually keep pinging it hey
  241. 6:48remember that was a one remember it was
  242. 6:49a zero you got to keep refreshing it
  243. 6:51so that's why it's called dynamic ram
  244. 6:53versus static range but you don't want
  245. 6:54to do that
  246. 6:55and reasonably fast um
  247. 6:59but price more reasonably then boy every
  248. 7:01bit for registers cost a lot
  249. 7:03um those are farther away you know i go
  250. 7:05to fry's electronics if that still
  251. 7:07exists anymore and i buy up
  252. 7:08you know some dims and i plug them in um
  253. 7:12dual input memory module so you could
  254. 7:14have
  255. 7:15um a larger space because they're
  256. 7:17external i can now swap them in and out
  257. 7:19which is great that's nice sometimes
  258. 7:20they
  259. 7:20burn on the board and you can't move
  260. 7:22them but most of the time you can you
  261. 7:23know most desktop computers you can swap
  262. 7:24a minimum out
  263. 7:25and increase by the way if you want to
  264. 7:27make your computer run faster
  265. 7:28you're going to learn this when you
  266. 7:29learn about vm a virtual memory
  267. 7:32buy more memory so talking about
  268. 7:34swapping it in and out
  269. 7:36are you ready for this revealing the
  270. 7:37layer of the onion the layer of the
  271. 7:39onion
  272. 7:40we're going to put caches in the middle
  273. 7:43and they're typically a different
  274. 7:44process they're not going to be
  275. 7:45sometimes it could be on the cpu which
  276. 7:46is great
  277. 7:47uh on the on the same core on the same
  278. 7:49chip
  279. 7:50as the cpu um they are
  280. 7:53as they're shown in this triangle it's a
  281. 7:54beautiful triangle it's consistent and
  282. 7:56by the way
  283. 7:56if ever you come with a technology that
  284. 7:58is kind of out of place
  285. 8:00it will the market will sort it out
  286. 8:02meaning well what if i had this if this
  287. 8:04could be bigger than memory what if this
  288. 8:05could actually be bigger than memory
  289. 8:07without it without being slowing it down
  290. 8:08well then it would move down there and
  291. 8:10memory would be above it like it
  292. 8:11actually will the market will move
  293. 8:12things around to
  294. 8:13automate that it's really interesting um
  295. 8:15so it is a three
  296. 8:16of three of the three parameters of this
  297. 8:18it is faster than memory but slower than
  298. 8:21registers
  299. 8:22it is more expensive cheaper it is more
  300. 8:25expensive than memory
  301. 8:26but less expensive than registers same
  302. 8:29thing
  303. 8:30and it's larger it's smaller
  304. 8:33remember the triangle it's smaller than
  305. 8:35memory uh but
  306. 8:37larger than the registers above it so
  307. 8:39those three parameters
  308. 8:41it fits right in the middle of all those
  309. 8:42three parameters
  310. 8:45jim gray was a berkeley alumnus he got
  311. 8:48his bachelor's in phd at berkeley
  312. 8:51he came up with this beautiful analogy
  313. 8:54thinking about
  314. 8:55if you had a fact or a piece of paper
  315. 8:57with like a secret thing on it like a
  316. 8:59password or something you need to get it
  317. 9:01how long would it take and making
  318. 9:02analogy so people could again that was a
  319. 9:04library analogy now what if you actually
  320. 9:06had
  321. 9:06the same idea but in terms of relative
  322. 9:09speed to
  323. 9:10how long it would take to get to
  324. 9:11something so registers the
  325. 9:13model that you've seen before is
  326. 9:16registers
  327. 9:17i can get to you know insta as fast as i
  328. 9:19can
  329. 9:20about a minute if you say register is a
  330. 9:21minute even though it's like one
  331. 9:22nanosecond one clock cycle
  332. 9:24um for one gigahertz clock is one
  333. 9:26nanosecond so imagine
  334. 9:28if the analogy in a physical piece paper
  335. 9:30is about a minute to get something
  336. 9:31i'm thinking what was that number again
  337. 9:33okay i got it okay that's about a minute
  338. 9:35now memory the equivalent time
  339. 9:39for how long it would take you to get
  340. 9:40something from memory
  341. 9:42we're going to talk about something in
  342. 9:43the hundreds to maybe even a thousand
  343. 9:46times
  344. 9:47that speed usually it's a several
  345. 9:48hundreds times that so what's several
  346. 9:50hundred
  347. 9:51minutes well we're talking about a trip
  348. 9:54to sacramento
  349. 9:54so that means you left a piece of paper
  350. 9:56how annoying would that be
  351. 9:58in sacramento and you gotta go grab that
  352. 9:59that would be just terrible
  353. 10:01and that maybe it's a book you're
  354. 10:02talking about maybe it's a piece of
  355. 10:03paper with a password on it
  356. 10:05caches are like in the middle right in
  357. 10:08the middle of that
  358. 10:08triangle that memory hierarchy so the
  359. 10:11analogy there is
  360. 10:12it's like it's in this room somewhere oh
  361. 10:13it's in the room okay i'll find it
  362. 10:15did i leave it under that no it's not
  363. 10:16under that under the plate knows
  364. 10:18but searching the room isn't too bad
  365. 10:20it's about two minutes so we love
  366. 10:22caches they are bigger than registers
  367. 10:24remember register's only a few of them
  368. 10:26now they're bigger than registers but
  369. 10:28they're about the same speed as
  370. 10:30registers you know they're not that far
  371. 10:31away in terms of distance at least
  372. 10:32the closest cache we're gonna learn
  373. 10:33there's more than one cache but just for
  374. 10:35now
  375. 10:36that's pretty cool to be able to have
  376. 10:37something that's much larger than
  377. 10:38registers but
  378. 10:39just about as fast as them a little
  379. 10:41slower but not that bad maybe one or two
  380. 10:43clock cycles that's great
  381. 10:45so we love this we love this analogy and
  382. 10:47we're going to actually see the things
  383. 10:48way above sacramento as we expect to go
  384. 10:50to disk
  385. 10:51how far is disk away you're going to see
  386. 10:53be surprised how far disc away
  387. 10:55disc is away in this analogy in terms of
  388. 10:57how long it takes for
  389. 10:58how many clock cycles would it take to
  390. 11:00go to disk
  391. 11:01so again i think i mentioned before in
  392. 11:03my other memory hierarchy but as we look
  393. 11:05at this triangle here are some of the
  394. 11:06parameters about this i think i might
  395. 11:08have said this
  396. 11:09as you get farther away as you get
  397. 11:11farther away from the processor
  398. 11:13you end up having increased access time
  399. 11:16okay
  400. 11:16so you're going to be slower it's just
  401. 11:19slower to go farther away from the cpu
  402. 11:21okay and what i mean is it's not just
  403. 11:23like it's the same speed but farther
  404. 11:24kind of
  405. 11:25like in the library analogy just farther
  406. 11:27distance no you're going to different
  407. 11:28technologies so it actually
  408. 11:29kind of it's like walking through
  409. 11:30quicksand and then walking through
  410. 11:31quicksand with
  411. 11:32with a big weight behind you and then
  412. 11:33walking through so it gets slower and
  413. 11:35slower the farther you go
  414. 11:36you get to different processes and you
  415. 11:37end up having different speeds
  416. 11:39as you get there that's not just the
  417. 11:41same speed but farther
  418. 11:43also the relative size of memory each
  419. 11:45level gets larger so as i move away from
  420. 11:47the processor i get bigger and bigger
  421. 11:49so i have caches is smaller than memory
  422. 11:51uh and we call memory and secondary
  423. 11:53memory here but
  424. 11:54so cache remember secondary memory which
  425. 11:56might be disks so second remember we
  426. 11:58often call disks
  427. 11:59which might be flash based or might be
  428. 12:01of spinning spinning
  429. 12:02uh cylinders however we decide that's
  430. 12:05what we call secondary memory and
  431. 12:07if we include that in this conversation
  432. 12:09the farther you get away from the cpu
  433. 12:10it's
  434. 12:10still consistent it is slower access
  435. 12:13time
  436. 12:14larger but we didn't mention here it's
  437. 12:17cheaper another factor here it's much
  438. 12:20cheaper the farther you go away
  439. 12:21so the price for a single bit on disk
  440. 12:24man
  441. 12:25nothing price for a single bit in memory
  442. 12:28still pretty good
  443. 12:29price for a single bit in cash whoo
  444. 12:30price for a single bit on the register
  445. 12:32boy that's pretty expensive expensive so
  446. 12:34i mean even in today's dollars that's
  447. 12:35pretty expensive thinking about what a
  448. 12:36single bit costs
  449. 12:37relative to a single bit on a disk drive
  450. 12:39interesting okay
  451. 12:41the other important thing is always it's
  452. 12:42the inclusivity it's always a subset the
  453. 12:45smaller is
  454. 12:46always a copy of the larger and every
  455. 12:48single one of the every single layer
  456. 12:49from the
  457. 12:50from the from the processor working on
  458. 12:52something right now it's
  459. 12:53computing something right now to the
  460. 12:54registers which is more set but the
  461. 12:56factory processors i had some data that
  462. 12:58flowing under the path i'm working on
  463. 12:59two numbers
  464. 13:00okay that's really okay smaller um
  465. 13:03and a copy of what was in the registers
  466. 13:05a copy of what's in my cache
  467. 13:07copy what's in memory and a copy in some
  468. 13:09sense of what's in disk
  469. 13:10remember what the loader does the loader
  470. 13:12grabs remember that
  471. 13:14it grabs from disk it loads into memory
  472. 13:17remembers then a copy of what was on
  473. 13:18disk
  474. 13:18same idea pretty cool right okay
  475. 13:25so the trick here's the whole the whole
  476. 13:28beauty it's a little longer
  477. 13:29video but this is the beauty of this
  478. 13:30idea
  479. 13:32the beauty is this abstraction
  480. 13:35abstraction is the key idea in this
  481. 13:37whole course it's the abstraction
  482. 13:40that you're living at forget the cost
  483. 13:41for a moment okay but you're living
  484. 13:43at the speed of the smaller guy but at
  485. 13:47the size of the bigger guy
  486. 13:48that's it that's the big idea it's like
  487. 13:51having
  488. 13:52imagine like having i don't know the
  489. 13:54disk available to you
  490. 13:55at the speed of registers that's the
  491. 13:57idea and the idea of caches is what if
  492. 13:59you had all of main memory
  493. 14:01which was big but at the speed of a
  494. 14:04process that
  495. 14:05in some sense the registers but you know
  496. 14:06something faster than that the speed of
  497. 14:08it's really the speed of the cache but
  498. 14:09what if you had access to all the memory
  499. 14:11at the speed of the cache it's not
  500. 14:12registered but it's pretty close that's
  501. 14:14the idea so every
  502. 14:15this whole beautiful idea look at the
  503. 14:17numbers here so
  504. 14:18the speed in cycles i think i want to
  505. 14:20circle some of these things so you know
  506. 14:22how fast is it to get to the reg file uh
  507. 14:24you know
  508. 14:25half half a half of a clock cycle
  509. 14:29well how about to get to the you know
  510. 14:31the caches about ones you know the
  511. 14:33single digits
  512. 14:34of clock cycles to get to the cache well
  513. 14:36how about main memory you know we talked
  514. 14:37about this you know about a thousand ish
  515. 14:39that's sacramento how about disc boy you
  516. 14:42don't even know how bad how far away
  517. 14:44this is okay and this is the size you
  518. 14:46know the highest is the highest cost in
  519. 14:48the small guy and the lowest cost here
  520. 14:50and the size is roughly
  521. 14:51like that and determine well how big do
  522. 14:53you mean this triangle what's the width
  523. 14:54of that triangle
  524. 14:55you know in the order of a hundreds you
  525. 14:58know they had 32
  526. 14:59registers something small in the order
  527. 15:01of like 10 000 ish
  528. 15:03for caches you know memory you know what
  529. 15:05size memory is memory is in the gibby
  530. 15:07usually some several gibby and disc is
  531. 15:09typical in the tubby so
  532. 15:10it's interesting to see what the width
  533. 15:12is typically for
  534. 15:13for computers and technology uh today
  535. 15:16and that number is changing every year
  536. 15:20so those are the on-chip components the
  537. 15:21things that are on ship are
  538. 15:23the cache that's the idea so some part
  539. 15:24of the cache is on chip and that's just
  540. 15:26that's just great
  541. 15:28so summary of the whole idea if the
  542. 15:30level is close to the process the higher
  543. 15:32up you get in that triangle the memory
  544. 15:33hierarchy it is smaller
  545. 15:35faster and more expensive per bit that's
  546. 15:37clear and also the important thing is a
  547. 15:39subset of the lower levels i think i
  548. 15:40said that four times now i want to make
  549. 15:42sure that you don't
  550. 15:43get that question wrong on the exam it's
  551. 15:45always a subset of copy of the lower
  552. 15:46levels
  553. 15:47um and the idea of the memory harkey is
  554. 15:50the illusion it's the
  555. 15:53and illusion woody allen has a line that
  556. 15:54says uh i put some backlights but
  557. 15:56i have backlights here in my studio i
  558. 15:58put some backlights behind me to give me
  559. 16:00to give me the illusion of three
  560. 16:01dimensions
  561. 16:02so same idea the idea here is
  562. 16:06in this hierarchy i have the illusion of
  563. 16:09the size of the lower levels at the
  564. 16:11speed of the upper levels that's it
  565. 16:12that's it that's the big idea we'll talk
  566. 16:14about how to actually make this work the
  567. 16:15next lectures we'll see you there

About this transcript

This page contains the full transcript of [CS61C FA20] Lecture 24.3 - Caches I: Memory Hierarchy by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 3,539 words across 567 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.