YouTube2Text

[CS61C FA20] Lecture 24.4 - Caches I: Locality, Design, Management — Transcript

by CS 61C Departmental · 2,778 words · 394 segments · language en · Watch on YouTube

Full transcript

  1. 0:00and welcome back
  2. 0:02as we think about how we would design
  3. 0:04our cache we still only have a very
  4. 0:05rough idea with what this thing is
  5. 0:07there are a lot of parameters to it
  6. 0:09there's some design parameters to it we
  7. 0:10understand what locality means and give
  8. 0:12you some new so a little bit a couple of
  9. 0:14dictionary words that we're going to be
  10. 0:15teaching you here
  11. 0:17and also understand how to manage this
  12. 0:19cache so let's actually dig deeper and
  13. 0:20try to build this an architect kind of
  14. 0:22specking it out like how would you spec
  15. 0:23this thing out that we're trying to
  16. 0:24build that gives that what we had the
  17. 0:26last lecture with which is you know this
  18. 0:28the speed of the smaller triangles at
  19. 0:30the at the size of the lower ones so um
  20. 0:32let's design some of these things
  21. 0:35so first thing first i think i won't say
  22. 0:38okay maybe i will say the fifth time
  23. 0:39copy caches always contain a copy of the
  24. 0:42lower levels said that um
  25. 0:45memory contains copies of disk we
  26. 0:46mentioned that before also
  27. 0:48here's a new here's the new words caches
  28. 0:51work on the principle of
  29. 0:53temporal
  30. 0:55and spatial locality
  31. 0:57temporal means time spatial means space
  32. 1:00the idea about temporarily says well if
  33. 1:03i used it
  34. 1:04recently if i just used it recently
  35. 1:05chances are i'll use it again
  36. 1:07pretty soon okay if you just use it at
  37. 1:10you know time t equals zero you use some
  38. 1:11piece of data
  39. 1:13chances are
  40. 1:14higher that you use that data again
  41. 1:16versus another random data i mean let's
  42. 1:18think about that that's useful and so
  43. 1:20that's the whole idea of having this
  44. 1:22recent called list if you called some
  45. 1:24number you're probably going to want
  46. 1:25that number in the future maybe not
  47. 1:26maybe not maybe it's a one-timer and
  48. 1:28that's true for data too it could be a
  49. 1:29one-timer but you know all things being
  50. 1:31equal
  51. 1:32it's nice to have a recent copy in case
  52. 1:34i happen to write something a couple
  53. 1:35times if i have a loop in the array
  54. 1:37guess what i'm hitting that array
  55. 1:38oftentimes it's nice to have that i'm
  56. 1:40calling you know i'm calling my plumber
  57. 1:42because he's never answered the phone
  58. 1:43it's nice to have his you know my
  59. 1:45plumber's number there
  60. 1:48spatial locality is about space it says
  61. 1:53if i access a particular place of memory
  62. 1:55but it acts as a place of memory
  63. 1:58boy it turns out that i don't just
  64. 2:00usually as a usual there's a lot of
  65. 2:02things are generalizations i usually
  66. 2:03don't randomly hit memory i'm actually
  67. 2:06going to mention at some point the worst
  68. 2:08thing you could do with a cache in which
  69. 2:10you actually are randomly hitting memory
  70. 2:13but let's say that's not that degenerate
  71. 2:15case most of the time i hit memory in a
  72. 2:17loop where i'm kind of processing
  73. 2:19through it and doing something so the
  74. 2:20chances are probably going to hit a
  75. 2:22neighbor at some point after that
  76. 2:24so that's the idea the idea is spatial
  77. 2:27locality says if you hit a memory
  78. 2:29location at some spot
  79. 2:31you're probably going to visit their
  80. 2:32neighbors at some point soon temporal
  81. 2:34locality says if i used any piece of
  82. 2:36data i probably will use it again it'd
  83. 2:37be nice to keep that local so i have it
  84. 2:39easy and and fast for future accesses
  85. 2:42that's the idea that's the pro principle
  86. 2:43of these two two guys
  87. 2:46so what that means for temporal locality
  88. 2:48is
  89. 2:49that's the by the way temporal locality
  90. 2:51is the entire idea of a cache it says
  91. 2:55have the thing that you just recently
  92. 2:57used
  93. 2:58well store that so if you just access
  94. 3:00somebody i literally have one memory
  95. 3:02access well remember it remember and
  96. 3:04keep it close to you in case you need it
  97. 3:05again that's what the tempo that's what
  98. 3:08the default behavior of a cache is
  99. 3:10always to have temporal locality it
  100. 3:12means i've got a copy so that i can use
  101. 3:13it again if i ever even if i have a
  102. 3:15recently called list of one that's still
  103. 3:18if i need to call that number again
  104. 3:19because they didn't pick up i've got it
  105. 3:20right there that's the idea so basically
  106. 3:22every cache unless there's some
  107. 3:24parameters we tweak i'll talk about
  108. 3:25later that don't have that every cache i
  109. 3:27have
  110. 3:28supports temporal locality it means i
  111. 3:30keep a copy so you can use the guy you
  112. 3:32just used in the future
  113. 3:35spatial locality says
  114. 3:37when you go out to get stuff from memory
  115. 3:40if i'm going to sacramento it's like
  116. 3:42if i were going to sacramento i had all
  117. 3:44these pieces of paper written down with
  118. 3:45all these other passwords there
  119. 3:47i might use another password soon if i
  120. 3:49maybe i'm changing my because i moved i
  121. 3:51have to change you know log into all my
  122. 3:53banks to ch to tell them all that i
  123. 3:54moved so if you're going to sacramento
  124. 3:57anyway
  125. 3:58how about bringing back some of the
  126. 3:59things from some other neighboring
  127. 4:01pieces of paper around when i was
  128. 4:03working on that paper with that password
  129. 4:05i probably was also changing my because
  130. 4:06maybe i got hacked or something so i
  131. 4:08have the other ones for this important
  132. 4:10banks around nearby grab the whole table
  133. 4:13i'm sure you've done this you've got to
  134. 4:14watch a sporting event like the super
  135. 4:16bowl and your friend says i'm going to
  136. 4:17the fridge you guys want anything yeah
  137. 4:19get me and so while you're going all the
  138. 4:21way to the fridge if you're going to go
  139. 4:23and make the effort get stuff you know
  140. 4:25grab me a couple of sparkling water not
  141. 4:28no i think good things you would have
  142. 4:29because people are under 21 and then you
  143. 4:31bring it back and you'd have the thing
  144. 4:33so if you're going anyway bring some
  145. 4:35neighboring stuff there that's what
  146. 4:36space locality is temporal says just
  147. 4:38have a most recently used one so i got
  148. 4:40it ready that's almost all caches
  149. 4:42basically every every cache and spatial
  150. 4:44says when you don't just grab one thing
  151. 4:46grab a couple of neighbors while you're
  152. 4:47there and there's some details while we
  153. 4:48do that that's the idea temporal and
  154. 4:50spatial locality two new words
  155. 4:52as we think about designing our cache
  156. 4:54again we're trying to spec this thing
  157. 4:55out we need to have this thing that
  158. 4:56operates at the speed of the small guy
  159. 4:58but at the size of the big guy and it's
  160. 5:00going to be a copy we have to ask
  161. 5:02ourselves well
  162. 5:04how do i know as i have these spaces
  163. 5:05these are let's let's say i have a
  164. 5:06recent call list okay i've got some
  165. 5:08spots i've got maybe 10 spots let's just
  166. 5:09make some easy simple numbers i've got
  167. 5:1110 spots
  168. 5:12um how do i know the original numbers i
  169. 5:15mean maybe i have the numbers but how do
  170. 5:16i know in memory where they originally
  171. 5:18came from so if i need to write to them
  172. 5:20i don't just have the numbers i need to
  173. 5:22be able to somehow
  174. 5:23access some so
  175. 5:25as i made a memory access i need people
  176. 5:26to know that no if i've got it in my
  177. 5:28recently called list it's here don't go
  178. 5:30there because i've got a copy of it use
  179. 5:32the one i've got that's really fast so i
  180. 5:34somehow need to store
  181. 5:35where i grabbed it from if you think
  182. 5:37about this and then how i remember that
  183. 5:39somehow so part of it is where did it
  184. 5:40come from if i grabbed it from that part
  185. 5:42of memory and here's the copy of it well
  186. 5:44how do i know when i go it again the
  187. 5:45system needs to know oh if you're going
  188. 5:46for the same spot i got it first already
  189. 5:48so how do you tell the system and how do
  190. 5:50you remember that
  191. 5:51um
  192. 5:52overall how do you know what's in the
  193. 5:53cache
  194. 5:54how do you
  195. 5:56if bits are just bits how do i know if
  196. 5:57these bits were random garbage bits
  197. 6:00remember we talked about something
  198. 6:02like an array being initialized to
  199. 6:04garbage well if i don't know it i don't
  200. 6:05know if those are if the garbage is data
  201. 6:08that's good or garbage is there a
  202. 6:09sentinel value i reset everything to
  203. 6:11okay reset the thing give it some
  204. 6:13sentinel value and that i'll know if
  205. 6:15it's the sentinel that is some
  206. 6:18characteristic value that i'm going to
  207. 6:20have no good value would have this value
  208. 6:21so i reset it to the sentinel value and
  209. 6:23i'll know like negative one or something
  210. 6:25if it's all positive numbers or
  211. 6:26something if it's an int and i'll say
  212. 6:28okay set the whole array to negative one
  213. 6:30that way i'll know if i've set you know
  214. 6:31if i stored something there or not so
  215. 6:33how am i using it to know which elements
  216. 6:35are in which elements are not which
  217. 6:36which are blank i haven't sorted
  218. 6:38anything there
  219. 6:39and how do i quickly get them how do i
  220. 6:40have to drop to like linearly search
  221. 6:42like how crazy would that be is it this
  222. 6:44one no this one is there a faster way to
  223. 6:46quickly get to it so i want to be able
  224. 6:48to get to it know what's there and then
  225. 6:50know where it came from that's kind of
  226. 6:51what we're talking about in our cache
  227. 6:52design kind of a fun space i almost
  228. 6:55i think
  229. 6:56this is just me reflecting on this i
  230. 6:58think it would have been fun to have
  231. 6:59this lecture where i stopped now and i
  232. 7:02send all the 61 students away for a week
  233. 7:04and they design caches because i bet you
  234. 7:06nine times out of ten you'd come up with
  235. 7:08whatever design i'm gonna teach you in
  236. 7:09the next thing so it's i'm kind of
  237. 7:11giving away the opportunity for this
  238. 7:13design challenge for people to come up
  239. 7:14with a new invention of how caches might
  240. 7:16work that might be more clever than the
  241. 7:18way they currently work so
  242. 7:20unfortunately i'm just going to tell you
  243. 7:21how we do it but there's an interesting
  244. 7:23space to allow you to just pause it so
  245. 7:24if you're watching this video pause it
  246. 7:26and then talk to your friends about
  247. 7:27let's if you didn't read a head in the
  248. 7:28book where you got the answer there try
  249. 7:30to design this thing what would it mean
  250. 7:32to have memory and then have this copy
  251. 7:34to know where it came from know what the
  252. 7:37values are here what they're initialized
  253. 7:38to know what's in it totally and then
  254. 7:40know how to how to find it in there so
  255. 7:42think about some design for that it'd be
  256. 7:44kind of fun to think about it faster
  257. 7:45maybe you can do a log search for it
  258. 7:47maybe it's even faster than that so
  259. 7:49think about how to design this to be
  260. 7:50able to have those all be fast and all
  261. 7:52be clear answers to these questions here
  262. 7:54nice right
  263. 7:56so
  264. 7:56here's the answer come now positive i
  265. 7:58could now unpause the video and come
  266. 7:59back uh no i'm not going to give away
  267. 8:01that i think i'm waiting a couple of
  268. 8:02slides
  269. 8:04this is just how we generally manage
  270. 8:05these high these levels of the hierarchy
  271. 8:07registers to memory
  272. 8:09how do we manage
  273. 8:11what how data moves between or how the
  274. 8:13copies of the data come from memory and
  275. 8:15go to registers you've done this already
  276. 8:17you know this answer
  277. 8:18the compiler does the work right you're
  278. 8:20either hand authoring risk 5 code or you
  279. 8:23write c which moves down to the compiler
  280. 8:26authoring the risk drive code for you
  281. 8:27but you know the load the loaf the the
  282. 8:31uh the load and stores that's how you
  283. 8:33move things in and out
  284. 8:35you wrote that right either the compile
  285. 8:36either wrote it because you did a memory
  286. 8:38access and that became risk five code or
  287. 8:40you hand authored it so you're doing the
  288. 8:41compiler does that so that's how that
  289. 8:43works how about cache to main memory do
  290. 8:45you have to manage that yourself
  291. 8:47actually here's what's cool
  292. 8:49don't need to worry about that at all
  293. 8:50that's handled by the system the cache
  294. 8:52controller does that for you that's neat
  295. 8:54so you can add this whole layer and not
  296. 8:57have to physically think about it it
  297. 8:59means the same program you had before
  298. 9:01if i have a machine with no cache just
  299. 9:03runs a lot slower
  300. 9:05if i add a cache i don't to change the
  301. 9:07program this is a big idea no need to
  302. 9:10change a program to to add this layer of
  303. 9:12the cache i change the system the system
  304. 9:14now manages it and works it all itself
  305. 9:16but the hardware does it for you now if
  306. 9:17you're going to be a hardware designer
  307. 9:19that's when you have to do it so think
  308. 9:20about taking upper division classes to
  309. 9:22learn how to make the make that work but
  310. 9:23that's kind of neat you don't worry
  311. 9:24about it from the programmer's point of
  312. 9:25view
  313. 9:27how about main memory to disk
  314. 9:30beautiful thing is that's not even
  315. 9:32managed by you either that's managed by
  316. 9:34the os and we'll learn about that when
  317. 9:35we get to virtual memory so save that
  318. 9:37for later but that's kind of neat now
  319. 9:39you could say well dan no i had a chance
  320. 9:42because when i was writing my program i
  321. 9:44could write a file or not yes
  322. 9:47you're right you explicitly could write
  323. 9:49your array to a file and read it from a
  324. 9:51file so you could still do it by the
  325. 9:52programmer's point of view but in terms
  326. 9:54of
  327. 9:55how the virtual memory pages which you
  328. 9:57don't know what that means yet work
  329. 9:59that's done by the os and we'll get to
  330. 10:00that we'll talk about virtual memory but
  331. 10:02there is some movement i'll give you a
  332. 10:03little i'll like see this conversation
  333. 10:06there is some movement from of data from
  334. 10:09memory to disk
  335. 10:11in and out of disk and that's like going
  336. 10:13past sacramento to even farther away
  337. 10:15we'll talk about that when we get to
  338. 10:16that but that is done by the os and
  339. 10:19again you learn more about 162 and we'll
  340. 10:20teach you a little bit more about it
  341. 10:21when we get to the vm lectures okay
  342. 10:24so here's the idea cache domain memory
  343. 10:26is the cache controller hardware
  344. 10:29and by the way there's some part of vm
  345. 10:30which is also kind of a cache
  346. 10:32but you don't even know what that word
  347. 10:33means and so we'll just skip that for
  348. 10:34now but come back to this slide when you
  349. 10:36learn from me like oh well you know what
  350. 10:37this thing called the tlb that's a cache
  351. 10:40too so we'll figure out what that is
  352. 10:41later
  353. 10:43so in conclusion this is again still
  354. 10:44setting these things up we're setting
  355. 10:46the design space for the future
  356. 10:48caches provide this remarkable illusion
  357. 10:50this more abstract i like abstraction
  358. 10:52better than illusion but i'll take it
  359. 10:53i'll take you the one
  360. 10:54it's an abstraction that lets you think
  361. 10:56like an illusion let's do the i did that
  362. 10:59both lets you think about
  363. 11:01accessing data at the speed of
  364. 11:04much things a speed of something much
  365. 11:06faster than memory but at the size of
  366. 11:08memory so all of a sudden memory card
  367. 11:09basically abstractly memory got faster
  368. 11:12that's pretty cool so i'm going to be
  369. 11:14right reading and writing memory and all
  370. 11:15of a sudden the reading rights are what
  371. 11:17this computer's way it's just sprightly
  372. 11:19today yeah because they added a cache
  373. 11:20overnight oh but you don't need to worry
  374. 11:22about program doesn't worry about it but
  375. 11:23all of a sudden i get much faster access
  376. 11:25to memory and we can talk about even how
  377. 11:28later how to write our code to optimize
  378. 11:30for the cache that's a whole nother
  379. 11:31conversation and a very rich
  380. 11:33conversation how to if i knew there was
  381. 11:35a cache what would i do differently from
  382. 11:36a programmer ah yes
  383. 11:38sometimes you can peek below the hood
  384. 11:40and see what hardware i'm running on to
  385. 11:42then change your code to optimize for
  386. 11:43that that's actually what's called
  387. 11:45optimization is called optimization is
  388. 11:46often how do i lift lift the hood up oh
  389. 11:48that's what hardware running okay put
  390. 11:50the hood back down now i'll change my
  391. 11:51code same does the same thing it just
  392. 11:53does it in a different way to optimize
  393. 11:55for the cash we'll talk all about that
  394. 11:56later okay see the next lecture thanks

About this transcript

This page contains the full transcript of [CS61C FA20] Lecture 24.4 - Caches I: Locality, Design, Management by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 2,778 words across 394 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.