How Cache Works Inside a CPU

แชร์
ฝัง
  • เผยแพร่เมื่อ 23 ธ.ค. 2024

ความคิดเห็น •

  • @dragnight2931
    @dragnight2931 22 วันที่ผ่านมา +45

    Wtf bro how the hell is this channel so underrated??? Dude keep doing what you're doing. It's absolutely breathtakingly brilliant

    • @BitLemonSoftware
      @BitLemonSoftware  22 วันที่ผ่านมา +9

      Thanks! I put a lot of effort into making the animations. I hope these videos are helpful to people.

    • @dragnight2931
      @dragnight2931 22 วันที่ผ่านมา +3

      @BitLemonSoftware keep it up mate.. it's amazing

    • @tristancole8158
      @tristancole8158 21 วันที่ผ่านมา +2

      There’s no need to swear. We’re all on your side here.

    • @Rnsryt5
      @Rnsryt5 12 วันที่ผ่านมา

      that's just how youtube work's not everyone is blessed by algorithms and also this niche is not so watchable and entertaining but very educational

  • @charlsdefoes5959
    @charlsdefoes5959 20 วันที่ผ่านมา +19

    please continue, I've been searching for ages to find this amazing content

    • @BitLemonSoftware
      @BitLemonSoftware  19 วันที่ผ่านมา +2

      I invest a lot of time researching and making the animations so each video takes a couple of weeks to make. Please be patient

  • @reinasama904
    @reinasama904 20 วันที่ผ่านมา +11

    This is one of the best explanations I've seen. I'll have to rewatch this video to fully grasp the content of it, thank you so much for making this!

  • @ArneChristianRosenfeldt
    @ArneChristianRosenfeldt 22 วันที่ผ่านมา +6

    For normal memory the CPU sends out the address, which then goes through the binary address generator to fetch a row.
    With cache we first fetch the addresses stored in the set. Then in a second step we address the cacheline (row) in a second memory bank. So cache needs two cycles.
    Therefore, N64 uses TMEM, not cache. Atari Jaguar uses scratchpad memory (on chip). And even here an access has 3 cycles latency ( vs 2 to the register file ). Atari calls this extremely fast memory
    It would be faster to use large registers. The Jaguar can load 64 bit at once. ARM uses a barrel shifter in every instruction to select packed bit fields.
    Likewise the CPU should just fetch very long instruction words. So long that it can contain REP SCANS and the 68k instructions of the same kind.

    • @AK-vx4dy
      @AK-vx4dy 18 วันที่ผ่านมา

      It is all true, but to much detailed for such level.

    • @ArneChristianRosenfeldt
      @ArneChristianRosenfeldt 18 วันที่ผ่านมา +2

      @ this was not meant as a criticism of the video, just a hint to follow. A lot of CS seems to be detached from the electric side. I think this was already visible in the 80s were Intel, WDC, and Motorola ran at higher clock speeds than the fabless RISC CPUs from theoretical CS , which offered incompatibility for an insane price .

  • @alecyalcin7567
    @alecyalcin7567 11 วันที่ผ่านมา +2

    Great video! Keep it up, my class teacher from Brazil has just shared this video through the group class.

    • @BitLemonSoftware
      @BitLemonSoftware  11 วันที่ผ่านมา +1

      Wow, I didn't realize I was making such an impact

  • @RobertFletcherOBE
    @RobertFletcherOBE 16 วันที่ผ่านมา +2

    older games used to do all of these things, its not that modern games are discovering this stuff they're returning to it.

  • @nfasts
    @nfasts 9 วันที่ผ่านมา

    Detailed video shows lots of efforts went into research and animation great work

  • @InfernTech
    @InfernTech หลายเดือนก่อน +7

    here before this channel blows up, very informative and beautiful man, keep it up

    • @BitLemonSoftware
      @BitLemonSoftware  หลายเดือนก่อน

      Thanks! Hopefully it will reach more people

  • @sg9257
    @sg9257 23 วันที่ผ่านมา +10

    I'm your 293rd subscriber. This channel is criminally underrated

    • @BitLemonSoftware
      @BitLemonSoftware  23 วันที่ผ่านมา +2

      Thanks for the support! The channel is still young, hopefully it will grow soon.

    • @noammichael5592
      @noammichael5592 20 วันที่ผ่านมา +1

      789 🫡

    • @howyoudoin2069
      @howyoudoin2069 20 วันที่ผ่านมา +1

      823!!!!

    • @keshav2136
      @keshav2136 20 วันที่ผ่านมา +1

      929

    • @Kleberei
      @Kleberei 12 วันที่ผ่านมา

      2349 ... growing fast :D

  • @pietraderdetective8953
    @pietraderdetective8953 21 วันที่ผ่านมา +4

    Yeah I agree with the other commenters, your channel is underrated.
    Let me fix that...liked and subbed!

    • @BitLemonSoftware
      @BitLemonSoftware  21 วันที่ผ่านมา

      Thank you for the support!

    • @dadestor
      @dadestor 21 วันที่ผ่านมา +1

      same, great video

  • @Vxlde
    @Vxlde 17 วันที่ผ่านมา

    I am pretty sure this channel is gonna blow up very soon, I love your content!

    • @BitLemonSoftware
      @BitLemonSoftware  17 วันที่ผ่านมา

      I'm glad you like it. Hopefully it will reach more people

  • @FranciscoHerrera007
    @FranciscoHerrera007 22 วันที่ผ่านมา +3

    keep it up man this is gonna blow up!

  • @金玄鹤
    @金玄鹤 20 วันที่ผ่านมา +3

    This high-quality channel has not yet reached 1k subscribers.

    • @BitLemonSoftware
      @BitLemonSoftware  20 วันที่ผ่านมา

      Indeed. Does that surprise you?

  • @divinedreams5657
    @divinedreams5657 หลายเดือนก่อน +2

    Nice animation and Video. You saved my day understanding caches :)

  • @ShadrachEmemekemini
    @ShadrachEmemekemini 19 วันที่ผ่านมา +2

    Sir, you're doing a great job here. As a certified Digital Marketer, I strongly believe you should leverage on Google Ads(TH-cam Ads). Soon, people would flood ur channel

  • @stachowi
    @stachowi 21 วันที่ผ่านมา +1

    This was amazing, never heard it explained so well.

  • @dazealex
    @dazealex 22 วันที่ผ่านมา +2

    Keep it up, loved the video and graphics!

    • @BitLemonSoftware
      @BitLemonSoftware  22 วันที่ผ่านมา

      Thanks! I appreciate the support

  • @FioraLaurent-s2d
    @FioraLaurent-s2d 3 หลายเดือนก่อน +3

    Hope more people find your channel like i find today, its a very good video with a great explanation. if you accept any suggestion, please apply this visualization methodology to explain some algorithms problems, for example, the dining philosophers problem in C. Thanks, i would love to see

    • @BitLemonSoftware
      @BitLemonSoftware  3 หลายเดือนก่อน

      Thank you! Of course I take suggestions. These types of videos take a lot of time to make, but I do want to touch on interesting algorithm problems, and will get there eventually.

  • @timog7358
    @timog7358 10 วันที่ผ่านมา +1

    great explanation

  • @jronbroke
    @jronbroke 22 วันที่ผ่านมา +3

    Keep up bro .Great video ❤.

  • @sudipmandal2497
    @sudipmandal2497 21 วันที่ผ่านมา +1

    Very insightful content. keep going man - your 739 subscriber.

  • @nikhilkumarav3021
    @nikhilkumarav3021 19 วันที่ผ่านมา

    This is really amazing. Thank you for the great work, i hope you have fun making such content because it is fun for us to watch it.

    • @BitLemonSoftware
      @BitLemonSoftware  19 วันที่ผ่านมา

      Thanks! I do enjoy making these videos and I hope they actually help people and I'm not just wasting time

  • @Matem-sc1ic
    @Matem-sc1ic 19 วันที่ผ่านมา +1

    Sometimes i love TH-cam recommendations ❤

    • @BitLemonSoftware
      @BitLemonSoftware  19 วันที่ผ่านมา +1

      I'll take it as a compliment 😁

  • @halfsleeves
    @halfsleeves 8 วันที่ผ่านมา

    It should be mentioned here that if this is direct mapped cache then each RAM address is mapped to the cache. But since the RAM is bigger than the cache, there are multiple RAM addresses ( RAM bytes/cache bytes ) which will be mapped to the same cache address. That is why, even though the cache is 32kb , 36 bits are used because if a RAM memory address which is not there in the cache tries to access the cache there should be a cache miss.

  • @AK-vx4dy
    @AK-vx4dy 18 วันที่ผ่านมา

    I only skimmed, but it looks very good, nice, clear explanations.

  • @Tanmay_Kudkar
    @Tanmay_Kudkar 22 วันที่ผ่านมา +2

    Keep growing bro ❤❤❤

  • @StevenMartinGuitar
    @StevenMartinGuitar 23 ชั่วโมงที่ผ่านมา

    Damn this was really great. Please do more!

  • @ntfsguy3601
    @ntfsguy3601 19 วันที่ผ่านมา

    Awesome video! I’m subscribing right now.

  • @fadiallo1
    @fadiallo1 14 วันที่ผ่านมา +1

    Best

  • @hareTom
    @hareTom 21 วันที่ผ่านมา

    Great content! Keep up the good work
    In next step, how does multi-core CPU handles their cache state and sync between them. That’s a part I never understand well enough

    • @BitLemonSoftware
      @BitLemonSoftware  21 วันที่ผ่านมา +1

      Thanks! The sync between caches is done using the MESIF/MOESI protocols (or other derivatives).
      It's on my ToDo list and I will dedicate a whole video to it.

  • @rohitkushvaha2481
    @rohitkushvaha2481 22 วันที่ผ่านมา +1

    Nice video, you should show code as example too in videos

    • @BitLemonSoftware
      @BitLemonSoftware  22 วันที่ผ่านมา +1

      Thanks! Sure I'll consider adding some code examples in the future

  • @Eeatch
    @Eeatch 13 วันที่ผ่านมา

    Hey, great video! Liked it and subscribed to your channel

    • @BitLemonSoftware
      @BitLemonSoftware  13 วันที่ผ่านมา

      Thanks! I really appreciate the support

  • @lqx7
    @lqx7 22 วันที่ผ่านมา

    Underrated channel

    • @BitLemonSoftware
      @BitLemonSoftware  22 วันที่ผ่านมา

      Thanks for the support! The channel is still young and hopefully it will grow soon.

  • @metinevrenkurtulus
    @metinevrenkurtulus 22 วันที่ผ่านมา +1

    If you create additional objects how do you keep them aligned in memory? Allocate bigger chunk? But if that chunk is filled up is there anything that can be done?

    • @BitLemonSoftware
      @BitLemonSoftware  22 วันที่ผ่านมา +2

      Take Vector in C++ STL as an example: you create objects in a small pre-allocated chunk of memory. When that memory is full, you allocate a bigger chunk (let's say twice the size you have right now), copy all existing objects to the new location, release the old memory and continue creating objects in the new location.
      This way objects are always stored next to each other in memory. Unfortunately, you have to pay the performance price when copying the data every time you allocate new memory.

    • @metinevrenkurtulus
      @metinevrenkurtulus 20 วันที่ผ่านมา +1

      @BitLemonSoftware Thank you very much! I see how it's done now.

  • @BalooCSGO69
    @BalooCSGO69 14 วันที่ผ่านมา

    בחמש שניות הראשון ידעתי שאתה ישראלי יתותח על

  • @MissPiggyM976
    @MissPiggyM976 22 วันที่ผ่านมา

    Well done, thanks!

  • @rahiiqbal1294
    @rahiiqbal1294 หลายเดือนก่อน +2

    Nice video :)

  • @chetan_naik
    @chetan_naik 13 วันที่ผ่านมา

    When I studied about computer architecture, they always taught that CPU talks to RAM directly not much about cache. Only when I became professional only then I realized multiple levels of cache before RAM. I understand the importance of caching but I wonder how much is overhead on CPU when cache miss happens at all cache levels. Wouldn't it be faster to directly fetch from RAM instead of looking through multiple levels of cache?

    • @BitLemonSoftware
      @BitLemonSoftware  13 วันที่ผ่านมา +1

      There is a very specific formula to figure out the Average Memory Access Time for a cache hierarchy.
      To break even (RAM access is equal to cache access on average), you need a certain percent of cache hits. This percent is relatively low (probably low teens) so anything above that will justify cache access.

  • @Tanmay_Kudkar
    @Tanmay_Kudkar 22 วันที่ผ่านมา +1

    I am your 423rd subscriber ❤

    • @BitLemonSoftware
      @BitLemonSoftware  22 วันที่ผ่านมา +1

      Welcome. I hope my videos are helpful

  • @ariel795
    @ariel795 18 วันที่ผ่านมา

    Subbed. Any chance of giving some recommended sources related?

  • @thrc1618
    @thrc1618 19 วันที่ผ่านมา

    What are the best low level programming languages to manage chache resources? Trying to see if Rush would come up in that list

    • @Jardynq
      @Jardynq 19 วันที่ผ่านมา +2

      You don't manage cache. That's done by the CPU. You can assist it though by taking advantage of temporality and locality by allocating and accessing your memory intelligently.

    • @BitLemonSoftware
      @BitLemonSoftware  18 วันที่ผ่านมา

      What do you mean by cache resources? The cache is completely controlled by hardware. Your choice of language won't have any direct impact on the behavior of the cache

    • @thrc1618
      @thrc1618 18 วันที่ผ่านมา

      Ok I see, so is it mostly memory/thread control from any low level code?

    • @BitLemonSoftware
      @BitLemonSoftware  18 วันที่ผ่านมา

      Languages like C/C++/Assembly give you the ability to control how the data in your program is arranged in memory. If you do it smart, it might increase the efficiency of the cache.
      I think threads can have an impact on cache, especially in situations where you run completely different code on different threads

  • @ДаниилИмани
    @ДаниилИмани 15 วันที่ผ่านมา +1

    Please, rearrange the CPU cache playlist in chronological order

    • @BitLemonSoftware
      @BitLemonSoftware  15 วันที่ผ่านมา

      Done! Thanks for pointing that out to me

  • @saeednajafii
    @saeednajafii 24 วันที่ผ่านมา

    u should have 1M subs.

  • @snowballs2023
    @snowballs2023 11 วันที่ผ่านมา

    Could eniminate number of cores if increase cpu cache?

  • @jairajsahgal5062
    @jairajsahgal5062 3 หลายเดือนก่อน +1

    Thank you

  • @Nik-oe7df
    @Nik-oe7df 13 วันที่ผ่านมา

    @6:51 it should be 2^36 bits, not bytes.

    • @BitLemonSoftware
      @BitLemonSoftware  13 วันที่ผ่านมา

      64GB is equal to 2^36 Bytes, which are represented by 36 bits

    • @Nik-oe7df
      @Nik-oe7df 13 วันที่ผ่านมา +1

      @@BitLemonSoftware You're right, i looked at that too quickly ^^.

  • @christianhaugen9462
    @christianhaugen9462 15 วันที่ผ่านมา

    Clarifying question: you keep mentioning that memory is slow, but is this just in comparison to how fast the cache can respond? RAM is supposed to be one of the fastest components, so it confused me a bit when you kept saying it was slow.

    • @BitLemonSoftware
      @BitLemonSoftware  15 วันที่ผ่านมา

      Sorry if I wasn't clear. You are right, when I say RAM is slow, it is always relative to cache.
      You could also say that RAM is really fast, compared to hard disks.

  • @NimaqAlizadeh
    @NimaqAlizadeh 20 วันที่ผ่านมา

    Nice🎉

  • @Clma333
    @Clma333 13 วันที่ผ่านมา

    This was such an insightful video! I really enjoyed the part about locality. It reminded me of a video I recently made on VPC, where I dive deeper into core concept of VPC and its implementation in AWS. If anyone’s interested, feel free to check it out - I’d love to hear your thoughts!

    • @Clma333
      @Clma333 13 วันที่ผ่านมา

      Thanks @BitLemonSoftware

  • @modman4842
    @modman4842 20 วันที่ผ่านมา

    How do I have a cs degree and have never herd of DOD

    • @BitLemonSoftware
      @BitLemonSoftware  20 วันที่ผ่านมา

      I think CS degrees often focus on OOP because it's more intuitive

  • @youtubehandlesux
    @youtubehandlesux 16 วันที่ผ่านมา +1

    0:59 factorio, one of the most optimized video games, uses OOP and inheritance, and most of the data belong to an object is stored in one place. ECS and DOD are overrated techniques that limit creativity.

    • @BitLemonSoftware
      @BitLemonSoftware  16 วันที่ผ่านมา

      On the other hand, Minecraft uses an incredibly efficient ECS (EnTT) to store and manage it's million-object maps.
      Anyway, I wasn't trying to paint an accurate picture of how games organize data, just to highlight the difference between memory layouts and how it relates to the cache

  • @nair889
    @nair889 20 วันที่ผ่านมา +1

    ur accent feels like your indian

    • @BitLemonSoftware
      @BitLemonSoftware  20 วันที่ผ่านมา +1

      Ummm... Not even a little bit. It's actually russian

    • @nair889
      @nair889 20 วันที่ผ่านมา +2

      @BitLemonSoftware пхпхпххпп, бывает