Set Associative Cache

5 篇文章 0 订阅

Set Associative Cache

Introduction

A set-associative scheme is a hybrid between a fully associativecache, and direct mapped cache. It's considered a reasonable compromisebetween the complex hardware needed for fully associative caches (whichrequires parallel searches of all slots), and the simplistic direct-mappedscheme, which may cause collisions of addresses to the same slot (similarto collisions in a hash table).

Let's assume, as we did for fully associate caches that we have:

  • 128 slots
  • 32 bytes per slot

Furthermore, let's assume that we can group slots together intosets. In particular, we will assume that we have 8 slots per set.

Parking Lot Analogy

Suppose we have 1000 parking spots. This time, instead ofusing a 3 digit number for each parking spot, we use 2 digits.Thus, the parking spots are numbered 00 up to 99.

However, instead of one parking spot per number, we have10 for each number. Thus, there are ten parking spots numbered00, ten numbered 01, ..., and ten numbered 99.

Your parking spot is based on the first 2 digits of your studentID number.

In this case, you use the first 2 digits of your student ID,and have up to 10 different parking spots you can park at. Thisgives you some flexibility about where to park.

In effect, the various parking permits on a large commuter campuswork just like that. There are many lots, each with their own letteror number. You are given a permit for a particular lot, but you canpark anywhere within this lot. The advantage is that you only have tosearch for a spot in one large lot, as opposed to searching for aparking spot in all of campus.

Set Associative Scheme

Like the direct mapped scheme, we still treat the slots likean array. The slots are still numbered 0000000 up to 1111111 (thereare 128 slots).

However, we group the slots into sets, and the key is tokeep track of the sets, instead of the slots.

How many sets do we have? 128 slots divided by 8 slots persets, gives us 16 sets.

We need to specify the set number, instead of the slot number,and that takes lg 16 = 4 bits.

Here's how the bits of the address break down. It's verysimilar to direct mapped, except we use 4 bits for the set, insteadof the slot.

Bits A4-0 is still the offset. The setnumber are the next 4 bits, Bits A8-5. Theremaining bits, A31-9 is the tag.

Finding the Slot

Finding a slot is more complex than in direct-mapped caches.Suppose you have address B31-0.
  • Use bits B8-5 to find the set.
  • This should specify 8 slots (since we said there were 8 slotsper set. The slots should have following slot indexes:
    • B8-5000
    • B8-5001
    • B8-5010
    • B8-5011
    • B8-5100
    • B8-5101
    • B8-5110
    • B8-5111
    In effect, the set number specifies the upper 4 bits of theindex, and the bottom 3 bits are all possible 3 bit bitstringvalues.
  • Search in all 8 slots to see if the tag A31-9 matches the tag in the slot.
  • If it matches one of the slots, get the byte at offset B4-0.
  • If not, decide which slot should be used (possibly evicting a slot), fetch the 32 bytes from memory, slot, updating valid bit, dirty bit, and tag as neededx
This is called 8-way set associative cache, since each set contains8 slots. You can have N-way set-associative caches, where eachset contains N slots (where N is a power of 2).

Compromises

This scheme is a compromise. You only have to use the complexcomparison hardware (to find the correct slot) on a small set ofslots, instead of over all the slots. Presumably, such comparisonhardware is more than linear in the number of slots, so thefewer the slots you need to search through, the less overallhardware is needed.

Yet, you gain the flexibility of allowing up to N cache linesper slot for an N-way set associative scheme.

Summary

A set-associative cache scheme is a combination offully associative and direct mapped schemes. You group slotsinto sets. You find the appropriate set for a given address (whichis like the direct mapped scheme),and within the set you find the appropriate slot (which is likethe fully associative scheme).

This scheme has fewer collisions because you have more slots topick from, even when cache lines map to the same set.


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值