Sie sind auf Seite 1von 8

181002027

CACHE MAPPING
• Cache mapping –
1. Direct mapping
2. Fully Associative Mapping
3. Set Associative Mapping / K-way Set Associative Mapping
DIRECT MAPPING
• Simplest mapping technique - each block of main memory maps to only one cache line
• if a block is in cache, it must be in one specific place
• Formula to map a memory block to a cache line:
• i = j mod c
• i=Cache Line Number
• j=Main Memory Block Number
• c=Number of Lines in Cache
• i.e. we divide the memory block by the number of cache lines and the remainder is
the cache line address
DIRECT MAPPING WITH
C=4
Block 0 w0,w1,w2,w3

Block 1 w4,w5,w6,w7
Slot 0
Block 2 w8,w9,w10,w11
Slot 1
Slot 2 Block 3 w12,w13,w14,w15

Slot 3 Block 4 w16,w17,w18,w19

Block 5 w20,w21,w22,w23
Cache Memory
Block 6 w24,w25,w26,w27

0 Mod 4 = Reminder 0 Block 7 w28,w29,w30,w31


4 Mod 4 = Reminder 0
Main Memory
DIRECT MAPPING PROS & CONS

• Simple
• Inexpensive
• Fixed location for given block
• If a program accesses 2 blocks that map to the same line repeatedly, cache
misses are very high – condition called thrashing
FULLY ASSOCIATIVE MAPPING
• A fully associative mapping scheme can overcome the problems of the direct mapping
scheme . Block 0

Slot 0 Block 1

Slot 1 Block 2
Block can map to any slot
Tag used to identify which block is in which slot Block 3 Main
Slot 2
All slots searched in parallel for target Memory
Slot 3 Block 4

Block 5
Cache Memory
Block 6
Block 7
SET ASSOCIATIVE MAPPING / K-WAY SET
ASSOCIATIVE MAPPING

• Two-way set associative gives much better performance than direct mapping
• Just one extra slot avoids the thrashing problem
• Four-way set associative gives only slightly better performance over two-way
• Further increases in the size of the set has little effect other than increased
cost of the hardware!
• To compute cache set number:
• Set Num = j mod v
• j = main memory block number
• v = number of sets in cache Block 0
Block 1

Set 0 Slot 0 Block 2

Slot 1 Block 3
Set 1 Slot 2 Block 4

Slot 3 Block 5

cache Main Memory

Das könnte Ihnen auch gefallen