patternMinor
CPU cache - retrieving data from memory
Viewed 0 times
cachecpumemoryretrievingfromdata
Problem
Regarding CPU cache, if the CPU does not find the data it needs in the cache, I understand it then looks for it in the main memory (RAM). (Let's assume we have only one level of cache in order to keep this question as simple as possible.)
My question is this: if the data is found in main memory, what happens? Does the processor use this data directly, or is the data loaded into the cache and then read from there?
My question is this: if the data is found in main memory, what happens? Does the processor use this data directly, or is the data loaded into the cache and then read from there?
Solution
Nobody can say what every computer will do, but there are some reasonable assumptions.
When you access data that is not in the cache, you want it to be in the cache afterwards. So the CPU will read the data from memory, and move it to the cache. That's one half of the job.
There is some part of the CPU that needs the data, and we want to get the data to that part of the CPU as fast and as cheap as possible. There is already a mechanism in place to provide the data if it is in the cache. So the CPU could just move the data to the cache, then use the existing mechanism. That's cheap and easy.
Or the CPU can move data from memory to the place where it is needed either simultaneously with the cache, or even before the data is moved to the cache. That has the advantage that the data may appear a little bit faster where it is needed. It has the disadvantage that now the two situations (in cache, not in cache) need to be handled by different hardware. That is likely more complicated and more expensive.
Which one is chosen depends on how much quicker the more complicated method is, how much it costs more, and how much the cost is compared to other possible improvements.
When you access data that is not in the cache, you want it to be in the cache afterwards. So the CPU will read the data from memory, and move it to the cache. That's one half of the job.
There is some part of the CPU that needs the data, and we want to get the data to that part of the CPU as fast and as cheap as possible. There is already a mechanism in place to provide the data if it is in the cache. So the CPU could just move the data to the cache, then use the existing mechanism. That's cheap and easy.
Or the CPU can move data from memory to the place where it is needed either simultaneously with the cache, or even before the data is moved to the cache. That has the advantage that the data may appear a little bit faster where it is needed. It has the disadvantage that now the two situations (in cache, not in cache) need to be handled by different hardware. That is likely more complicated and more expensive.
Which one is chosen depends on how much quicker the more complicated method is, how much it costs more, and how much the cost is compared to other possible improvements.
Context
StackExchange Computer Science Q#76692, answer score: 2
Revisions (0)
No revisions yet.