52 Cache基本知识 现代计算机,在cPU和主存之间一般都设置一个高速,小容量的存储 器 cache,它对于提高计算机系统的性能有着重要的意义 Sample memory hierarchy CPU 0 Cache LO DCache L2 T LI Cache I Cache backside option Disk L2 L2 L2 ●● Cache Cach Cache Tape Juke Box I/0 Adapter Main Memory 16
计算机体系结构 Chapter5.16 5.2 Cache基本知识 ▪ 现代计算机,在CPU和主存之间一般都设置一个高速,小容量的存储 器cache,它对于提高计算机系统的性能有着重要的意义
Q1:映象规则 当要把一个块从主存调入 Cache时,如何放置问题 三种方式 全相联方式:即所调入的块可以放在 cache中的任何位置 直接映象方式:主存中每一块只能存放在 cache中的唯一位置 一般,主存块地址i与 cache中块地址的关系为: j=imod(M),M为 cache中的块数 ·组相联映象:主存中每一块可以被放置在 Cache中唯一的一个组中的任意 个位置,组由若干块构成,若一组由n块构成,我们称N路组相联 组间直接映象 组内全相联 若 cache中有G组,则主存中的第i块的组号K K=i mod(G), 计算机体系结构 Chapter517
计算机体系结构 Chapter5.17 Q1:映象规则 ▪ 当要把一个块从主存调入Cache时,如何放置问题 ▪ 三种方式 • 全相联方式:即所调入的块可以放在cache中的任何位置 • 直接映象方式:主存中每一块只能存放在cache中的唯一位置 一般,主存块地址i 与cache中块地址j 的关系为: j = i mod (M) ,M为cache中的块数 • 组相联映象:主存中每一块可以被放置在Cache中唯一的一个组中的任意 一个位置,组由若干块构成,若一组由n块构成,我们称N路组相联 - 组间直接映象 - 组内全相联 若cache中有G组,则主存中的第i 块的组号K K = i mod (G)
Q1: Where can a block be placed in the upper level? Block 12 placed in 8 block cache: Fully associative, direct mapped, 2-way set associative S A Mapping= block Number Modulo Number Sets Fully associative Direct mapped Set associative block 12 can go block 12 can go block 12 can go anywhere only into block 4 anywhere in set o (12mod8) (12mod4) Block 01234567 Block 01234567 Block 01234567 Set setset set Block-frame address 0123 Block 1111111111222222222233 01234567890123456789012345678901 计算机体系结构 Chapter518
计算机体系结构 Chapter5.18 ▪ Block 12 placed in 8 block cache: • Fully associative, direct mapped, 2-way set associative • S.A. Mapping = Block Number Modulo Number Sets 0 1 2 3 4 5 6 7 Block no. Fully associative: block 12 can go anywhere 0 1 2 3 4 5 6 7 Block no. Direct mapped: block 12 can go only into block 4 (12 mod 8) 0 1 2 3 4 5 6 7 Block no. Set associative: block 12 can go anywhere in set 0 (12 mod 4) Set 0 Set 1 Set 2 Set 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 Block-frame address 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 Block no. Q1: Where can a block be placed in the upper level?
Q1的讨论 NWay组相联:如果每组由N个块构成, cache的块数为M 则 cache的组数G为MN 不同相联度下的路数和组数 路数 组数 全相联 直接相联 其他组相联1<N<M M 相联度越高, cache空间利用率就越高,块冲突概率就越小,失效率就越 低 ·N值越大,失效率就越低,但 Cache的实现就越复杂,代价越大 ·现代大多数计算机都采用直接映象,两路或四路组相联。 计算机体系结构 Chapter519
计算机体系结构 Chapter5.19 Q1的讨论 ▪ N-Way组相联:如果每组由N个块构成,cache的块数为M ,则cache的组数G为M/N ▪ 不同相联度下的路数和组数 路数 组数 全相联 M 1 直接相联 1 M 其他组相联 1 < N <M 1 < G < M • 相联度越高,cache空间利用率就越高,块冲突概率就越小,失效率就越 低 • N值越大,失效率就越低,但Cache的实现就越复杂,代价越大 • 现代大多数计算机都采用直接映象,两路或四路组相联
Q2(1/2):查找方法 在 CACHE中每一 block都带有tag域(标记域),标记分为 两类 Address Tags:标记所访问的单元在哪一块中,这样物理地址就分为 部分: Address Tags# Block index# block offset 全相联映象时,没有 Block Index 显然 Address tag越短,査找所需代价就越小 Status Tags:标记该块的状态,如 Valid, Dirty等 Block Address Block T Index offset Set select Data select 计算机体系结构 Chapter520
计算机体系结构 Chapter5.20 Q2(1/2): 查找方法 ▪ 在CACHE中每一block都带有tag域(标记域),标记分为 两类 • Address Tags:标记所访问的单元在哪一块中,这样物理地址就分为三 部分: Address Tags ## Block index## block Offset 全相联映象时,没有Block Index 显然 Address tag越短,查找所需代价就越小 • Status Tags:标记该块的状态,如Valid, Dirty等 Block offset Block Address Tag Index Set Select Data Select