1Page1Memory-HierarchyDesignWhyismemoryimportant?1101001000198019811982198319841985198619871988198919901991199219931994199519961997199819992000DRAMCPU• MemorywallduetoemphasisonspeedforprocessordensityforDRAMCPU-DRAMSpeedGapTheGoalProvidememorysystemwithcostofcheapest levelofmemoryandwithspeedasfastasfastest levelofmemoryInstructioncacheUnifiedcacheDatacacheDRAMmemorySecondarystorageCPU(registers)UpperlevelLowerlevelMemoryHierarchyL1cacheL2cache• Thecorrectnesscriteria– Theexecutionresultsofaprogramshouldbeas if itwereexecutedonasystemwithoutanycachememory2Page2GeneralCachingPrinciples• Locality– TemporalLocality:referencedagainsoon– SpatialLocality:nearbyitemsreferencedsoon• Locality+smallerHWisfaster=memoryhierarchy– Levels:eachsmaller,faster,moreexpensive/bytethanlevelbelow– Inclusive:datafoundintopalsofoundinthebottomSomeDefinitions• Upperisclosertoprocessor• Block:minimumunitofinformationthatcanbepresentincache• Hittime:timetoaccesscache,includinghitdetermination• Hitrate:fractionfoundinthecache- Missrate=1- HitRate• Misspenalty:timetofetchablockfromlowerlevel,includingtimetoreplaceinCPU- accesstime:timetoaccesslowerlevel- transfertime:timetotransferblockDifferencesinMemoryLevelsFourQuestionsforMemoryHierarchyDesigners• Q1:Wherecanablockbeplacedintheupperlevel?(Blockplacement)• Q2:Howisablockfoundifitisintheupperlevel?(Blockidentification)• Q3:Whichblockshouldbereplacedonamiss?(Blockreplacement)• Q4:Whathappensonawrite?(Writestrategy)3Page3Q1:Wherecanablockbeplacedintheupperlevel?• DirectMapped:Eachblockhasonlyoneplacethatitcanappearinthecache.• Fullyassociative:Eachblockcanbeplacedanywhereinthecache.• Setassociative:Eachblockcanbeplacedinarestrictedsetofplacesinthecache.– Iftherearenblocksinaset,thecacheplacementiscalledn-waysetassociativeAssociativity ExamplesFullyassociative:Block12cangoanywhereDirectmapped:Blockno.=(Blockaddress)mod(#ofblocksincache)Block12cangoonlyintoblock4(12mod8)Setassociative:Setno.=(Blockaddress)mod(#ofsetsincache)Block12cangoonlyintoset0(12mod4)butanyblockinthatsetQ2:HowIsaBlockFoundIfItIsintheUpperLevel?• Theaddresscanbedividedintotwomainparts– Blockoffset:selectsthedatafromtheblockoffsetsize=log2(blocksize)– Blockaddress:tag+index» index:selectssetincacheindexsize=log2(#ofsets)=log2(#ofblocks/set associativity)» tag:comparedtotagincachetodeterminehittagsize=addresssize- indexsize- offsetsizeMappingFunction4Page4MappingFunctionConsider• 64KBcache• 4Bytedatatransfer(block)sizebetweenmainmemoryandcache• CacheOrganizedin16Kblockframes(slots)of4Byteseach• Mainmemoryhas16MBytes(Orwecantreatthememoryashaving4Mblocksof4Byteseach)24bitmemoryaddressMappingStructureMainMemoryCache0 1RowNumberColumnNumberRowNumberColumnNumberMappingStructureMapping Rows Columns Rows ColumnsDirect 256 16K 1 16KAssociative 4M 1 16K 1SetAssociative 512 8K 2 8KMainMemory CacheDirectMapping14BitsindexNo28BitsTag5Page5AssociativeMapping222bittagSetAssociativeMapping2139Tag IndexBlockOffsetAddressMatchtoCacheBlockOffsetIndexTag.....8.3vValidbit---->Tagsearch---->Datablock--->2-waysetassociativecacheQ3:WhichBlockShouldbeReplacedonaMiss?• DirectMapped:– NoChoice(onlyonecandidate)• SetAssociativeorFullyAssociative:– Random- easiertoimplementbutlessefficient– LeastRecentlyused- hardertoimplementbutmoreefficient• Missratesforcacheswithdifferentsize, associativity andreplacementalgorithm.6Page6Q4:WhatHappensonaWrite?• Writethrough:Theinformationiswrittentoboththeblockinthecacheandtotheblockinthelower-levelmemorycombinedwithwritebufferssoitwon’twaitforlowerlevelmemoryaccess• Writeback:Theinformationiswrittenonlytotheblockinthecache.Themodifiedcacheblockiswrittentomainmemoryonlywhenitisreplaced.– isblockcleanordirty?(addadirtybittoeachblock)• ProsandConsofeach(obviousones):– Writethrough» readmissescannotresultinwritestomemory,» easiertoimplement» mainmemoryis“always” up-to-date(lesscoherenceproblem)– Writeback» Lessmemorytraffic» PerformwritesatthespeedofthecacheQ4:WhatHappensonaWrite?• Sincedatadoesnothavetobebroughtintothecacheonawritemiss,therearetwooptions:– Writeallocate» Theblockisbroughtintothecacheonawritemiss» Usedmostlywithwrite-backcaches» Hopesubsequentaccessestotheblockhitincache– No-writeallocate» Theblockismodifiedinmemory,butnotbroughtintothecache» Usedwithwrite-throughcaches»
View Full Document