1
\$\begingroup\$

My book about computer organization said that:

If size of a block is 1 word (4 bytes), it will encounter 10 misses when accessing 10 consecutive integers in an array.

If we set the size of a block to 2 words, we can achieve a reduction from 10 misses to maximum 6 misses when probing those 10 consecutive integers. (Assume an integer takes 4 bytes).

I don't get why it is 6 misses, I thought it would be more reasonable to be 5.

\$\endgroup\$
1
  • \$\begingroup\$ Block size (among other things) dictates how much data is fetched on a cache miss... \$\endgroup\$
    – vicatcu
    Commented Dec 3, 2018 at 14:23

1 Answer 1

5
\$\begingroup\$

If the ten words you want to fetch happen to be aligned to the block boundaries, you'll only need to fetch 5 blocks, as shown here:

           ___
               Word 1000
           ___ Word 1001 ___
           1   Word 1002
           ___ Word 1003
           2   Word 1004
Cache      ___ Word 1005     The ten
Block      3   Word 1006     words you
Boundaries ___ Word 1007     want to
           4   Word 1008     fetch.
           ___ Word 1009
           5   Word 100A
           ___ Word 100B ___
               Word 100C
           ___ Word 100D
               Word 100E
           ___ Word 100F

However, if the ten words start in the middle of a cache block, then they span a total of six blocks, as shown here:

           ___
               Word 1000
           ___ Word 1001
           1   Word 1002 ___
           ___ Word 1003
           2   Word 1004
Cache      ___ Word 1005     The ten
Block      3   Word 1006     words you
Boundaries ___ Word 1007     want to
           4   Word 1008     fetch.
           ___ Word 1009
           5   Word 100A
           ___ Word 100B
           6   Word 100C ___
           ___ Word 100D
               Word 100E
           ___ Word 100F
\$\endgroup\$
3
  • 1
    \$\begingroup\$ That is to say, if the first cache miss brings in no additional data that is useful for future loads. \$\endgroup\$
    – vicatcu
    Commented Dec 3, 2018 at 14:25
  • \$\begingroup\$ I'm sorry, can you explain it more simply for me, I don't understand some phrases, such as "cache block boundaries" \$\endgroup\$
    – Tjh Thon
    Commented Dec 3, 2018 at 16:37
  • \$\begingroup\$ See edit above. \$\endgroup\$
    – Dave Tweed
    Commented Dec 3, 2018 at 18:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.