YouTube2Text

[CS61C FA20] Lecture 26.2 - Caches III: Writes, Block Sizes, Misses — Transcript

by CS 61C Departmental · 5,364 words · 842 segments · language en · Watch on YouTube

Full transcript

  1. 0:00and welcome back now we're going to
  2. 0:02reveal some layers of the onion
  3. 0:04we kind of were living in a rubber room
  4. 0:06for a while now we're going to realize
  5. 0:08that it's
  6. 0:08a little sharper and there's some more
  7. 0:10details behind this so let's think about
  8. 0:11how to handle rights for
  9. 0:13up to now we've only been reading we now
  10. 0:15we were reading words
  11. 0:16more than just bytes in beginning we're
  12. 0:17just reading bytes now reading words now
  13. 0:19how about writes what happens there what
  14. 0:21about block sizes and what happens when
  15. 0:23we have misses
  16. 0:24let's talk about all those elements near
  17. 0:25and now and get some more details
  18. 0:28so this is a beautiful picture of a
  19. 0:30multi-word
  20. 0:31uh multi-word block multi-word block so
  21. 0:35it's a block that's more more than just
  22. 0:36one word
  23. 0:37um direct map cache i've got here
  24. 0:42let's make let's actually make four
  25. 0:44words a block okay so four words so the
  26. 0:46block size is going to be
  27. 0:48like before four words are blocked um
  28. 0:50the cash size is going to be
  29. 0:524k words this is the same as before we
  30. 0:54saw this exact picture before 4k words
  31. 0:56or
  32. 0:5716k bytes all that's the same we saw the
  33. 1:00way we can think about our our ti and oh
  34. 1:02and divide them up
  35. 1:02and we saw the picture here in in the
  36. 1:05cache and the data is on the right side
  37. 1:07got a valid tag and i've got 10 10 24
  38. 1:10different rows
  39. 1:11so here is what happens we start
  40. 1:15by looking at the index and next tells
  41. 1:17how much row i'm in
  42. 1:18the row first i check my valid and i
  43. 1:21check my tag and so the tag comes out
  44. 1:22and my valid comes out of there
  45. 1:25so when my when i am valid and when my
  46. 1:28tag equal is equal
  47. 1:30i grab that particular
  48. 1:33word out of this and that let's actually
  49. 1:35look at some details here as i look at
  50. 1:37this
  51. 1:38here's what's actually quite interesting
  52. 1:41i only have a hit when do i have a hit
  53. 1:45you have a hit when you just you could
  54. 1:47think of the logic already when
  55. 1:49the valid bit is on there's a one there
  56. 1:52and the tag matches
  57. 1:53so i take my 18 bits of the tag compare
  58. 1:56with the 18 bits
  59. 1:57of the tag that's stored in that row and
  60. 2:00that block
  61. 2:01and well this is the block but in the in
  62. 2:02that row and i do a comparison there's
  63. 2:05an
  64. 2:05equal sign there so that means you just
  65. 2:07compare like they're if they're the same
  66. 2:08there's a one at the output of that box
  67. 2:10if they're not the same as the zero
  68. 2:12and only when i am that with the valid
  69. 2:15bit so only when it's valid and they're
  70. 2:17equal do i have a hit
  71. 2:18so that's already kind of interesting
  72. 2:21each of the data words
  73. 2:23is going to be fed into a mux here's my
  74. 2:26mux
  75. 2:27now what am i selecting from i'm
  76. 2:30selecting from
  77. 2:31which particular one i wanted
  78. 2:35you know remember we've mentioned it
  79. 2:37before these are all words i'm grabbing
  80. 2:39i ignore these last two bits those two
  81. 2:42bits are the byte offset
  82. 2:43that's where i am but i'm reading only
  83. 2:45word aligned values
  84. 2:46so i'm never reading every single
  85. 2:48request ever those two are zeros because
  86. 2:50i'm only reading words and words and all
  87. 2:52my words gonna be word aligned
  88. 2:54so that byte offset i don't i ignore
  89. 2:56they're all these are all zeros zero
  90. 2:57and zero that's what they are these two
  91. 3:01bits
  92. 3:02are the bits which are my block offset
  93. 3:05taken together those four bits are my
  94. 3:07bite offset but i'm reading words
  95. 3:09and if i'm word aligned i'm only ever
  96. 3:12getting
  97. 3:13having it be that those four guys if i
  98. 3:15look at that
  99. 3:16that nibble describing this thing that
  100. 3:18nibble is either 0
  101. 3:204 8 or c which means i want that
  102. 3:23byte that by word that by 8
  103. 3:26or c okay each 040 to c had two bits in
  104. 3:30the lower side
  105. 3:31are zeros so i actually only use the
  106. 3:33upper bits
  107. 3:34and the upper two bits are zero one
  108. 3:37two three what's the upper two bits of c
  109. 3:40one one upper two bits of
  110. 3:41of eight one zero what's happened to
  111. 3:43it's a four o
  112. 3:45it's a zero zero so this is this number
  113. 3:48is telling me
  114. 3:49which of those words is the mux going to
  115. 3:52be sending out
  116. 3:53and that might send that data out and
  117. 3:54i'm done that's a beautiful picture so
  118. 3:56this picture is actually describing
  119. 3:58what's happening
  120. 3:59in hardware and these are all happening
  121. 4:00at the same time it's not like well do
  122. 4:02this first
  123. 4:03okay you know computer scientists always
  124. 4:05think well you're sequentially
  125. 4:07well first check this and then
  126. 4:10you got to go and check the tag because
  127. 4:12if you're doing software you'd be doing
  128. 4:13in steps
  129. 4:14not zone hardware folks all these things
  130. 4:16are happening at the same time
  131. 4:18same time same time same time same time
  132. 4:20all that's coming out here
  133. 4:22okay and by the way if this is not a hit
  134. 4:26you ignore what this is i don't care
  135. 4:28what data's coming on those those lines
  136. 4:29i'm not going to pay attention to it
  137. 4:30because i haven't
  138. 4:31it's the wrong one either it's not valid
  139. 4:33or the tags don't match so i'm going to
  140. 4:34ignore my data so all those things
  141. 4:35happen at the same time but at the end
  142. 4:37of the day i check this hit first and if
  143. 4:38that's good
  144. 4:39then i'll use the data otherwise i'll
  145. 4:40ignore that data
  146. 4:43now i ask you what kind of locality are
  147. 4:45we taking advantage of here
  148. 4:46and i'll just pause as you think to
  149. 4:48yourself and before i give the answer
  150. 4:51the answer is both both temporal
  151. 4:54locality and
  152. 4:55spatial locality probably the person who
  153. 4:57wrote this slide i
  154. 4:58inherited a slide deck from other 61c
  155. 5:00instructors probably their mention they
  156. 5:02want you to say
  157. 5:02spatial locality because your block size
  158. 5:04is more than just one byte or one word
  159. 5:06so they want you to say spatial locality
  160. 5:08because they're talking about the block
  161. 5:09size
  162. 5:10but it's a cache all caches have
  163. 5:12temporal locality unless
  164. 5:13unless they don't remember the most
  165. 5:14recent guys but this one cache does and
  166. 5:16so
  167. 5:16they do that so it's it's taking
  168. 5:18advantage of both temporal
  169. 5:20and spatial locality we haven't at all
  170. 5:22though
  171. 5:23talked about rights let's just be honest
  172. 5:25let's be clear
  173. 5:27rights are part of the world right i do
  174. 5:29some sws sbs shs as well
  175. 5:32so what do we do on writes okay i have
  176. 5:34some data
  177. 5:35i'm going to store it in the cache the
  178. 5:37cache may have
  179. 5:38different data than i have i'm going to
  180. 5:40be writing to the area as i'm clobbering
  181. 5:41the cache
  182. 5:42as i'm writing something to memory i'm
  183. 5:44writing to memory i'm going to write
  184. 5:45into the cache too so that i stores it
  185. 5:48as well
  186. 5:49now i could either just
  187. 5:52treat them all as always consistent and
  188. 5:55that's the easier case
  189. 5:57the much easier case is what's called a
  190. 5:58right through so i'm taking my data from
  191. 6:00the processor
  192. 6:01and i'm pushing it out to the cache
  193. 6:03update the cache
  194. 6:04and you know what go to sacramento
  195. 6:06anyway push it all the way through the
  196. 6:07sacramento
  197. 6:09done now my life is so much easier thank
  198. 6:12you so much for doing it right through
  199. 6:13because
  200. 6:14they're always the same i don't worry
  201. 6:15about any of the details of
  202. 6:17what happens when they're inconsistent
  203. 6:19or in a way corrupted
  204. 6:20and maybe corruption is part of the
  205. 6:22design that's what the second one is
  206. 6:24about
  207. 6:24so write back says you know if you're
  208. 6:26just reading and writing to
  209. 6:27value you don't need to why don't you
  210. 6:30just stay in the cache
  211. 6:31here you know i'm going to read from an
  212. 6:32array value and i got it that's fine or
  213. 6:34read it or maybe it wasn't loaded so i
  214. 6:35load it up now it's there
  215. 6:36and now same same array value same array
  216. 6:39address
  217. 6:40i'm going to write a different value
  218. 6:41well do i have to go to sacramento i
  219. 6:43just
  220. 6:43i just came from second why couldn't you
  221. 6:45have them being consistent as the design
  222. 6:48because watch i write it and then the
  223. 6:49next line i read it again hey wait if i
  224. 6:51if i just read it again and write a
  225. 6:53different value and read it again a
  226. 6:54different value
  227. 6:55why do i ever need to tell memory like i
  228. 6:57feel like i can live with my cash
  229. 6:59and we talked about the we mentioned i
  230. 7:01mentioned this over and over
  231. 7:03it's always a local copy but you know in
  232. 7:06this world of right back
  233. 7:08i can save a ton of trips to sacramento
  234. 7:11i can save a ton of trips to sacramento
  235. 7:15if i just don't have to update
  236. 7:16sacramento all the time i'll let you
  237. 7:18know
  238. 7:19whenever i remove it from that so that
  239. 7:21we'll talk about that
  240. 7:22what do i need to actually up tell
  241. 7:24sacramento i wanted to actually write it
  242. 7:25to memory
  243. 7:26and but i get a big performance win if
  244. 7:29i'm reading it right in the same spot
  245. 7:30to not have to go to sacramento with
  246. 7:32every right if you say right through
  247. 7:34i'm going to sacramento in memory every
  248. 7:35single time but if i'm just going read
  249. 7:37write read write of the same location
  250. 7:39boy right back is way faster than right
  251. 7:41through are you kidding me it's a
  252. 7:42thousand cycles or more
  253. 7:44due to sacramento every time i'm doing
  254. 7:45that right so if i can save that i love
  255. 7:47it so people really appreciate write
  256. 7:49backs
  257. 7:49but you end up having more complexity
  258. 7:52what does a slide say
  259. 7:57memory when it's inconsistent there's a
  260. 7:59word for it we call it being stale
  261. 8:01stale is like stale bread it's kind of
  262. 8:02smelly and old and kind of you know
  263. 8:04maybe moldy so it means that memory was
  264. 8:07old
  265. 8:08stale means it's got older the most
  266. 8:10recent copy the freshest copy the
  267. 8:12the true the single source is almost
  268. 8:14there's no more single source of truth
  269. 8:15by the way but like the
  270. 8:17the the answer
  271. 8:20is in the cache not in memory memory is
  272. 8:23no longer the referential
  273. 8:24place where stuff is it's in the cache
  274. 8:27so there's a little bit we have to think
  275. 8:28about that memory is no longer the
  276. 8:30the last word cache is the last word
  277. 8:33actually if it's ever stale
  278. 8:35it also means i need to tell the system
  279. 8:38you know what
  280. 8:39if i'm going to go with right back i
  281. 8:40mean i i need to let the system know
  282. 8:43that this is now inconsistent i don't
  283. 8:46say corrupted because raptor usually
  284. 8:47means a negative thing
  285. 8:48i'm designing this into this so right
  286. 8:50back isn't corrupted it's that when i
  287. 8:51let memory be stale i gotta
  288. 8:53let it know that way that really it's
  289. 8:54the cash that has the referential
  290. 8:56value and that means i need to add
  291. 8:59another bit
  292. 9:00i had a bid for valid to say when i
  293. 9:01initialize the cash i need to know
  294. 9:02whether it's
  295. 9:03whether that tag is i can trust it or
  296. 9:05not so i had a valid bit
  297. 9:08we do the same thing here and similar i
  298. 9:10have a bit called the dirty bit and that
  299. 9:12dirty bit on a right back cache
  300. 9:14says that cache block is not the same as
  301. 9:18the block and this whatever that happens
  302. 9:19to be in the same
  303. 9:20place you know align that the same block
  304. 9:23there in memory
  305. 9:24that's not the same the cache has a
  306. 9:26different value
  307. 9:27even if by the way when i write it
  308. 9:31it happens to write the same value that
  309. 9:33was there before that's a little bit of
  310. 9:34a subtlety what if it's all zeros
  311. 9:36and i happen to write all zeros well i'm
  312. 9:38doing it right and it's right back it
  313. 9:40doesn't check them all
  314. 9:41and then say well if they're the same
  315. 9:42don't let nope even though i'm writing
  316. 9:44the same value it'll still make it stale
  317. 9:46it'll still say nope
  318. 9:47dirty bit said hi this guy is stale even
  319. 9:49though they're actually the same value
  320. 9:50so there's a little bit of a subtlety
  321. 9:51maybe you can optimize it and
  322. 9:53read but that's who wants to do that
  323. 9:54because maybe often block sizes are
  324. 9:56really wide
  325. 9:56who wants to spend time cycling through
  326. 9:58comparing the old guy with the new gun
  327. 10:00i'm going to write and when they're the
  328. 10:01same
  329. 10:01no but you often write a change so you
  330. 10:04don't do that so the point is even from
  331. 10:05writing the same block as was in memory
  332. 10:07i still say
  333. 10:07memory is now stale and dirty bit for
  334. 10:09that block is now one
  335. 10:11they're inconsistent and when the block
  336. 10:14is replaced that's when you need to
  337. 10:15write to memory so
  338. 10:16eventually memory gets updated but only
  339. 10:19when the block has replaced it or
  340. 10:21it's also replaced if the you don't know
  341. 10:23about the
  342. 10:24operating system yet but when the
  343. 10:25operating system has an input output
  344. 10:27activity
  345. 10:28it often flushes the cache and when you
  346. 10:30flush the cache you have to then
  347. 10:32correct correctly put back in memory
  348. 10:33because when you flush the cash you
  349. 10:34don't want to remember cash is now the
  350. 10:36same
  351. 10:36is now the truth and you don't want to
  352. 10:38just throw it away when you flush the
  353. 10:39cash
  354. 10:40if cash is only a copy i can just erase
  355. 10:42it all how do you raise the cash
  356. 10:44set them all invalid but if some of them
  357. 10:46had the dirty bets said hi
  358. 10:48you'd better put those back to
  359. 10:49sacramento to make sure that you update
  360. 10:50memory before i set the dirty bit and
  361. 10:52that
  362. 10:52kind of erase the cache if you will
  363. 10:54remember you never go
  364. 10:56you never do that you just set the dirty
  365. 10:57bit to erase the cache so when you flush
  366. 10:59it or raise the cash you set the valid
  367. 11:01the valid bit to zero but all the dirty
  368. 11:03bits that were won
  369. 11:04you got to make sure you write those
  370. 11:05back to sacramento okay
  371. 11:07and then you can play with the
  372. 11:08performance conversation and performance
  373. 11:09trade-offs when does one win when does
  374. 11:11the other win
  375. 11:12right what can you come up with a
  376. 11:14scenario where each one of them looks
  377. 11:15bad
  378. 11:16if you can by the way we can and you
  379. 11:18should think about that
  380. 11:19that's why we don't just say here's how
  381. 11:21we do it by the way remember how we
  382. 11:23talked about direct map cache and i
  383. 11:24even alluded to how would you find which
  384. 11:26which block it was maybe you use a
  385. 11:28linear search i was just making stuff up
  386. 11:30nobody does that this is where you just
  387. 11:32immediately go there it's a
  388. 11:33constant time figure out what exactly
  389. 11:35what row i have to go to by looking at
  390. 11:36the bits for my index we know how to do
  391. 11:38that now
  392. 11:39there's no log search for these things
  393. 11:42so in the same way
  394. 11:43because i'm still talking about two of
  395. 11:44these guys that must mean that there's
  396. 11:46some scenario where this is better some
  397. 11:48performance from some usage
  398. 11:52some characteristics of a cache with a
  399. 11:54usage pattern
  400. 11:55that makes right through be better and
  401. 11:57might be some characteristic with
  402. 11:58youth's pattern that makes right back be
  403. 12:00better which is the decision why we
  404. 12:01still talk about two ways of doing
  405. 12:02things
  406. 12:02so that there isn't like a clear winner
  407. 12:04and we just ignore and it's lost to
  408. 12:06history
  409. 12:06one's compliment lost to two's
  410. 12:08complement i'm sorry one's compliment
  411. 12:10you lost
  412. 12:11two's complement is better i don't want
  413. 12:13two two zeros so one's complement is a
  414. 12:15kind of a historical footnote
  415. 12:17but both right through and right back
  416. 12:18aren't historical footnotes we both
  417. 12:20these are both reasonable designs in a
  418. 12:21particular cache for a particular system
  419. 12:23so thinking about that is that still a
  420. 12:25conversation for that particular
  421. 12:27instance
  422. 12:28it isn't by the way all caches aren't
  423. 12:29always about memory hacking you have
  424. 12:30caches for the web page i got one paid
  425. 12:32cache
  426. 12:32cache isn't many i have cache for my
  427. 12:35recents of my uh
  428. 12:36phone call list so they're catches in
  429. 12:38all these places
  430. 12:40um and in any one of the situations the
  431. 12:42design might be well this one should be
  432. 12:44right through
  433. 12:44that one should be right back depending
  434. 12:45on how long is it to sacramento maybe
  435. 12:47it's not too long but
  436. 12:48all those come maybe the complexity
  437. 12:50means that it is longer but it's not
  438. 12:52that big a pain so i'll do that because
  439. 12:54the code to write the write back is
  440. 12:55whatever i hurry okay
  441. 12:59now let's talk about block sizes
  442. 13:03we started by starting the first picture
  443. 13:05of a cache i had a one byte block size
  444. 13:07like one you know the column width was
  445. 13:09where the width was one and i said well
  446. 13:10make it two
  447. 13:11and then we actually now have seen 16 16
  448. 13:13byte wide
  449. 13:14blocks what are the benefits of that
  450. 13:17well the benefits are you know spatial
  451. 13:19locality is screaming for spatial
  452. 13:20locality
  453. 13:21if you're going to sacramento if you go
  454. 13:23to the refrigerator get me a hole
  455. 13:25get me some food okay i came back here
  456. 13:27here's this and here's that
  457. 13:28okay if you go in there anyway it once
  458. 13:31you're going to the long distance path
  459. 13:33while you're there grab some stuff and
  460. 13:34then bring more of it back so you can
  461. 13:36stream it back as you're coming back
  462. 13:37with some data
  463. 13:39so this is very applicable for stored
  464. 13:42program concept
  465. 13:43model because we often have sequential
  466. 13:46arrays
  467. 13:46and you typically sweep through an array
  468. 13:48so if i'm going to go there
  469. 13:50i'm going to go and grab the whole block
  470. 13:53of that and that's going to be some
  471. 13:54fraction of the array and now as i'm
  472. 13:55walking through
  473. 13:56it's there it's a miss but then the rest
  474. 13:58of it or hits
  475. 13:59that's the idea of a larger block size
  476. 14:01what's the drawback
  477. 14:04we talked a little bit before two slides
  478. 14:06ago i believe two lectures ago
  479. 14:08on hit hit rate miss rate
  480. 14:12hit or miss penalty when you have a miss
  481. 14:15how much pain do you have to suffer to
  482. 14:17go to sacramento or go even farther for
  483. 14:19that
  484. 14:19so a larger block size means your miss
  485. 14:22penalty goes up
  486. 14:23it means if you come you know reasonably
  487. 14:26rather than go and grab one bite i gotta
  488. 14:27grab
  489. 14:28really i gotta go stack i grab 16 bytes
  490. 14:30what if i'm literally how about this
  491. 14:32randomly hitting memory just randomly
  492. 14:34literally and making it as bad
  493. 14:35what if i'm looking at what how you did
  494. 14:37what you did how you design your cache
  495. 14:39and making you do the most work possible
  496. 14:41it's a robot and i'm making you
  497. 14:42literally
  498. 14:43move to every corner like it's like
  499. 14:44taking the roomba go to that corner
  500. 14:46and then that corner and then that
  501. 14:48corner like it's literally and then
  502. 14:49and then like it's not just letting it
  503. 14:51kind of sweep a room it's literally like
  504. 14:52setting it random spaces as far away as
  505. 14:54it can
  506. 14:55so you can make this look really bad
  507. 14:57because of the miss penalty by
  508. 14:59hitting it randomly and therefore
  509. 15:00there's no spatial location the spatial
  510. 15:02academy isn't being exploited
  511. 15:04you're grabbing its neighbors but never
  512. 15:05visiting its neighbors i'm going to
  513. 15:07grab this block and it's a lot maybe
  514. 15:09it's really wide
  515. 15:11and then guess what i'm never going to
  516. 15:12see it again i'm going to grab another
  517. 15:13guy
  518. 15:14in fact if you make it even worse i'll
  519. 15:15grab another guide that happens at the
  520. 15:16same index and boop it's in the same
  521. 15:18spot oh my god really i went to get
  522. 15:19this huge amount and now it's replaced
  523. 15:21the same guy again and every single one
  524. 15:23is going to be a cache miss black
  525. 15:24replacement
  526. 15:25yes yes how do you do that
  527. 15:29you make a stride the stride is exactly
  528. 15:31the same as
  529. 15:33because i want to have an array an array
  530. 15:34an array has to be the same
  531. 15:36spot every so if your stride memory
  532. 15:39access memory access plus
  533. 15:42cache size cache size means remember the
  534. 15:45picture i drew before
  535. 15:46i drew this picture here with the cache
  536. 15:49size
  537. 15:50here's access one the next access
  538. 15:54is exactly the same spot in the next
  539. 15:58cache down
  540. 15:59that means this tag is i and this tag is
  541. 16:02i plus one
  542. 16:03and i plus two if you stride by cache
  543. 16:06size
  544. 16:06you typically have the worst possible
  545. 16:08performance because you're not making
  546. 16:09use at all
  547. 16:10of the fact that you loaded this whole
  548. 16:13block
  549. 16:14you're not using the neighbors you're
  550. 16:15going around and replacing the same guy
  551. 16:18that you if this is really wide imagine
  552. 16:20how if making this really wide
  553. 16:22you're having to go to sacramento grab
  554. 16:24all the neighbors and you're never using
  555. 16:25them
  556. 16:26can you please just the next memory
  557. 16:28access go plus one minus one so you can
  558. 16:29use some neighbors no sorry
  559. 16:31stride plus cash size worst possible
  560. 16:34performance ever
  561. 16:35in fact i encourage you look up your
  562. 16:37system's
  563. 16:38cache size and write a four line program
  564. 16:41that
  565. 16:41reads a bite i don't care what you do
  566. 16:43just you know read read a word read a
  567. 16:44word from make a huge array make a huge
  568. 16:46array in malik
  569. 16:47huge array find out what your cache size
  570. 16:50is
  571. 16:50and literally have a loop that reads it
  572. 16:52and then jumps by the next memory access
  573. 16:54is exactly the next cache size
  574. 16:56so that will be the worst possible
  575. 16:58situation you're never going to exploit
  576. 16:59at all the cash at all forget even
  577. 17:01spatial locality you're just never able
  578. 17:03to be you're never visiting the same
  579. 17:05spot you're just jumping a raid that's
  580. 17:06exactly
  581. 17:07that's really big and you're jumping
  582. 17:09you're striding by cash size
  583. 17:11worst possible performance by the way do
  584. 17:12that and run like 10 of them
  585. 17:15take your computer find out your cash
  586. 17:16what your block size is
  587. 17:18and run 20 of them just run a little
  588. 17:19thing you know make a little terminal
  589. 17:20make like 10 terminals and run them all
  590. 17:22you're going to be hitting this cash
  591. 17:24like okay i mean you're hitting the
  592. 17:26memory i create every single one
  593. 17:27not a single memory access is hitting is
  594. 17:30it's really funny
  595. 17:30to do this this is more fun in vm by the
  596. 17:32way because in vm you're moving data
  597. 17:35from the disk and then
  598. 17:36so it's it's worse this is a fun story
  599. 17:38to do i'll bring it hope
  600. 17:40hope i give that lecture but that's a
  601. 17:42situation where you can make vm look
  602. 17:43really bad
  603. 17:44by always striding by the thing that's
  604. 17:46going to be the unit of data because the
  605. 17:48worst possible same idea in vm you have
  606. 17:50these
  607. 17:50this unit uh we have here blocks and
  608. 17:52cache sizes we'll talk about pages there
  609. 17:54if you stride by page size that's really
  610. 17:56bad so
  611. 17:57that was an aside to make your system
  612. 17:58look really bad you want to make it
  613. 18:00really bad
  614. 18:00stride by the cash size then you'll
  615. 18:03never take advantage of temporal or
  616. 18:04spatial locality
  617. 18:06okay so if you make if your blocks that
  618. 18:09all that aside was
  619. 18:10if you have a large block size you're
  620. 18:12going to have a big miss penalty
  621. 18:14okay because you have to go when you're
  622. 18:15going to segment you have to bring more
  623. 18:16back with you that's the idea
  624. 18:18and by the way here's the funny so if
  625. 18:21the block size is too big relative to
  626. 18:22the cash size
  627. 18:23there are too few blocks and the miss
  628. 18:25rate goes up
  629. 18:26so in the extreme case where you just
  630. 18:28make it remember i told you you could
  631. 18:29take your cash
  632. 18:30and for the same area you can make like
  633. 18:32in any
  634. 18:34how do i say this if i said i want you
  635. 18:36to make a fence where the area inside
  636. 18:37the fence is
  637. 18:38fixed well it could be this way or twice
  638. 18:41as tall
  639. 18:42and half as wide or twice as wide and
  640. 18:44half as tall same area right i have this
  641. 18:45flexibility of aspect ratio
  642. 18:47of the cash that's the aspect ratio when
  643. 18:49you make it the degenerate case
  644. 18:51which is one high one you know one high
  645. 18:54by total number of bytes equal to the
  646. 18:57cash
  647. 18:57so one high and total equal to that that
  648. 19:00is the that
  649. 19:01in a way that's pretty good you just
  650. 19:03grab the huge
  651. 19:04range from that but here's the funny if
  652. 19:07you're like making a copy what if i'm
  653. 19:10copying a piece of code like two-line
  654. 19:11piece of code that copies from this part
  655. 19:13of memory to that part of memory
  656. 19:14so i go from here and i read a bit and
  657. 19:17then i go to here
  658. 19:18well this is a different part so i have
  659. 19:20to now bring and let's say that they're
  660. 19:22far enough away that they don't all fit
  661. 19:23together
  662. 19:24have to bring this guy in put that long
  663. 19:26thing around there
  664. 19:27well there remember always draw your
  665. 19:29memory same with this cache i'll draw
  666. 19:31memory wide so i'm
  667. 19:32reading from here memory to here i'm
  668. 19:34just reading copying from here to there
  669. 19:35a to b a to b a to b little loop well
  670. 19:38read this
  671. 19:39miss then i read this one well that's
  672. 19:41not there because that cause i only have
  673. 19:42one cache it's only one row
  674. 19:44so that's a miss two i'm trying to write
  675. 19:45that value and i read this one read the
  676. 19:47next guy over here
  677. 19:48okay that's a miss too and you have this
  678. 19:50crazy
  679. 19:52you're just loading in and out just
  680. 19:53never have a cache hit because you're
  681. 19:55always reading and writing
  682. 19:56from different places but there's only
  683. 19:58one row to store stuff so that's
  684. 20:00terrible
  685. 20:01even if i had two that'd be better but
  686. 20:03then you had this issue that's two and
  687. 20:04the direct map that could
  688. 20:06have the same index which means the
  689. 20:08mother wrote the same the best situation
  690. 20:09is when they end up having two different
  691. 20:11rows and i can read from here oh read
  692. 20:12read read right from here this is great
  693. 20:13like how fast this is if they both can
  694. 20:15fit in the cache at the same time
  695. 20:16so even two different rows can be can
  696. 20:17save me that if i happen to have a
  697. 20:19direct map cache
  698. 20:20that happens to have the same index
  699. 20:21where they end up in the same row
  700. 20:24long story short one big row is really
  701. 20:27bad and you often have this called ping
  702. 20:28pong effect where i'm continually
  703. 20:29kicking out
  704. 20:30these two guys and then forcing them out
  705. 20:31because they happen to have only one row
  706. 20:33and they don't fit they both can't fit
  707. 20:35so this is a really nice graph of a
  708. 20:37block size trade-off
  709. 20:39if i look at block size versus miss
  710. 20:42penalty how bad is your penalty your
  711. 20:45time
  712. 20:46for larger block size it just goes up
  713. 20:48and if you're going to sacramento
  714. 20:50and i'm i'm going to it's a linear you
  715. 20:52know relationship i've gone to
  716. 20:53sacramento to
  717. 20:54fetch one thing it's there fair fast
  718. 20:56double it's a bit more if i flash four
  719. 20:58times that that
  720. 20:59it's more there it's kind of a linear
  721. 21:00relationship there's probably some
  722. 21:01overhead i've got a sacramento period
  723. 21:03but then every kind of extras thing i'm
  724. 21:05grabbing is slower to grab
  725. 21:08put in my arms and walk it across so
  726. 21:11this penalty goes up linearly with block
  727. 21:13size
  728. 21:14how does miss rate relate to block size
  729. 21:17that's the kind of interesting thing
  730. 21:19normally block size is helping a little
  731. 21:21bit with that because
  732. 21:23all of a sudden you know spatial
  733. 21:24locality is coming in here so if you
  734. 21:26look at this
  735. 21:27spatial locality means that miss rate
  736. 21:29remember i don't have misses
  737. 21:31i want this to be as low as possible i
  738. 21:32don't want me misses okay i want my hit
  739. 21:34rate to go up
  740. 21:35so my miss rate is high but then as i
  741. 21:38make my block side better
  742. 21:39spacial cali is like hey you went there
  743. 21:41already and now my neighbors got it for
  744. 21:43me so that's kind of neat
  745. 21:44but what happens is at the end of it we
  746. 21:46just talked about this
  747. 21:48we lose temporal locality i end up
  748. 21:49having too few blocks to hold all the
  749. 21:51things i normally do and it starts to go
  750. 21:52up it there
  751. 21:53and that's a problem and if you remember
  752. 21:57there well i think i showed you this yet
  753. 21:59average access time where i see this
  754. 22:01again
  755. 22:01is a product of those guys so we kind of
  756. 22:04multiply them together
  757. 22:05and this the fact that this guy goes up
  758. 22:07here the fact that this guy goes up
  759. 22:09kind of amplifies this a little bit more
  760. 22:11if you see that and so this goes up here
  761. 22:13and what we typically
  762. 22:14say is we look for the knee in the curve
  763. 22:17we look in a place where the curve drops
  764. 22:19down otherwise the no
  765. 22:21otherwise known as the local minimum and
  766. 22:23so there is a
  767. 22:24sweet spot for the block size it isn't
  768. 22:26like well
  769. 22:27just make it as big as possible it's
  770. 22:28always a win or i mean if you only look
  771. 22:30at this miss penalty make it as small as
  772. 22:32possible
  773. 22:33if you just look at one number if i want
  774. 22:34to reduce missed penalty make it as
  775. 22:36small as possible
  776. 22:37well but then the remiss rate goes up
  777. 22:38and the fact that the fact that average
  778. 22:40access time is a project both of those
  779. 22:41means that i have to think about the the
  780. 22:43knee and the curve for that
  781. 22:46now let's let's talk about this what
  782. 22:48we're talking about misses what kind of
  783. 22:50misses do i have
  784. 22:54first is a compulsory miss these are
  785. 22:56these misses
  786. 22:57are misses because it's a cold cache
  787. 23:00cache starts there's nothing there all
  788. 23:02the valid bits are off there's no
  789. 23:04nothing's valid so
  790. 23:05i gotta take the hit compulsory means
  791. 23:07you just gotta do it
  792. 23:08uh you gotta take the hit you gotta
  793. 23:10start you gotta take the take the fall
  794. 23:12you need to take the miss
  795. 23:13on every road that hasn't been visited
  796. 23:15before that valid bit is off and you
  797. 23:17gotta take you gotta take that
  798. 23:18you need to pay that penalty there's no
  799. 23:19way around that so that put
  800. 23:21so every block is going to have at least
  801. 23:24one compulsory miss
  802. 23:25okay every block of memory
  803. 23:29will have at least one compulsory miss
  804. 23:34how about conflict misses
  805. 23:38well conflict is because you've got two
  806. 23:41remember the blue first picture of the
  807. 23:42cache the two blues
  808. 23:44mapped to the same i guess it was here
  809. 23:46the two blues map to the same blue over
  810. 23:48there so
  811. 23:51that's a shame oh it's such a shame we
  812. 23:52couldn't fix that
  813. 23:54in fact later lectures we're going to
  814. 23:56tell you how to fix that so two blocks
  815. 23:57happen to map to the same thing
  816. 23:59and that's the problem with direct map
  817. 24:00caches it i mentioned before if i'm
  818. 24:02ping-ponging here
  819. 24:04if i can even if i have a row a cache
  820. 24:06with two rows
  821. 24:08i still might have those guys be the
  822. 24:10same spot you know this huge block and
  823. 24:12this use block end up being the same
  824. 24:13because of the way that
  825. 24:14the index works they have to be the same
  826. 24:16row oh that's annoying
  827. 24:17so that's an issue with direct map
  828. 24:19caches that maybe we can exploit
  829. 24:20and think about relaxing that and maybe
  830. 24:23direct map caches aren't the only
  831. 24:24game in town we'll explore that in later
  832. 24:26lectures so that's fun
  833. 24:28so conflict missions you could either
  834. 24:30make the cache bigger
  835. 24:31and maybe the smart thing is could
  836. 24:34multiple distinct blocks fit in the same
  837. 24:36index
  838. 24:36what would that even mean to have two
  839. 24:39blocks two blues
  840. 24:40end up being in the same blue area
  841. 24:43we'll actually explore that in the next
  842. 24:45lecture we'll see you there

About this transcript

This page contains the full transcript of [CS61C FA20] Lecture 26.2 - Caches III: Writes, Block Sizes, Misses by CS 61C Departmental, generated from the public captions YouTube serves with the video. The transcript has 5,364 words across 842 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.