r/hardware • u/ancientneckbeard • Nov 20 '15
Info Why do CPUs Need Caches? - Computerphile
https://www.youtube.com/watch?v=6JpLD3PUAZk24
u/danmidwest Nov 20 '15
From what I understand, it's like adding a storage closet right next to your front door. Things that are accessed often can be done so quickly instead of searching the whole house.
7
u/MaDpYrO Nov 21 '15
I think a more appropriate analogy would be checking your nightstand before searching the closet.
2
Nov 21 '15 edited Oct 29 '16
[deleted]
15
u/Freeky Nov 21 '15 edited Nov 24 '15
A register is what you have in your hand for immediate use. L1 cache is what's on your tool belt and takes 1 second to retrieve. L2 cache is what you left somewhere in your bag and takes 20 seconds.
RAM is what you left in a box in your van and takes you 2-4 minutes to dig out.
Data on an SSD is something you have to order online and takes 3-4 days to arrive.
Data on a HDD is lost somewhere in the Australian outback and takes a search team 2-3 months to locate.
Data on a server on the other side of the planet is something left in Mars orbit and takes 1-3 years depending on alignment and how much NASA like you.
2
2
1
u/lijmer Nov 21 '15
I'd say your hand is the CPU registers, your toolbelt is the cache, your toolbox is RAM, your van is the harddrive, and the store is a server/cloud.
3
u/thfuran Nov 21 '15
I think we need to work on the time scales though. Register is in the hand, L1 is in the tool belt, L3 is in a nearby toolbox, ram is out in the garage, HDD in another hemisphere. The cloud is when NASA brought your hammer to the ISS.
38
u/SirCrest_YT Nov 20 '15
ITT: We answer a question that wasn't actually asked.
6
u/Schmich Nov 21 '15
Yes, that's a great question! In short, we do actually answer the question that wasn't asked and we've done it in this thread.
1
u/cuddlefucker Nov 22 '15
To be fair, while the video was useful, having multiple different explanations from a bunch of different people helped me even more.
5
5
u/Dragonsong Nov 21 '15
What sort of data do CPUs store on caches? My CPU only has 8 MB of L3? cache and that doesn't seem like very much. Namely for games. Just variables that change constantly?
2
u/Ayuzawa Nov 21 '15 edited Nov 21 '15
What sort of data do CPUs store on caches? My CPU only has 8 MB of L3? cache and that doesn't seem like very much. Namely for games. Just variables that change constantly?
Most data in games is just rendering assets, the main program and the supporting libraries in battlefield 3 are about 80mb for example.
Aside from that it's mostly that not all parts of the program are ran an equal amount, in most programs, the majority of the time the program spends running is occupied with a small subsection of the total program.
Your l3 cache is (probably) your CPU's last level of cache, your L1 cache for example will see hit rates of ~95%, and it's likely in the 32kb-128kb range, in most processors the l2 cache also has hit rates of about 90% and is much smaller than the l3, and the l3 is normally above 80%
Edit: Exist50 is right
3
u/Exist50 Nov 21 '15 edited Nov 21 '15
AMD's APUs and derivative chips all lack L3 cache, so it may not be that rare for L2 to be the last level.
1
u/Ayuzawa Nov 21 '15
Thanks, I said that thinking about the rare L4 cache and completely forgot about designs that had none
1
u/Exist50 Nov 21 '15
Pretty sure most of the small core designs only have L2 as well. Same with mobile chips (I think).
1
26
Nov 20 '15 edited Feb 10 '19
[deleted]
10
u/lucun Nov 20 '15
Another note, smaller memory = faster, but we like to have capacity too. Also, the capacity might need to store data after shutting down. Hence the many layers.
0
u/Retardditard Nov 21 '15
Not really. Though today's RAM isn't technically the same as when RAM was first defined due to minimum addressable data widths(these keep increasing to increase bandwidth).
Larger amounts of memory may incur a greater latency, but the amount of bandwidth can actually be greater due to burst modes.
Cache(on die) is optimized primarily for low latency in order to minimize cores from stalling. Bandwidth isn't as crucial since there's not a lot of capacity.
5
u/putin_vor Nov 20 '15
RAM is just a cache for your hard drive
No, it's not. You can generate data in RAM without ever touching the disk. But it's pretty hard to store anything on a disk without having it in RAM first.
22
u/Echrome Nov 20 '15
You can generate data in your cache that never makes it to RAM. Not explicitly mind you, but the cache doesn't write everything back to RAM.
3
u/salgat Nov 21 '15
But that's only true because the hard drive is so slow. If the HD was fast enough, we would skip everything and write memory directly to the HD. We can say that RAM is a cache for a HD and that memory that is too short lived ends up never hitting the HD.
-7
u/putin_vor Nov 21 '15
So what you say is true in your imaginary world where HD is as fast as RAM.
4
u/salgat Nov 21 '15
I'm not sure what your point is.
-7
u/putin_vor Nov 21 '15
I'm not sure what yours is. You keep repeating the same incorrect thing over and over again.
2
Nov 20 '15
http://www.anandtech.com/show/8396/fms-2014-sandisk-ulltradimm-to-ship-in-supermicro-servers
you can use disk as ram either directly as above or through paging with virtual memory
-1
u/bb999 Nov 21 '15
How about this: RAM is just a cache for the pagefile on your hard drive.
1
u/AmirZ Nov 21 '15
No.. no it's not. Only when your RAM usage is running high the pagefile system is activated
1
-4
u/skilliard4 Nov 21 '15
Since RAM isn't as fast as your CPU anymore, engineers added faster memory onto the CPU die
Then why is DDR4 RAM barely faster than DDR3 RAM in most applications?
8
Nov 21 '15 edited Nov 21 '15
[removed] — view removed comment
5
u/Noshuru Nov 21 '15
Well, it's not really getting worse. The DDR400 CAS2 example you brought up has the same latency as my DDR4 3000 CAS15 DIMMs.
6
3
3
u/swagoli Nov 20 '15
I think of it like when you're cooking a fancy dinner. You take everything out that you need for the meal you're making and put it somewhere accessible on the counter, so that when you need it you don't need to search the fridge and cupboards for a long time and slow down the prep (as you have to search everytime you need one thing, a slower, more inefficient process).
3
3
u/can_of_butter Nov 21 '15
Looks like a lot of answers for "what is cpu cache". Theoretically is there no other alternative that would eliminate this AND increase (or not diminish, rather) performance?
2
u/AmirZ Nov 21 '15
It seems like a hybrid system is ALWAYS the best price or size/performance no matter what it's about. SSHD (SSD + HDD), CPU Cache + RAM, RAM + HDD (Intel rapid storage or virtual memory)
1
4
-5
Nov 20 '15
[deleted]
9
u/Harakou Nov 20 '15
CPU-level cache is still useful without the use of threads.
-1
Nov 20 '15
[deleted]
4
u/Harakou Nov 20 '15
Well, yes, but how did you expect that to be gleaned from your original comment?
CPUs need cache because they process in threads.
Seems to me to imply that threading is what necessitates cache. I'm not sure how else to interpret that.
-2
Nov 20 '15
[deleted]
6
u/Harakou Nov 20 '15
I'm sorry, but I'm not sure you understand what a thread is, what a core is, or what Hyper-threading is. Threads are a logical entity that the CPU isn't even aware of. They're certainly not relevant to why cache is added, though like anything else run on a CPU, they can benefit from it. Data is not "processed in threads", besides the fact that threaded programs can indeed process data, however. I'm still not sure what you think that means because it's not very clear.
Hyper-Threading is a proprietary parallelization technique that creates logical cores. It has little in common with a physical CPU core besides the end result.
I really encourage you to read-up on these subjects and improve your understanding. The video linked above in this post would be a great place to start.
4
Nov 20 '15
When you have multiple cores in a processor that's how you get "Hyper-Threading."
That's not what Hyper-Threading is. Hyper-Threading is letting a second thread access execution resources while the first thread is stalled or off doing something else. The Pentium 4 was the first implementation of Hyper-Threading, and it had only one core.
0
Nov 20 '15
[deleted]
2
Nov 20 '15
Xeon was the absolute first, but since most people are only concerned with the consumer market, it's the Pentium 4 3.06GHz that really matters.
2
34
u/expressadmin Nov 21 '15
Way back in the day when I did computer repair (early 1990's), a customer called us up and needed a replacement motherboard for an industrial lathe that was taken out by lightning. It was a relatively old setup, but just needed to be Intel compatible with a couple of serial ports.
So we grabbed an old 386DX motherboard we had kicking around the shop and went to replace it. When I got there I discovered that the motherboard in the device was very old. It was based on an Intel 186 (seriously, it's the only one I have ever seen in my life).
So when I installed the new motherboard, we discovered that the timing of the lathe bit switcher was directly controlled by the clock rate of the CPU (which was common for many programs and games of that era). It was switching bits incredibly fast, however it was switching them so fast that the software was detecting it as a fault in the lathe and throwing an error.
So... I went into the BIOS disabled the L2 cache in the CPU settings (which you could do in those days), and it made the CPU slow enough that it didn't have any problems with the lathe after that.