1

I met two cases in final exam. First case memory fetch information from location like: 0x101,0x102,0x101,0x102,0x101,0x102,0x101,0x102.

Second case memory fetch information from location like: 0x101,0x101,0x101,0x101,0x111,0x109,0x102,0x100.

The question is in which case it use temporal locality.

Here is my point: In the first case. I think in reality when we access 0x101,the memory will also access 0x102 into cache. Then in the following six fetch, there will be no penalty. That means in this case we only have one cache miss. Here I think we benefit from both temporal locality and spatial locality. while in the second case in the first four step we benefit from temporal locality but in the following step we do not have temporal locality. Actually this leads to more cache miss than first choice. I think both are right but we can only have one answer so I feel confused.

2 Answers2

0

I'd vote for the 2nd one. As you said, it has a clear case of temporal locality on the first 4 steps.

It is never said that your cache has space to hold more than 1 item in memory. It could be a CPU with just 1 register or something. So it is possible that the first case does not exhibit any locality whatsoever.

Did the question provide more details on the architecture of the system?

Cubicle Dragon
  • 305
  • 1
  • 9
  • No more detail information are provided by this question. I wonder I choose a wrong answer in this exam, what a pity... – user3180776 Jan 10 '14 at 09:29
0

It's definitely the 2nd choice. The question is clear enough: you are explicitly making use of temporal locality in the second case because you're accessing 0x101 multiple times in a row.

See this question: Spatial vs. Temporal locality

Temporal locality implies that you're going to access the same address multiple times, relatively closely in time.

You are right in saying that the first case also uses temporal locality, but I'd say it gears towards spatial locality because you are alternating between 2 neighbour positions, thus, cache misses are minimized because of spatial locality, not because of temporal locality.

In the second case, cache misses are minimized because of temporal locality. Remember that temporal locality says that if you accessed position X right now, you will likely do so again very soon. This is the property explored in the second case.

Community
  • 1
  • 1
Filipe Gonçalves
  • 20,783
  • 6
  • 53
  • 70
  • But what is the mean of "very soon". I doubt that in two or three system clock is also called very soon. – user3180776 Jan 10 '14 at 12:02
  • @user3180776 2 or 3 system clocks is nothing. 100 system clocks is still very soon. It depends on the context, but remember that CPU cycles are very fast. Given the options in your question, I'd go for 2 because temporal locality is really obvious there. – Filipe Gonçalves Jan 10 '14 at 12:29
  • @user3180776, soon is a subjective definition - it should be considered soon enough if you access that same line while it's still residing in the cache (the actual distance will differ according to cache size/associativity, access patterns, etc..) – Leeor Jan 11 '14 at 09:39