Home Technique Cache

Cache



Introduction

Cachereferstothememorythatcanexchangehigh-speeddata.ItexchangesdatabeforethememoryandCPU,sothespeedisveryfast.L1Cache(firstlevelcache)isthefirstlevelofCPUcache.Thecapacityandstructureofthebuilt-inL1cachehaveagreaterimpactontheperformanceoftheCPU,butthecachememoryiscomposedofstaticRAM,andthestructureismorecomplex.WhentheCPUdieareacannotbetoolarge,thecapacityoftheL1cacheisnotItmaybetoobig.Generally,thecapacityofL1cacheisusually32-256KB.L2Cache(second-levelcache)isthesecond-levelcacheoftheCPU,dividedintointernalandexternalchips.Theinternalchip'sL2cacherunsatthesamespeedasthemainfrequency,whiletheexternalL2cacheisonlyhalfofthemainfrequency.TheL2cachecapacitywillalsoaffecttheperformanceoftheCPU.Theprincipleisthatthelargerthebetter,theL2cacheofordinarydesktopCPUsisgenerally128KBto2MBorhigher,andtheL2cacheofCPUsusedonnotebooks,serversandworkstationscanreachupto1MB-3MB.Sincethehigherthespeedofthecache,themoreexpensiveitis,sosomecomputersystemshavetwoormorelevelsofcache.Thefirst-levelcacheclosetotheCPUhasthehighestspeedandthesmallestcapacity.Thesecond-levelcachehasaslightlylargercapacityandaslightlylowerspeed.

Thecacheisjustacopyofasmallpartofthedatainthememory,sowhentheCPUlooksfordatainthecache,itwillnotbefound(becausethedataisnotcopiedfromthememorytothecache).Atthattime,theCPUwillstilllookfordatainthememory,sothesystemspeedwillslowdown,buttheCPUwillcopythedatatothecachesothatitwillnotberetrievedfromthememorynexttime.Astimechanges,themostfrequentlyaccesseddataisnotstatic.Thatistosay,thedatathatwasnotfrequentlyaccessedjustnowneedstobeaccessedfrequently.Themostfrequentdatajustnowisnotfrequent,soItissaidthatthedatainthecacheshouldbereplacedfrequentlyaccordingtoacertainalgorithm,soastoensurethatthedatainthecacheisaccessedmostfrequently.

Workingprinciple

TheworkingprincipleofthecacheisthatwhentheCPUwantstoreadapieceofdata,itfirstsearchesitfromtheCPUcache,andthenreadsitimmediatelyandsendsittotheCPUforprocessing;,ItreadsfromtherelativelyslowmemoryandsendsittotheCPUforprocessing,andatthesametimetransfersthedatablockwherethedataislocatedintothecache,sothattheentireblockofdatacanbereadfromthecacheinthefuture,noneedtocallRAM.ItisthisreadmechanismthatmakestheCPUreadcachehitrateveryhigh(mostCPUscanreachabout90%),whichmeansthat90%ofthedatathattheCPUwillreadnexttimeareintheCPUcache,onlyabout10%Needstobereadfrommemory.ThisgreatlysavesthetimefortheCPUtodirectlyreadthememory,andalsomakestheCPUbasicallynoneedtowaitwhenreadingdata.Ingeneral,theorderinwhichtheCPUreadsdataiscachedfirstandthenmemory.

RAM(Random-AccessMemory)isoppositetoROM(Read-OnlyMemory).RAMistheonethatdisappearsafterpowerfailure,andtheinformationwillnotdisappearafterROMpowerfailure.whichtype.RAMisdividedintotwotypes,oneisstaticRAM,SRAM(StaticRAM);theotherisdynamicRAM,DRAM(DynamicRAM).Thestoragerateoftheformerismuchfasterthanthelatter,andthememoryusedisgenerallydynamicRAM.Inordertoincreasethespeedofthesystem,itisenoughtoexpandthecache.Thelargertheexpansion,themoredatacachedandthefasterthesystem.ThecacheisusuallystaticRAM,andthespeedisveryfast,buttheintegrationofstaticRAMislow(storageForthesamedata,thevolumeofstaticRAMis6timesthatofdynamicRAM),andthepriceishigh(staticRAMofthesamecapacityisfourtimesthatofdynamicRAM).ItcanbeseenthatexpandingstaticRAMasacacheisaverystupidbehavior,butforToimprovetheperformanceandspeedofthesystem,itisnecessarytoexpandthecache.Inthisway,thereisacompromisemethod.InsteadofexpandingtheoriginalstaticRAMcache,somehigh-speeddynamicRAMisaddedasacache.Thespeedofthesehigh-speeddynamicRAMishigherthanthatoftheconventionaldynamicRAMisfast,butslowerthantheoriginalstaticRAMcache.TheoriginalstaticRAMcacheiscalledthefirstlevelcache,andthedynamicRAMthatwasaddedlateriscalledthesecondlevelcache.

Functionalrole

Theharddiskcachemainlyplaysthreeroles:

Pre-reading

WhentheharddiskiscontrolledbytheCPUinstruction,itstartstoread.Whenfetchingdata,thecontrolchipontheharddiskwillcontroltheheadtoreadthedatainthenextorseveralclustersoftheclusterbeingreadintothecache(becausethedataontheharddiskisstoredcontinuously,thereadhitrateisrelativelyhighHigh),whenthedatainthenextorseveralclustersneedstoberead,theharddiskdoesnotneedtoreadthedataagain,justtransferthedatainthecachetothememorydirectly,becausethecacherateismuchhigherthanThereadandwritespeedofthemagneticheadcanachievethepurposeofsignificantlyimprovingperformance.

Write

Cache(16photos)

Whentheharddiskreceivesaninstructiontowritedata,itwillnotwritethedataimmediatelyIsstoredonthedisc,buttemporarilystoredinthecache,andthensendsa"datawritten"signaltothesystem,thenthesystemwillthinkthatthedatahasbeenwritten,andcontinuetoperformthefollowingwork,andtheharddiskisinWhenitisidle(whennotreadingorwriting),thedatainthecacheiswrittentothedisk.Althoughtheperformanceofwritingdatahasbeenimprovedtoacertainextent,italsoinevitablybringssecurityrisks-whenthedataisstillinthecache,thepowerissuddenlylost,thenthedatawillbelost.Forthisproblem,theharddiskmanufacturersnaturallyhaveasolution:whenthepowerisoff,theheadwilluseinertiatowritethedatainthecacheintoatemporarystorageareaotherthantrackzero,andthenwritethedatatothedestinationafterthenextstartup.

Temporarystorage

Sometimes,somedatawillbeaccessedfrequently.Forexample,theinternalcacheoftheharddisk(akindoftemporarystorage)willstoresomefrequentlyreaddatainthecache.Itcanbetransferreddirectlyfromthecachewhenitisreadagain.Thecacheislikethememoryofacomputer.Whentheharddiskreadsandwritesdata,itisresponsiblefordatastorageandstorage.Inthisway,notonlycanthetimefordatareadandwritebegreatlyreducedtoimprovetheuseefficiencyoftheharddisk.Atthesametime,theuseofcachecanalsoreducefrequentreadsandwritesoftheharddisk,makingtheharddiskquieterandmorepower-saving.Withalargerharddiskcache,youwillbefasterwhenreadinggames,fasterwhencopyingfiles,andmoreadvancedinsystemstartup.

Thesizeofthecachecapacityisdifferentfordifferentbrandsandmodels.Theearlyharddiskcacheisbasicallyverysmall,onlyafewhundredKB,whichcannolongermeettheneedsofusers.16MBand32MBcachesarecurrentlyusedbymainstreamharddrives,andthereareproductswithlargercachecapacitiesinserversorspecialapplications,evenreaching64MB,128MB,andsoon.Althoughthelarge-capacitycachecanstoremoredatainthecachewhiletheharddiskisreadingandwriting,toincreasetheaccessrateoftheharddisk,itdoesnotmeanthatthelargerthecache,themoreoutstandingitis.Thereisanalgorithmicproblemwithcachedapplications.Evenifthecachecapacityislargewithoutanefficientalgorithm,thehitrateofcacheddataintheapplicationwillbelow,andtheadvantagesoflarge-capacitycachecannotbeeffectivelyused.Algorithmsarecomplementarytocachecapacity.Large-capacitycachesrequiremoreefficientalgorithms,otherwiseperformancewillbegreatlyreduced.Fromatechnicalpointofview,high-capacitycachealgorithmsareanimportantfactorthatdirectlyaffectstheperformanceofharddrives.Largercapacitycacheisaninevitabletrendinthedevelopmentofharddisksinthefuture.

Technologydevelopment

TheearliestCPUcachewasawhole,andthecapacitywasverylow.IntelbegantoclassifycachesfromthePentiumera.Atthattime,thecacheintegratedintheCPUcorewasnotenoughtomeettheneedsoftheCPU,andthelimitationsonthemanufacturingprocesscouldnotgreatlyincreasethecapacityofthecache.Therefore,thereisacacheintegratedonthesamecircuitboardastheCPUoronthemotherboard.Atthistime,thecacheintegratedwiththeCPUcoreiscalledthefirst-levelcache,andtheexternaloneiscalledthesecond-levelcache.Thefirstlevelcacheisalsodividedintodatacache(DataCache,D-Cache)andinstructioncache(InstructionCache,I-Cache).Thetwoarerespectivelyusedtostoredataandexecuteinstructionsforthesedata,andbothcanbeaccessedbytheCPUatthesametime,reducingconflictscausedbycontentionforCache,andimprovingprocessorperformance.WhenIntelintroducedthePentium4processor,itreplacedtheinstructioncachewithanewly-addedfirst-leveltrackingcachewithacapacityof12KμOps,whichmeansitcanstore12Kmicroinstructions.

WiththedevelopmentoftheCPUmanufacturingprocess,thesecond-levelcachecanalsobeeasilyintegratedintotheCPUcore,andthecapacityisalsoincreasingyearbyyear.WhetheritisintegratedintheCPUornottodefinethefirstandsecondlevelcachesisnolongeraccurate.Andasthesecond-levelcacheisintegratedintotheCPUcore,thepreviousdivisionofthesecond-levelcacheandtheCPUhasbeenchanged.Atthistime,itworksatthesamerateasthemainfrequency,whichcanprovideahighertransmissionratefortheCPU..Thesecond-levelcacheisoneofthekeystotheperformanceoftheCPU.WhentheCPUcoredoesnotchange,increasingthesecond-levelcachecapacitycangreatlyimprovetheperformance.AndthedifferencebetweenthehighandlowendofthesamecoreCPUisoftendifferentinthesecondlevelcache,whichshowstheimportanceofthesecondlevelcachetotheCPU.

TheCPUfindsusefuldatainthecacheiscalledahit.WhenthereisnodataneededbytheCPUinthecache(calledamissatthistime),theCPUaccessesthememory.Intheory,inaCPUwithasecond-levelcache,thehitrateforreadingthefirst-levelcacheis80%.Thatistosay,theusefuldatafoundintheCPU'sfirst-levelcacheaccountsfor80%ofthetotaldata,andtheremaining20%​​isreadfromthesecond-levelcache.Duetotheinabilitytoaccuratelypredictthedatatobeexecuted,thehitrateofreadingthesecond-levelcacheisalsoabout80%(readingusefuldatafromthesecond-levelcacheaccountsfor16%ofthetotaldata).Thentheremainingdatahastobecalledfrommemory,butthisisalreadyafairlysmallpercentage.Higher-endCPUswillalsohaveathird-levelcache,whichisdesignedfordatathatmissesafterreadingthesecond-levelcache—atypeofcache.InaCPUwithathird-levelcache,onlyabout3%ofthedataneedstoberetrievedfromthecache.Calledinmemory,whichfurtherimprovestheefficiencyoftheCPU.InordertoensureahighhitrateduringCPUaccess,thecontentinthecacheshouldbereplacedaccordingtoacertainalgorithm.Amorecommonlyusedalgorithmisthe"leastrecentlyusedalgorithm"(LRUalgorithm),whicheliminatesthelinesthathavebeenleastvisitedinthemostrecentperiodoftime.Therefore,itisnecessarytosetacounterforeachrow.TheLRUalgorithmclearsthecounterofthehitrowandadds1tothecountersoftheotherrows.Whenreplacementisneeded,thedatarowwiththelargestrowcountercountiseliminated.Thisisanefficientandscientificalgorithm.Itscounterclearingprocesscaneliminatesomedatathatisnolongerneededafterfrequentcallsfromthecacheandimprovetheutilizationofthecache.InCPUproducts,thecapacityofthefirstlevelcacheisbasicallybetween4KBand64KB,andthecapacityofthesecondlevelcacheisdividedinto128KB,256KB,512KB,1MB,2MB,4MB,etc.Thereisnotmuchdifferencebetweenthefirst-levelcachecapacityofeachproduct,andthesecond-levelcachecapacityisthekeytoimprovingCPUperformance.TheincreaseinthecapacityofthesecondarycacheisdeterminedbythemanufacturingprocessoftheCPU.TheincreaseincapacitywillinevitablyleadtoanincreaseinthenumberoftransistorsinsidetheCPU.TointegratealargercacheonalimitedCPUarea,therequirementsforthemanufacturingprocesswillbehigher.MainstreamCPUsecondarycachesarearound2MB,amongwhichIntelhassuccessivelyintroducedhigh-performanceCPUswith4MBand6MBsecondarycachesfordesktopcomputersin2007,butthepriceisrelativelyhigh,andtheconfigurationrequirementsarenottoohigh.Myfriend,ageneraldual-coreCPUwith2MBL2cachecanbasicallymeetdailyInternetneeds.

Mainsignificance

Theprincipleofcachingworkis"localityofreference",whichcanbedividedintotemporallocalityandspatiallocality.SpatiallocalitymeansthattheCPUneedsacertaindataatacertainmoment,soitislikelythatthenextstepwillneedthedatanearby;timelocalitymeansthatwhenacertaindataisaccessedonce,itwillbere-examinedafterashortperiodoftime.Onevisit.Forapplications,nomatteritistheinstructionfloworthedataflow,thelocalityphenomenonofreferencewillappear.

Togiveasimpleexample,forexample,whenplayingaDVDmovie,theDVDdataconsistsofaseriesofbytes.Atthistime,theCPUwillprocesstheDVDdatafromthebeginningtotheendinturn.IftheCPUreadsthistimeTheDVDdatais1minuteand30seconds,sothenexttimeitisread,itwillstartfrom1minuteand31seconds.Therefore,inthiscase,theordereddataaresequentiallyreadintotheCPUforprocessing.Fromthedatapointofview,applicationssuchasWordusuallyhavegoodspatiallocality.Inuse,userswillnotopen7or8documentsatatime,andwillnotchangeoneofthedocumentswithafewwords.Mostusersopenoneortwodocumentsandthenprocessthemforalongtimewithoutdoingotherthings.Inthisway,thedatainthememorywillbeconcentratedinonearea,anditcanbecentrallyprocessedbytheCPU.

Consideringfromtheprogramcode,designersusuallytrytoavoidprogramjumpsandbranches,sothattheCPUcanprocesslargepiecesofcontinuousdatawithoutinterruption.Games,simulations,andmultimediaprocessingprogramsareusuallyrepresentativesofthisaspect,whichcontinuouslyprocesslargeblocksofdatawithsmallpiecesofcode.Butinofficeapplications,thesituationisdifferent.Changingfonts,formatting,andsavingdocumentsallrequiredifferentpartsoftheprogramcodetowork,andtheinstructionsusedareusuallynotinacontinuousarea.SotheCPUhastojumparoundinmemorytofindthecodeitneeds.Thismeansthatforofficeprograms,alargercacheisneededtoreadinmostfrequentlyusedcodesandputtheminacontiguousarea.Ifthecacheisnotenough,youneedthedatainthememory,andifthecacheislargeenough,allthecodecanbeputin,andyoucangetthehighestefficiency.Inthesameway,high-enddataapplicationsandgameapplicationsrequireahighercapacitycache.

CPUCache

CPUCache(CacheMemory)isatemporarymemorylocatedbetweentheCPUandthememory.Itscapacityismuchsmallerthanthememorybuttheexchangerateisfasterthanthememory.many.TheappearanceofthecacheismainlytosolvethecontradictionbetweentheCPUoperationrateandthememoryreadandwriterate,becausetheCPUoperationrateismuchfasterthanthememoryreadandwriterate,whichwillmaketheCPUspendalongtimewaitingforthedatatoarriveorwritethedataintothememory.Thedatainthecacheisasmallpartofthememory,butthissmallpartisabouttobeaccessedbytheCPUinashorttime.WhentheCPUcallsalargeamountofdata,itcanavoidthememoryandcallitdirectlyfromthecache,therebyspeedingupthereadingrate..ItcanbeseenthataddingcachetotheCPUisanefficientsolution,sothattheentireinternalmemory(cache+memory)becomesahigh-speedstoragesystemwithbothcacheandmemory.ThecachehasagreatimpactontheperformanceoftheCPU,mainlyduetotheCPU'sdataexchangesequenceandthebandwidthbetweentheCPUandthecache.

ThecachebasicallyusesSRAMmemory.SRAMistheabbreviationofEnglishStaticRAM.Itisamemorywithstaticaccessfunction.Itcansavethedatastoredinitwithoutrefreshingthecircuit.UnlikeDRAMmemory,whichrequiresarefreshcircuit,theDRAMmustberefreshedandchargedeveryonceinawhile,otherwisetheinternaldatawilldisappear,soSRAMhashigherperformance,butSRAMalsohasitsshortcomings,thatis,itsintegration.Lower,DRAMmemoryofthesamecapacitycanbedesignedintoasmallervolume,butSRAMrequiresalargevolume,whichisalsoanimportantreasonwhythecachecapacitycannotbemadetoolarge.Itscharacteristicsaresummarizedasfollows:Theadvantagesareenergysaving,fastspeed,noneedtocooperatewiththememoryrefreshcircuit,andcanimprovetheoverallworkefficiency.Thedisadvantagesarelowintegration,largevolumeofthesamecapacity,andhighprice,whichcanonlybeusedinasmallamountforthekey.Sexualsystemtoimproveefficiency.

Workingprinciple

1.Readingorder

WhentheCPUwantstoreadapieceofdata,itfirstlooksintheCache,ifIfitisfound,itwillbereadimmediatelyandsenttotheCPUforprocessing;ifitisnotfound,itwillbereadfromthememoryatarelativelyslowspeedandsenttotheCPUforprocessing.Atthesametime,thedatablockwherethedataislocatedcanbetransferredtotheCache,whichcanmakesubsequentadjustments.TheblockdataisreadfromtheCache,andthereisnoneedtocallthememory.

ItisthisreadmechanismthatmakesthehitrateofCPUreadCacheveryhigh(mostCPUscanreachabout90%),whichmeansthat90%ofthedatatobereadbytheCPUnexttimeareinIntheCache,onlyabout10%needtobereadfrommemory.ThisgreatlysavesthetimefortheCPUtodirectlyreadthememory,andalsomakestheCPUbasicallynoneedtowaitwhenreadingdata.Ingeneral,theorderinwhichtheCPUreadsdataisCachefirstandthenmemory.

2,CacheClassification

IntelhasseparatedCachefromPentium,whichisusuallydividedintofirst-levelcacheL1andsecond-levelcacheL2.Inthepastconcept,L1CacheisintegratedintheCPUandiscalledon-chipCache.InL1,therearealsodataCache(D-Cache)andinstructionCache(I-Cache).Theyarerespectivelyusedtostoredataandexecuteinstructionsforthesedata,andthetwoCachescanbeaccessedbytheCPUatthesametime,reducingconflictscausedbycompetingCachesandimprovingprocessorperformance.

3.Readhitrate

TheCPUfindsusefuldataintheCacheiscalledahit.WhenthereisnodataneededbytheCPUintheCache(Atthistime,itiscalledamiss),theCPUonlyaccessesthememory.Theoretically,inaCPUwithLevel2Cache,thehitrateforreadingL1Cacheis80%.Thatistosay,theusefuldatafoundbytheCPUfromtheL1Cacheaccountsfor80%ofthetotaldata,andtheremaining20%​​isreadfromtheL2Cache.Duetotheinabilitytoaccuratelypredictthedatatobeexecuted,thehitrateofreadingL2isalsoabout80%(readingusefuldatafromL2accountsfor16%ofthetotaldata).Thentheremainingdatahastobecalledfrommemory,butthisisalreadyafairlysmallpercentage.Insomehigh-endCPUs(likeIntel’sItanium),weoftenhearL3Cache,whichisdesignedfordatathatmissesafterreadingL2Cache—akindofCache.AmongCPUswithL3Cache,thereareonlyabout5%Ofthedataneedstobecalledfrommemory,whichfurtherimprovestheefficiencyoftheCPU.

Level1Cache

Level1Cache(Level1Cache)isreferredtoasL1Cache.ItislocatednexttotheCPUcore.ItistheCPUcachethatismostcloselyintegratedwiththeCPU,anditisalsotheearliestinhistory.CPUcache.Becausethetechnicaldifficultyandmanufacturingcostofthefirst-levelcachearethehighest,theincreasedtechnicaldifficultyandcostincreasebroughtaboutbyincreasingthecapacityareverylarge,buttheperformanceimprovementbroughtbyitisnotobvious,thecostperformanceisverylow,andtheexistingfirst-levelcachehitsTherateisalreadyveryhigh,sothefirstlevelcacheisthesmallestofallcaches,muchsmallerthanthesecondlevelcache.

Thefirstlevelcachecanbedividedintothefirstleveldatacache(DataCache,D-Cache)andthefirstlevelinstructioncache(InstructionCache,I-Cache).Thetwoareusedtostoredataanddecodetheinstructionsthatexecutethesedatainrealtime,andbothcanbeaccessedbytheCPUatthesametime,reducingconflictscausedbycontentionforCache,andimprovingprocessorperformance.ThefirstleveldatacacheandthefirstlevelinstructioncacheofmostCPUshavethesamecapacity.Forexample,AMD’sAthlonXPhasa64KBlevelonedatacacheanda64KBleveloneinstructioncache.Thefirstlevelcacheisrepresentedby64KB+64KB,AndtherestoftheCPU'sL1cacherepresentationmethodcanbededucedbyanalogy.

Intel'sCPUwithNetBurstarchitecture(themosttypicalisPentium4)hasaspeciallevelofcache,usinganewlyaddedleveloftracecache(ExecutionTraceCache,T-CacheorETC))Toreplacethefirst-levelinstructioncache,withacapacityof12KμOps,whichmeansthatitcanstore12Kor12000decodedmicro-instructions.Theoperatingmechanismofthefirst-leveltrackingcacheandthefirst-levelinstructioncacheisdifferent.Thefirst-levelinstructioncacheonlydecodesinstructionsinrealtimeanddoesnotstoretheseinstructions,whilethefirst-leveltrackingcachealsodecodessomeinstructions.Instructionsarecalledmicro-ops,andthesemicro-instructionscanbestoredinthefirst-leveltracecache,andthereisnoneedtodecodetheprogrameverytime.Therefore,thefirst-leveltracecachecaneffectivelyincreasethenumberofinstructionsunderhighoperatingfrequency.Thedecodingcapabilityofthemicro-ops,andμOpsismicro-ops,whichmeansmicro-operation.Itprovidesμopstotheprocessorcoreataveryhighrate.TheIntelNetBurstmicro-architectureusesanexecutiontrackingcachetoseparatethedecoderfromtheexecutionloop.Thistracecacheprovidesuopstothecorewithahighbandwidth,whichisessentiallysuitableformakingfulluseoftheinstruction-levelparallelmechanisminthesoftware.Intelhasnotannouncedtheactualcapacityofthefirst-leveltrackingcache,butonlyknowsthatthefirst-leveltrackingcachecanstore12,000micro-ops(micro-ops).Therefore,youcannotsimplyusethenumberofmicroinstructionstocomparethesizeoftheinstructioncache.Infact,thesingle-coreNetBurstarchitectureCPUusing8Kμopscacheisbasicallyenough,andtheextra4kμopscangreatlyimprovethecachehitrate.Ifyouwanttousehyper-threadingtechnology,12KμOpswillbesomewhatinsufficient,whichiswhysometimesIntelprocessorswillcauseperformancedegradationwhenusinghyper-threadingtechnology.Forexample,theNorthwoodcore'sfirst-levelcacheis8KB+12KμOps,whichmeansitsfirst-leveldatacacheis8KB,andthefirst-leveltrackingcacheis12KμOps;andthePrescottcore'sfirst-levelcacheis16KB+12KμOps,whichmeansitsfirst-leveldatacacheis16KB,Thefirst-leveltrackingcacheis12KμOps.Here,12KμOpsisdefinitelynotequalto12KB,andtheunitsarealldifferent,oneisμOpsandtheotherisByte(byte),andtheiroperatingmechanismsarecompletelydifferent.SothosewhosimplyaddthefirstlevelcacheofIntel'sCPU,forexample,saythattheNorthwoodcoreisa20KBfirst-levelcache,andthePrescottcoreissaidtobea28KBfirst-levelcache,andbasedonthis,itisconsideredthatthefirst-levelcachecapacityofIntelprocessorsisfarTheviewthattheprimarycachecapacityofAMDprocessorsislowerthan128KBiscompletelywrong,andthetwoarenotcomparable.InthecomparisonofCPUswithdifferentarchitectures,itisdifficultformanycachestofindthecorrespondingthings.Evencacheswithsimilarnameshavedifferentdesignideasandfunctiondefinitions.Atthistime,simplearithmeticadditioncannotbeusedforcomparison;andinthearchitectureInaverysimilarCPUcomparison,itmakessensetocomparethecachesizesofvariousfunctionsseparately.

Level2cache

Level2cache,itissomebuffermemoryinsidetheprocessor,itsfunctionisthesameasmemory.Datingbacktothe1980s,astheprocessorwasrunningfasterandfaster,slowly,thespeedatwhichtheprocessorneededtoreaddatafromthememorybecamehigherandhigher.However,therateofincreaseofthememoryspeedisveryslow,andthepriceofthememorythatcanreadandwritedataathighspeedisveryhighandcannotbewidelyadopted.Fromtheperspectiveofperformance-priceratio,Intelandotherprocessordesignandproductioncompanieshavecomeupwithasolution,whichistouseasmallamountofhigh-speedmemoryincombinationwithalargeamountoflow-speedmemorytoprovidedatafortheprocessortogether.Inthisway,theoptimalperformanceandcostofusearebothconsidered.Thosehigh-speedmemoryarecalledbuffermemory,or"cache"forshort,becausetheyarelocatedbetweenthecpuandthememoryandarealsotheplacewheredataistemporarilystored.Itsfunctionislikeaplacewheregoodsaretemporarilystackedinawarehouse.Whenthegoodsareplacedfromthetransportvehicle,theyaretemporarilystackedinthebufferarea,andthenmovedtotheinternalstorageareaforlong-termstorage.Thegoodsarestoredinthisareaforashorttime,whichisatemporarycargoyard.Initially,thecachewasonlylevelone,buttheprocessorspeedincreasedandthelevelonecachewasnotenough,sothesecondlevelcachewasadded.Thesecond-levelcacheisamemorywithaslowerspeedandalargercapacitythanthefirst-levelcache.Itismainlyusedfortemporaryexchangeofdatabetweenthefirst-levelcacheandthememory.Inordertoadapttothefasterprocessorp4ee,thethird-levelcachehasappeared.Itscapacityislargerandthespeedisslowerthanthesecond-levelcache,butitismuchfasterthanthememory.Theappearanceofthecachehasgreatlyimprovedtheoperatingefficiencyofthecpuprocessor.Thisareastoresdatathatisfrequentlyusedbythecpu.Therefore,thelargerthecache,thehighertheefficiencyoftheprocessor.Atthesametime,thephysicalstructureofthecacheislargerthanthatofthememory.Alotofcomplexity,soitscostisalsoveryhigh.

Theresultofextensiveuseofsecondarycacheistheimprovementofprocessoroperatingefficiencyandthesubstantialincreaseincostandprice.Forexample,thecoresoftheXeonprocessorusedontheserverandtheordinaryp4processorarebasicallythesame,thatis,thesecond-levelcacheisdifferent.Xeon'ssecond-levelcacheis2mb-16mb,p4'ssecond-levelcacheis512kb,sothecheapestXeonisalsomoreexpensivethanthemostexpensivep4,thereasonisthatthesecond-levelcacheisdifferent.Thatisl2cache.DuetothelimitationoftheL1levelcachecapacity,inordertoincreasethecomputingspeedofthecpuagain,ahigh-speedmemory,namelytheleveltwocache,isplacedoutsidethecpu.Theworkingfrequencyismoreflexible,anditcanbethesamefrequencyasthecpuordifferent.Whenthecpureadsdata,itfirstlooksinl1,thenfroml2,thenthememory,andthentheexternalmemory.Therefore,theimpactofl2onthesystemcannotbeignored.

Theearliestcpucacheisawhole,andthecapacityisverylow,Intelhasclassifiedthecachesincethepentiumera.Atthattime,thecacheintegratedinthecpucorewasnolongersufficienttomeettheneedsofthecpu,andthelimitationsonthemanufacturingprocesscouldnotgreatlyincreasethecapacityofthecache.Therefore,thereisacacheintegratedonthesamecircuitboardasthecpuoronthemotherboard.Atthistime,thecacheintegratedwiththecpucoreiscalledthefirst-levelcache,andtheexternaloneiscalledthesecond-levelcache.Withthedevelopmentofthecpumanufacturingprocess,thesecond-levelcachecanalsobeeasilyintegratedintothecpucore,andthecapacityisalsoincreasingyearbyyear.Itisnolongeraccuratetodefinethefirstandsecondlevelcacheswhethertheyareintegratedinthecpuornot.Andasthesecond-levelcacheisintegratedintothecpucore,thepreviousdivisionofthesecond-levelcacheandthecpuhasbeenchanged.Atthistime,itworksatthesamerateasthemainfrequency,whichcanprovideahighertransmissionrateforthecpu..

Three-levelcache

L3Cache(three-levelcache)isdividedintotwotypes,theearlyonewasexternal,andgraduallybecamebuilt-in.AnditsactualeffectisthattheapplicationofL3cachecanfurtherreducememorylatency,andatthesametimeimprovetheperformanceoftheprocessorwhencomputinglargeamountsofdata.Reducingmemorylatencyandimprovingthecomputingpoweroflargeamountsofdataareveryhelpfulforgames.TheadditionofL3cacheintheserverfieldstillhasasignificantimprovementinperformance.Forexample,aconfigurationwithalargerL3cachewillusephysicalmemorymoreefficiently,soitsslowerdiskI/Osubsystemcanhandlemoredatarequests.ProcessorswithlargerL3cachesprovidemoreefficientfilesystemcachingbehaviorandshortermessageandprocessorqueuelengths.

Infact,theearliestL3cachewasappliedtotheK6-IIIprocessorreleasedbyAMD.Atthattime,theL3cachewaslimitedbythemanufacturingprocessandwasnotintegratedintothechip,butintegratedonthemotherboard.Infact,theL3cache,whichcanonlybesynchronizedwiththesystembusfrequency,isnotmuchdifferentfromthemainmemory.Later,theL3cachewasusedbyIntel'sItaniumprocessorfortheservermarket.ThenthereareP4EEandXeonMP.IntelalsoplanstointroduceanItanium2processorwith9MBL3cacheandadual-coreItanium2processorwith24MBL3cacheinthefuture.

ButbasicallytheL3cacheisnotveryimportanttotheperformanceimprovementoftheprocessor.Forexample,theXeonMPprocessorwith1MBL3cacheisstillnotOpteron'sopponent.Itcanbeseenthattheincreaseinfront-sidebusisbetterthanIncreasedcachebringsmoreeffectiveperformanceimprovement.

SuperCache

SuperCache,alsoknownasSuperCache,thespeedbottleneckofthecomputerismainlythereadandwritespeedofthemechanicalharddisk.SuperCacheuseshigh-speedmemoryfortheharddiskreadandwriteasacache.Itisthefirstchoiceforspeedinguplargememorymachinesandanindispensabletoolforservers.

Workingprinciple:ForSuperCache,thereisnoconceptoffilesontheharddisk.Itisjustasmallgridofauser-specifiedsize,suchas32k.Thecontentofasmallgridontheharddiskisread,thenItiscachedinthememory,andthenexttimethissmallgridisread,itisreaddirectlyfromthememorywithoutanyactionontheharddisk,thusachievingthepurposeofacceleration.Therearetwocachemodes,1.MFUmode,wheneachsmallgridisread,asimplecountismade.Whenthecacheisfull,thesmallercountvaluewillbeclearedoutofthecachefirst;2.MRUmode,simpleQueue,firstinfirstout.

Systemcache

ComparingtheCPUtoafurniturefactoryinthecity,andcomparingthestoragesystemtoawoodfactoryinthesuburbs,theactualsituationisthatthewoodfactoryisgettingawayfromthefurniturefactory.Evenifalargertruckisusedtotransportthewood,thefurniturefactoryhastostopworkandwaitforthewoodtoarrive.Insuchasituation,onesolutionistobuildasmallwarehouseintheurbanareaandplacesomewoodmaterialsmostcommonlyusedbyfurniturefactories.Thiswarehouseisactuallythe"Cache"ofthefurniturefactory,andthefurniturefactorycancontinuouslydeliverthewoodneededintimefromthewarehouse.Ofcourse,thelargerthewarehouseandthemorewoodstored,thebettertheeffect,becauseeventhelesscommonlyusedthingscanbefoundinthewarehouse.Ifthereisnowoodinthewarehouse,wewillcontinuetolookforitfromthewoodfactoryoutsidethecity,andthefurniturefactorywillhavetowait.ComparedwiththeL1cache,thewarehousecanbereadandwrittenintimeandquicklybytheCPU,soitstoresthemostcommonlyusedcodesanddataoftheCPU(howtoselectthe"mostcommonlyused"willbeintroducedlater).TheL1cacherateismuchfasterthansystemmemorybecauseitusesSRAM,whichusesfourtosixtransistorsonasinglechipofmemory.ThisalsomakesthecostofSRAMquitehigh,soitcannotbeusedintheentirestoragesystem.OnmostCPUs,theL1cacheandthecoreareonthesamechip.Inthecaseofafurniturefactory,itislikeafactoryandawarehouseonthesamestreet.ThisdesignallowstheCPUtogetdatafromthenearestandfastestplace,butitalsomakesthedistancebetweenthe"woodfactoryoutsidethecity"andthe"warehouse"andthe"furniturefactory"almostfaraway.Inthisway,thedatarequiredbytheCPUisnotintheL1cache,thatis,"CacheMiss",andittakesalongtimetofetchdatafromthestoragedevice.Thefastertheprocessorspeed,thegreaterthegapbetweenthetwo.Usingahigh-frequencyprocessorlikePentium4,gettingdatafromthememoryisequivalenttothe"timberfactory"locatedinanothercountry.

Infact,thecacheisapartoftheCPU.ItexistsintheCPUatwhichtheCPUaccessesdataataveryfastrate.Itcanaccessandprocessonebillioninstructionsanddatainonesecond(term:CPUfrequency1G),andthememoryismuchslower.Fastmemorycanreachtensofmegabytes.Itcanbeseenhowthespeeddifferencebetweenthetwois.ThebigcacheistosolvetheproblemofthedifferencebetweentheCPUspeedandthememoryspeed.ThememoryisthemostaccessedbytheCPU.FrequentdataandinstructionsarecopiedintothecacheintheCPU,sothattheCPUcannotoftenfetchdatafromtheslowmemorylikea"snail".TheCPUonlyneedstofetchitfromthecache,andthecacherateisfasterthanMemoryismuchfaster.Specialpointstobepointedouthereare:1.Becausethecacheisonlyacopyofasmallpartofthedatainthememory,whentheCPUlooksfordatainthecache,itwillnotbefound(becausethedataisnotcopiedfromthememorytotheCache).Atthistime,theCPUwillstillfinddatainthememory,sothesystemspeedwillslowdown,buttheCPUwillcopythedatatothecachesothatitwillnotberetrievedfromthememorynexttime.2.Astimechanges,themostfrequentlyaccesseddataisnotstatic,thatistosay,thedatathatisnotfrequentlyaccessedjustnowneedstobeaccessedfrequently.Justnowitwasthemostfrequentlyaccesseddata,andthenitwasnot.Frequent,sothedatainthecacheshouldalwaysbereplacedaccordingtoacertainalgorithm,soastoensurethatthedatainthecacheisthemostfrequentlyaccessed3.Regardingthefirstlevelcacheandthesecondlevelcache,inordertodistinguishthesetwoconcepts,wefirstUnderstandtherelativerelationshipbetweenRAMandROM.RAMistheonewhoseinformationdisappearsafterpowerfailure,andROMistheonewhoseinformationwillnotdisappearevenafterpowerfailure.RAMisdividedintotwotypes:oneisstaticRAMandSRAM;theotherisdynamicRAMandDRAM.

Diskcache

Diskcacheisdividedintoreadcacheandwritecache.Readcachemeansthattheoperatingsystemkeepsthefiledatathathasbeenreadinthememoryspacewhenthememoryisrelativelyfree(thismemoryspaceiscalledthe"memorypool"),andthenexttimethesoftwareortheuserreadsthesameThefiledoesnothavetobereadfromthediskagain,therebyincreasingthespeed.Thewritecacheactuallysavesthedatatobewrittentothediskinthememoryspaceallocatedbythesystemforthewritecache.Whenthedatasavedinthememorypoolreachesacertainlevel,thedataissavedtotheharddisk.Thiscanreduceactualdiskoperations,effectivelyprotectthediskfromdamagecausedbyrepeatedreadandwriteoperations,andreducethetimerequiredforwriting.

Accordingtothedifferentwritingmethods,therearetwotypes:write-throughandwrite-back.Whenreadingtheharddiskdatainthewritegeneralmode,thesystemfirstcheckstherequestcommandtoseeiftherequireddataisinthecache.Ifso,thecachesendstheresponsedata.Thisprocessiscalledahit.Inthisway,thesystemdoesnothavetoaccessthedataintheharddisk.SincethespeedofSDRAMismuchfasterthanthatofmagneticmedia,thespeedofdatatransmissionisaccelerated.Thewrite-backtypeistofindthedatainthecachewhentheharddiskdataiswritten,andwhenthedataisfound,thecachewillwritethedatatothedisk.Mostharddisksusethewrite-backcache,whichgreatlyimprovestheperformance.TheEnglishnameofthecacheisCache.CPUcacheisalsoakindofmemory,withfastdataexchangerateandhighfrequencyofoperation.Diskcacheisamemoryareaallocatedinordinaryphysicalmemorybytheoperatingsystemfordiskinputandoutput.

Theharddiskbuffer,theharddiskbufferistheplacewheretheharddiskexchangesdatawiththeexternalbus.Theprocessofharddiskreadingdataistoconvertmagneticsignalsintoelectricalsignals,fillandemptythebufferagainandagain,fillagain,andthenempty,stepbystepaccordingtothecycleofthePCIbus.Itcanbeseenthattheroleofthebufferisveryimportant.of.Itsroleisalsotoimproveperformance,butitisdifferentfromthecachein:1.Itisafixed-capacityhardware,unlikethecachethatcanbedynamicallyallocatedinthememorybytheoperatingsystem.Second,itsimpactonperformancegreatlyexceedstheimpactofdiskcachingonperformance.Becausethereisnobuffer,itwillberequiredtoreadorwritetothediskeverytimeaword(usually4bytes)istransferred.

Cachemapping

Cachecanbedividedintodirectmappingcache,groupassociativecacheandfullyassociativecache.

Directmappingcache

Inthistypeofcache,eachgrouphasonlyonerow,E=1,andthestructureisverysimple.Theentirecacheisequivalenttoaone-dimensionalarrayofgroups.Thelinereplacementinthecaseofamissisalsoverysimple,justoneline,whichisnotthereplacementofthehit.Inordertoadapttothesmallcapacity,acertaindatablockinthen+1thlayerofmemorycanonlybereplacedbyasubsetofacertainlocationintheupperlayer(thatis,thenthlayer)ofmemory.Assumingadirectlymappedcache,(S,E,B,m)=(4,1,2,4),thatistosay,theaddressis4bits(16),therearefourgroups,eachgroupisonerow,Twobytesperblock.Sincethereare16addresses,representing16bytes,thereare8blocksintotal,butthereareonly4groups,thatis,4rows.Onlymultipleblockscanbemappedtothesamecachegroup.Forexample,0and4aremappedtogroup1,1and5aremappedtogroup2,andsoon.Herecomestheproblem.Forexample,whenblock0isreadfirst,thedataofblock0iscachedtogroup0.ThenIreadblock4again,becauseblock4isalsomappedtogroup0,andgroup0hasonlyonerow,sothedataofthepreviousblock0willbeoverwritten.IfIreadblock0later,thedatawillbelost.Cangotothelower-levelmemorytofindit.Intheactualcycleprogram,itiseasytocausethissituation,whichiscalledjitter.Theexistenceofthissituationnaturallygreatlyaffectstheperformance.Therefore,abettermappingschemeisneeded.

Groupassociativecache

Inthegroupassociativecache,Eisgreaterthan1,whichmeansthattherearemultiplecachelinesinagroup.AsmuchasEisequalto,itiscalledasmanypaths,soitiscalledEpathgroupconnection.

Thematchingofgroup-associatedrowsisabitmorecomplicated,becausethemarkbitandvalidbitofmultiplerowsneedtobechecked.Ifyoufinditintheend,it'sokay.Ofcourse,therowcontainingtherequireddatawillberemovedfromthenextlevelofstorageforreplacementifitcannotbefound,butwithsomanyrowsinagroup,whichrowtoreplace.Ifthereisablankline,itisnaturaltoreplacetheblankline.Ifthereisnoblankline,thensomeotherreplacementstrategiesaretriggered.Inadditiontotherandomstrategyintroducedjustnow,therearealsotheleastfrequentlyusedstrategies,andtheleastrecentlyusedstrategies.Thesestrategiesthemselvesrequireacertainamountofoverhead,butyoumustknowthattheoverheadofmissesisverylarge,soinordertoensurethehitrate,itisworthwhiletoadoptsomerelativelycomplicatedstrategies.

Fullyassociativecache

Theso-calledfullyassociativecacheisacachecomposedofagroupcontainingallcachelines(blockscanbeplacedanywhereinthecache).Sincethereisonlyonegroup,thegroupselectionisparticularlysimple.Atthistime,theaddressdoesnothaveagroupindex,onlythemarkandoffset,thatis,thetpartandthebpart.Theothersteps,rowmatchinganddataselection,andtheprincipleofgroupassociationarethesame,butthescaleismuchlarger.Iftheabovedescriptionofthesethreemappingmethodsisveryabstract,inordertobeabletounderstandmorethoroughly,comparethememorytoalargesupermarket,thethingsinthesupermarketarebytesordata.Inordertomakeiteasytoseedelicious,funandpopularthings,thesupermarketcanputthesethingstogetherinaspecialrecommendationcounter,whichisthecache.Ifyoujustputthesegoodsonthecounterandyouaredone,thenthisisacompletelyrelatedway.

Butifyouwanttofindwhatyouwant,youhavetolookfortheserecommendedgoods,andbecauseoftheuncertainlocation,youmayevensearchtheentirerecommendationcounter.Thisefficiencyisundoubtedlynothigh.Sothemanagerofthesupermarketdecidedtoadoptanothermethod,whichistodivideallrecommendedgoodsintomanycategories,suchas"jambiscuits","chocolatebiscuits","walnutmilk",etc.,andstoreonekindofgoodsoneachfloorofthecounter.Thisistheprincipleofdirectassociationaccess.Theadvantageofthisisthatitiseasyforcustomerstohaveatargeted,quickerandmoreeffectivesearch.

Butthismethodstillhasitsdisadvantages,thatis,iftherearemanycustomerswhoneedjambiscuits,andtherearerelativelyfewcustomerswhoneedchocolatebiscuits,obviouslythedemandforjambiscuitswillbefarmorethanthatofchocolatebiscuits.Thedemand,butthespaceforplacingthetwotypesofbiscuitsisthesame,sothissituationmayoccur:thestoragespaceforjambiscuitsisfarfrommeetingthemarketdemand,andthestoragespaceforchocolatebiscuitsisleftunused.Inordertoovercomethisshortcoming,thebossdecidedtoimprovetheinventorymethod:orclassifythegoods,buttheclassificationmethodhaschanged,accordingto"biscuits","milk","juice"andothercategoriesofinventory,thatis,nomatterwhatkindofbiscuitscanbeStoredinthespaceusedby"biscuits",thismethodobviouslyimprovesthesufficiencyofspaceutilizationandmakesstorageandsearchmethodsmoreflexible.

Technicalindicators

InCPUproducts,thecapacityofthefirstlevelcacheisbasicallybetween4kband64kb,andthecapacityofthesecondlevelcacheisdividedinto128kb,256kb,512kb,1mb,2mbWait.Thereisnotmuchdifferencebetweenthefirst-levelcachecapacityofeachproduct,andthesecond-levelcachecapacityisthekeytoimprovingcpuperformance.Theincreaseinthecapacityofthesecond-levelcacheisdeterminedbythecpumanufacturingprocess.Theincreaseincapacitywillinevitablyleadtoanincreaseinthenumberofinternaltransistorsinthecpu.Tointegratealargercacheonalimitedcpuarea,therequirementsforthemanufacturingprocesswillbehigher./p>

CachesizeisoneoftheimportantindicatorsofCPU,anditsstructureandsizehaveagreatinfluenceonCPUspeed.Simplyput,thecacheisusedtostoresomecommonlyusedorabouttobeuseddataorinstructions.Whenthesedataorinstructionsareneeded,theyaredirectlyreadfromthecache.Thisismuchfasterthanreadingfromthememoryoreventheharddisk.Significantlyincreasetheprocessingrateofthecpu.Theso-calledprocessorcacheusuallyreferstothesecondarycache,orexternalcache.Thatis,thehigh-speedbuffermemoryisasmall-scalebuthigh-speedmemorylocatedbetweentheCPUandthemainmemorydram(dynamicram),usuallycomposedofsram(staticrandomaccessmemory).Usedtostoredatathatisfrequentlyusedbythecpu,sothatthecpudoesnothavetorelyontheslowerdram(dynamicrandomaccessmemory).L2cachehasalwaysbeenatypeofmemorywithextremelyfastspeedandveryexpensiveprice,calledsram(staticram),sram(staticram)istheEnglishabbreviationofstaticmemory.Becausesramusesthesamesemiconductorprocessasmakingcpu,comparedwithdynamicmemorydram,sramhasafasteraccessrate,butithasalargervolumeandahighprice.

Thebasicideaof​​theprocessorcacheistouseasmallamountofsramasthebufferbetweenthecpuandthedramstoragesystem,thatis,thecachesystem.Anotablefeatureof80486andhigher-endmicroprocessorsisthattheprocessorchipintegratessramasacache.Becausethesecachesareinstalledinthechip,theyarecalledon-chipcaches.Thecachecapacityofthe486chipisusually8k.High-endchipssuchaspentiumare16kb,andpowerpcscanreach32kb.Thepentiummicroprocessorfurtherimprovestheon-chipcache,usingdataanddual-channelcachetechnology.Relativelyspeaking,theon-chipcachehasasmallcapacity,butitisveryflexibleandconvenient,whichgreatlyimprovestheperformanceofthemicroprocessor.On-chipcacheisalsocalledlevelonecache.Duetothehighclockfrequencyofhigh-endprocessorssuchas486and586,oncethefirstlevelcachemisses,theperformancewillbesignificantlydeteriorated.Inthiscase,themethodusedistoaddacacheinadditiontotheprocessorchip,whichiscalledasecondarycache.Thesecondarycacheisactuallytherealbufferbetweenthecpuandthemainmemory.Sincetheresponsetimeonthesystemboardismuchlowerthantherateofthecpu,itisimpossibletoachievetheidealrateofhigh-endprocessorssuchas486and586withoutthesecondarycache.Thecapacityofthesecond-levelcacheshouldgenerallybemorethananorderofmagnitudelargerthanthatofthefirst-levelcache.Inthesystemsettings,usersareoftenrequiredtodeterminewhetherthesecondarycacheisinstalledandthesize.Thesizeofthesecondarycacheisgenerally128kb,256kbor512kb.Inmicrocomputersabove486,256kbor512kbsynchronouscacheiscommonlyused.Theso-calledsynchronizationmeansthatthecacheandcpuusethesameclockcycleandworksynchronouslyatthesamerate.Comparedwithasynchronouscache,theperformancecanbeimprovedbymorethan30%.OneofthedevelopmenttrendsofthepcanditsserversystemisthattheCPUfrequencyisgettinghigherandhigher,thesystemarchitectureisgettingmoreandmoreadvanced,andtheimprovementofthestructureandaccesstimeofthemainmemorydramisslower.Therefore,thecachetechnologyisbecomingmoreandmoreimportant,andthecacheisgettingbiggerandbiggerinthepcsystem.ThemajorityofusershaveregardedcacheasanimportantindicatorforevaluatingandpurchasingPCsystems.

Opticaldrivecache

Opticalstoragedriveshaveinternalbuffersorcachememory.Thesebuffersareactualmemorychips,mountedonthecircuitboardofthedrive,whichmayprepareorstorelargerdatasegmentsbeforesendingdatatothePC.ThetypicalbuffersizeforCD/DVDis128KB,butthespecificdrivecanbelargeorsmall(usuallythemorethebetter).ArecordableCDorDVDdrivegenerallyhasalarge-capacitybufferof2MB-4MBormoretopreventbufferunderrunerrorsandatthesametimemaketherecordingworksmoothandconstantwriting.Generallyspeaking,thefasterthedrive,themorebuffermemorytohandlethehighertransferrate.

CD/DVDdriveswithbufferingorcachinghavemanyadvantages.BufferingcanensurethatthePCreceivesdataatafixedrate.Whenanapplicationrequestsdatafromthedrive,thedatamaybelocatedindifferentplacesscatteredonthedisc.Becausetheaccessrateofthedriveisrelativelyslow,thedrivehastosenddatatothePCatintervalswhenreadingdata.Thebufferofthedrivecanreadandpreparethecontentdirectoryoftheopticaldiscinadvanceunderthecontrolofthesoftware,thusspeedingupthefirstdatarequest.

ThelawforCD-ROMdrivetoreaddataistosearchinthecachefirst.Ifitisnotfoundinthecache,itwillsearchonthedisc.Thelarge-capacitycachecanreadmoredatainadvance,butinpracticalapplicationsInCD-ROM,DVD-ROMandotherreadoperations,thechanceofreadingrepeatedinformationisrelativelysmall.Mostoftheopticaldiscsaremoreoftenreadmorefilesatatime.,TheimportanceofcacheonDVD-ROMdrivesisnotreflected,somostoftheseproductsusesmallercachecapacity.CD-ROMgenerallyhasseveralkindsof128KB,256KB,512KB;andDVDgenerallyhas128KB,256KB,512KB,onlyindividualexternalDVDdriveadoptslargercapacitycache.

OnrecordersorCOMMBOproducts,cachingbecomesveryimportant.Whenburningadisc,thesystemwillpre-readthedatathatneedstobeburnedintothecache,andthenreadthedatafromthecacheforburning.Thecacheisthebridgebetweenthedataandtheburningdisc.Whenthesystemtransfersdatatothecache,itisinevitablethattherewillbeatransmissionpause.Forexample,whenburningalargenumberofsmall-capacityfiles,theharddiskreadingratemaynotkeepupwiththeburningrate,whichwillresultinthedatainthecache.Theinputandoutputarenotproportional.Ifthisstatecontinuesforaperiodoftime,itwillcauseallthedatainthecachetobeoutput,andnoinputwillbeobtained.Atthistime,itwillcauseacacheunderloaderror,whichwillleadtoafailuretoburnthedisc.Therefore,therecorderandCOMMBOproductswillusealargercachecapacity,coupledwiththeanti-engravingtechnology,canminimizetheprobabilityofburningabaddisk.Atthesametime,thecachecanalsocoordinatethedatatransmissionratetoensurethestabilityandreliabilityofdatatransmission.

Burnerproductsgenerallyhave2MB,4MB,8MB,andCOMBOproductsgenerallyhave2MB,4MB,8MBcachecapacity.Duetothelimitationofmanufacturingcost,thecachecannotbemadelargeenough.Buttherightamountofcachecapacityisstilloneofthekeystoconsiderwhenchoosingopticalstorage

NetworkCache

Concept

WWWisoneofthemostpopularapplicationsontheInternet,Itsrapidgrowthhascausednetworkcongestionandserveroverload,resultinginincreasedcustomeraccessdelays,andWWWservicequalityhasbecomeincreasinglyapparent.Cachetechnologyisconsideredtobeoneoftheeffectivewaystoreduceserverload,reducenetworkcongestion,andenhancethescalabilityofWWW.Itsbasicideaistousetheprincipleoftemporallocalityofcustomeraccess(TemproralLocality)tostorethecontentaccessedbycustomersintheCacheStoreacopy.Whenthecontentisaccessednexttime,itdoesnotneedtobeconnectedtotheresidentwebsite,butisprovidedbythecopykeptintheCache.

Webcontentcanbecachedontheclientside,proxyserver,andserverside.StudieshaveshownthatcachingtechnologycansignificantlyimproveWWWperformance,anditcanbringthefollowingbenefits:(1)Reducenetworktraffic,therebyreducingcongestion.

(2)Themainreasonsforreducingcustomeraccessdelayare:

①Thecontentcachedintheproxyservercanbeobtaineddirectlyfromtheproxyinsteadoffromtheremoteserver.Reducedtransmissiondelay;

②Thecontentthatisnotcachedcanbequicklyobtainedbycustomersduetonetworkcongestionandthereductionofserverload.

(3)Aspartoftheclient'srequestcontentcanbeobtainedfromtheagent,theloadontheremoteserverisreduced.

(4)Iftheremoteserverfailstorespondtotheclient'srequestduetoaremoteserverfailureornetworkfailure,theclientcanobtainacopyofthecachedcontentfromtheproxy,whichenhancestherobustnessoftheWWWservice.

Webcachingsystemwillalsobringthefollowingproblems:

(1)Thecontentobtainedbytheclientthroughtheproxymaybeoutdated.

(2)Ifacachefailureoccurs,theclient'saccessdelaywillincreaseduetotheadditionalproxyprocessingoverhead.Therefore,whendesigningaWebcachingsystem,weshouldstrivetomaximizethecachehitrateandminimizethecostoffailure.

(3)Theproxymaybecomeabottleneck.Therefore,anupperlimitofthenumberofservicecustomersandalowerlimitofserviceefficiencyshouldbesetforanagent,sothattheefficiencyofanagentsystemisatleastthesameastheefficiencyofaclientdirectlyconnectedtoaremoteserver.

AffecttheInternetaccessrate

TheprocessofaccessingthewebsiteiscompletedbytheHTTPprotocolbuiltontopoftheTCP/IPprotocol.SincetheclientsendsanHTTPrequest,thewaitingtimeexperiencedbytheuserismainlydeterminedbytheresponsetimeoftheDNSandthewebsite.ThedomainnameofthewebsitemustfirstberesolvedtoanIPaddressbytheDNSserver,andthedelayofHTTPisdeterminedbythenumberofround-triptimesbetweentheclientandtheserver.Theround-triptimereferstothetimetheclientwaitsfortheresponseofeachrequest.Theaverageround-triptimedependsonthreeaspects:

WebsiteServerDelay

Thedelaycausedbythewebserveraccountsforthemainproportionoftheroundtriptime.WhenaserverreceivesmultipleconcurrentHTTPrequests,queuingdelaywilloccur.SincerespondingtoanHTTPrequestoftenrequiresmultipleaccesstothelocalharddisk,evenaserverwithasmallloadmayhaveadelayoftensorhundredsofmicroseconds.

Thedelayintroducedbyrouters,gateways,proxyserversandfirewalls

ThereareusuallymultiplenetworksinthepathbetweentheclientandtheserverEquipment,suchasrouters,gateways,proxies,firewalls,etc.Theyallneedtostore/forwardthepassingIPpackets,soqueuingdelayandprocessingdelaywillbeintroduced.Whenthenetworkiscongested,thesedevicesmayevenlosepackets.Atthistime,theyhopethattheclientandserverwillresumecommunicationthroughanend-to-endprotocol.

OndifferentcommunicationlinksDatatransmissionrate

Inawideareanetwork,fromonenetworkdevicetoanothernetworkdeviceThedatatransferratebetweentimeisanimportantfactorindeterminingtheround-triptime.Buttheroleofbasicbandwidthisnotasimportantaspeoplethink.AtestshowsthatwhenawebsiteusesT3speedtoaccesstheInternet,only2%ofwebpagesorobjectscanbeprovidedtotheclientatarateof64kbps,whichisobviouslyShowsthatbandwidthisnotthemostcriticalfactorinnetworkperformance.

TheInternetisextendingtoeverycorneroftheworld.Auser'srequesttoaservermaytraveladistanceof8,000kilometersto16,000kilometers.ThedelaycausedbythespeedoflightandthedelayofnetworkequipmentisthenetworkThemostfundamentalreasonforsuchslowness.

Networkcachingsolvesthefundamentalproblem

Sincethereasonthataffectsthenetworkspeediscausedbydistanceandthespeedoflight,theonlywaytospeedupWebaccessistoshortentheclientThedistancefromthewebsite.Bystoringthepagesandobjectsfrequentlyvisitedbyusersclosertotheuser,thedelayintroducedbythespeedoflightcanbereduced.Atthesametime,thedelayintroducedbyrouters,firewallsandproxiesisalsoreducedduetothereductionoflinksintherouting..

Thetraditionalsolutionistoestablishamirrorservertoachievethepurposeofshorteningthedistance.Butthismethodhasgreatshortcomings.Foracertainsite,itisimpossibletoestablishamirrorsiteclosetoeachusergroup.Itisevenmoreuneconomicaltousethismethodformostofthesites,anditwillbemanagedatthesametime.Andmaintainingmirrorsitesisaverydifficulttask.

NetworkcachingisanemergingnetworktechnologythatreducesInternettrafficandimprovesend-userresponsetime.Itsconceptcomesfromotherareasofcomputersandnetworks.Forexample,thereisacacheinthepopularIntel-basedCPUtoincreasetherateofmemoryaccess;variousoperatingsystemsalsousecachetoincreasetheratewhenaccessingdisks.;Distributedfilesystemsusuallyalsousecachingtoimprovethespeedbetweentheclientandtheserver.

Type

Theremaybetwoformsofcachingofstaticpages:Infact,themaindifferenceiswhethertheCMSitselfisresponsibleforthecacheupdatemanagementoftheassociatedcontent.

1.Staticcaching:Itisastaticpagethatgeneratescorrespondingcontentimmediatelywhennewcontentisreleased.Forexample,onMarch22,2003,aftertheadministratorenteredanarticlethroughthebackgroundcontentmanagementinterface,Andsynchronouslyupdatethelinksontherelevantindexpages.

2.Dynamiccaching:Afterthenewcontentisreleased,thecorrespondingstaticpageisnotgeneratedinadvanceuntilthecorrespondingcontentisrequested,ifthefront-endcacheservercannotfindthecorrespondingcache,itwillsendtheback-endcontentThemanagementserversendsarequest,andthebackgroundsystemgeneratesastaticpageofthecorrespondingcontent.Theusermaybeslowerwhenaccessingthepageforthefirsttime,butinthefuture,itwilldirectlyaccessthecache.

Disadvantagesofstaticcaching:

Complextriggerupdatemechanism:Thesetwomechanismsareverysuitablewhenthecontentmanagementsystemisrelativelysimple.Butforawebsitewithacomplicatedstructurediagramofanetworkcachesystem,thelogicalreferencerelationshipbetweenpagesbecomesavery,verycomplicatedproblem.Themosttypicalexampleisthatanewsitemshouldappearonthenewshomepageand3relatednewstopicsatthesametime.Inthestaticcachemode,eachnewarticleisposted,inadditiontothepageofthenewscontentitself,thesystemneedstobetriggered.Thebrowsergeneratesmultiplenewrelatedstaticpages,andthetriggeringoftheserelatedlogicoftenbecomesoneofthemostcomplexpartsofthecontentmanagementsystem.

Batchupdateofoldcontent:Thecontentpublishedbystaticcacheisdifficulttomodifythecontentofthepreviouslygeneratedstaticpage,sothatwhenusersvisittheoldpage,thenewtemplatewillnottakeeffectatall.

Inthedynamiccachemode,eachdynamicpageonlyneedstobeconcerned,andotherrelatedpagescanbeautomaticallyupdated,whichgreatlyreducestheneedtodesignrelatedpageupdatetriggers.

Thenetworkcachecanbeontheclientsideoronthenetwork,sowedividethecacheintotwocategories:browsercacheandproxycache.

Almostallbrowsershaveabuilt-incache,theyusuallyusetheclient'slocalmemoryandharddisktocompletethecachework,whileallowinguserstocontrolthesizeofthecachedcontent.Browsercachingisanextremecaseofnetworkcaching,becausethecachingislocatedlocallyontheclient.Usuallyaclienthasonlyoneuserorafewsharedcomputerusers,andtheharddiskspacerequiredbythebrowsercacheisusuallyintherangeof5MBto50MB.However,thebrowsercacheisdifficulttosharebetweenusers,andthecachesofdifferentclientscannotcommunicate,sothecontentandeffectsofthecachearequitelimited.

Proxycachingisanindependentapplicationlayernetworkservice,whichismorelikeE-mail,Web,DNSandotherservices.Manyuserscannotonlysharethecache,butalsoaccessthecontentinthecacheatthesametime.Enterprise-levelproxycachesgenerallyneedtobeconfiguredwithhigh-endprocessorsandstoragesystems,usingdedicatedsoftware,therequiredharddiskspaceisabout5MBto50GB,andthememoryis64MBto512MB.

Theproxyisbetweentheclientandthewebsiteserver.Insomecases,thisconnectionisnotallowed.Forexample,ifthewebsiteisinafirewall,theclientmustestablishaTCPconnectionwiththeproxy,andthenTheproxyestablishesaTCPconnectionwiththewebsiteserver.Theproxyactsasadatarelaybetweentheserverandtheclient.TheHTTPrequestsentbytheproxyisslightlydifferentfromthegeneralHTTPrequest,mainlyinthatitcontainsthecompleteURL,notjustthepathoftheURL.

ProxycacheHowitworks

Whentheproxycachereceivesarequestfromtheclient,itfirstcheckstherequestedcontentWhetherithasbeencached.Ifitisnotfound,thecachemustforwardtherequestonbehalfoftheclient,andwhenreceivingthefilefromtheserver,saveitinacertainformonthelocalharddiskandsendittotheclient.

Ifthecontentrequestedbytheclienthasbeencached,therearetwopossibilities:First,thecachedcontentisoutofdate,thatis,thecontentstoredinthecacheexceedsthepresettimelimit,orthewebsiteserverThewebpagehasbeenupdated.Atthistime,thecachewillasktheoriginalservertoverifythecontentinthecache.Eitherupdatethecontentorreturnan"unmodified"message;second,thecachedcontentisnew,thatis,itissynchronizedwiththecontentoftheoriginalwebsite.Thisiscalledacachehit.Atthistime,thecachewillimmediatelysendthesavedcontenttotheclient.

Whentheclient'srequestdoesnothit,itincreasestheprocessingtimeofcachestorageandforwarding.Inthiscase,doesproxycachingstillmakesense?Infact,theproxycachecanestablishmultipleconcurrentTCP/IPconnectionswiththewebsiteserveratthesametimetoobtainthecontentonthewebsiteinparallel.Theexistenceofthecachereducesthenumberofvisitstothewebsiteasawhole,andalsoreducesthenumberofqueuesontheserversideperunittime,sothequeuingdelayofconcurrentconnectionsismuchsmalleratthistime.Excellentcachingcanevenrealizetheprefetchingofrelatedlinksinwebpagestospeeduptheconnectionrate.

ProxycachingStrategy

Whentheoriginalserver’sfilesaremodifiedordeleted,howdoesthecacheknowhowit’ssaved?Isthecopyobsolete?TheHTTPprotocolprovidesbasicsupportforthecacheservice.Itenablesthecachetoquerytheoriginalserverwhetherafileischanged,andifthecachedcopyisoutofdate,itwillbeconditionallydownloaded.Onlywhentheoriginalserverfileexceedsthespecifieddate,anewfilewillbeissued.

However,theloadcausedbythesequeryoperationsonthewebserverisalmostthesameasthatofobtainingthefile,soitisimpossibletoperformsuchoperationswhentheclientinitiatesarequesttothecache.TheHTTPprotocolallowstheservertoselectivelyspecifythelifetimeofeachdocument,thatis,clearlyindicatetheeffectivelifecycleofafile,andtheshortlifetimemeans"don'tcacheit".Theretentiontimeofthecopycanbefixed,oritcanbecalculatedfromthesize,source,timetolive,orcontentofthefile.

Distributedcache

Thedistributedcachesystemistosolvethebottleneckbetweenthedatabaseserverandthewebserver.Ifawebsitehasalotoftraffic,thisbottleneckwillbeveryobvious,andeachdatabasequerywillconsumeaconsiderableamountoftime.Forwebsitesthatarenotupdatedveryquickly,wecanusestaticizationtoavoidexcessivedatabasequeries.Forwebsiteswhoseupdatespeedismeasuredinseconds,staticizationisnottooideal,andacachingsystemcanbeusedtobuildit.Ifonlyasingleserverisusedasacache,theproblemwillnotbetoocomplicated.Iftherearemultipleserversusedasacache,theloadbalancingofthecacheservermustbeconsidered.

UseMemcacheddistributedcachingservicetosavetheuser'ssessiondata,andachievethepurposeofeachfunctionalmodulebeingabletosharetheprivatedatainthissessionacrossprovincesandservers.EachprovinceusesoneserverastheMemcachedservertostorethedatainthesession.Ofcourse,multipleserverscanbeused,butthenumberofMemcachedserversineachprovincemustbethesame,soastoensuretheMemcachedclientTheoperationisthesamepieceofdatatoensuredataconsistency.

Add,delete,andmodifysessiondata

Memcachedclient,whenadding,deleting,andmodifyingsessioninformationdata,youmustnotonlyadd,delete,ModifytheMemcachedserverdatainthisprovince,andatthesametimedothesameoperationonMemcahedserversinotherprovinces,sothatuserscanaccessthesamesessiondatawhenaccessingthefunctionalmodulesofserversinotherprovinces.TheMemcachedclientserverlistusestheintranetIPofthelocalareanetwork(suchas:192.168.1.179)tooperatetheMemcahedserverinthisprovince,andthepublicIP(suchas:202.183.62.210)tooperatetheMemcaheserverinotherprovinces.

Readsessiondata

ThelistofMemcachedclientserversforallmodulesofthesystemtoreadsessiondataaresettotheintranetIPoftheMemcachedserveraddressinthisprovinceToreadthesessiondatafromtheMemcahedserver.

Confirmationofthesamesession

Usecookiestokeepthecustomerintouchwiththeserver.Atthebeginningofeachsession,aGUIDisgeneratedastheSessionIDandstoredinthecookieoftheclient.Thescopeisthetop-leveldomainname,sothatthesecond-levelandthird-leveldomainnamescansharethiscookie,andthesystemusesthisSessionIDtoconfirmwhetheritisthesameAconversation.

TheuniqueIDofthesessiondata

TheuniquekeyofthesessiondatastoredontheMemcachedserver.TheKey,whichistheuniqueIDofthesessiondata,isdefinedas:SessionID_Name,SessionIDistheSessionIDstoredintheclientcookie,andNameisthenameofthesessiondata.TheNameofeachsessiondatainthesamesessionmustbeunique,otherwisethenewsessiondatawilloverwritetheoldsessiondata.

Sessionexpirationtime

Theexpirationofthesessionisachievedbycontrollingtheeffectivetimeofthecookie.ThesessiontimeissettotheSessionIDortheeffectivetimeinthecookie.AndeachtimetheSessionIDisaccessed,theeffectivetimeofthecookiemustbereset,sothattheeffectivetimeofthesessionreachedisthelongesttimefortheSessionIDvalueinthecookiebetweentwovisits.Iftheintervalbetweenthetwovisitsexceedstheeffectivetime,TheCookiesavedintheSessionIDwillbeinvalid,andanewSessionIDwillbegeneratedandstoredintheCookie,theSessionIDchanges,andthesessionends.InvalidationofsessiondataintheMemcachedserver,everytimesessiondataisaddedtotheMemcacheserver,theeffectivetimeissettooneday,whichis24hours,sothattheMemcachedserviceusesitsinternalmechanismtoclearit,andthereisnoneedtospecializethesessiondataintheprogram.Deleteoperation.ThevalidtimeofthedataintheMemcacheserverisonlylogical.Evenafter24hours,ifthememoryallocatedtotheMemcachedserviceissufficient,thedataisstillstoredinthememory,buttheMemcacheclientcannotreadit.OnlywhenthememoryallocatedtotheMemcachedserviceisnotenough,itwillcleanupuselessorrelativelyolddata,thatis,lazycleaning.

Howtoincreasethecache

CPUcache

CPUcacheisdividedintotwolevels:L1(firstlevelcache)andL2(secondlevelcache),whenWhentheprocessorwantstoreaddata,itmustfirstlookintheL1cache,thentheL2cache,andfinallythesystemmemory.Ifonedayyoufindthatyourcomputerisalotslower,andittakesafewminutestoentertheWindowsdesktop,youshouldcheckwhetherthefirstandsecondcachesoftheCPUareturnedon.IntheStandardCMOSSetup(standardCMOSsetting)intheBIOSsettings,twoitemsareusedtoturnonorturnoffthecache:whenCPUInternalCacheissettoEnable,turnonthefirstlevelbufferwithintheCPU,andifitissettoDisabl,itwillturnoff.Atthistime,thesystemperformanceWillbegreatlyreduced;ExternalCacheoptionistocontrolthesecond-levelbufferonthemotherboard,ifthereisasecond-levelcacheonthemotherboard,itshouldbesettoEnable.

Harddiskcache

Click"Start"/"Run"onthecomputerdesktop,type"Msconfig"tostartthe"SystemConfigurationUtility",andthenselectthe"system.ini"tabUnderthe"Vcache"item,youcanadjusttheharddiskcacheaccordingtotheactualsituationofthesystem.Therearegenerallythreelinesofcontentinthisoption:ChunkSize=1024,MaxFileCache=10240andMinFileCache=10240;thefirstlineisthebufferreadandwriteunitvalue,thesecondandthirdlinesarethemaximumandminimumbuffervalues​​oftheharddisk,andtheequalsignThefollowingvalues​​canbemodified,aslongasyouright-clickandselectanyrow,youcanmodifyit.Ifyourmemoryis128MB,thevalueoftheabovethreelinesismorereasonable,ofcourse,youcanalsocustomizeit.Ifyoudon’tknowhowtosettheappropriatebuffervalue,please"WindowsOptimizer"forhelp.Thereisa"DiskCacheOptimizer"iteminthissoftware,andyoucaneasilysetthecachewiththemouse;orlet"WindowsOptimizer"Automaticallyhelpyouoptimizesettings.Whenthecachevalueoftheharddiskislargeenough,theharddiskdoesnotneedtoreadandwritethediskfrequently,whichcanprolongthelifeoftheharddiskandincreasethedatatransmissionspeed.

Inaddition,settingthe"FileSystemCache"oftheharddiskto"NetworkServer"canspeedupthesystem'saccesstotheharddisk,becausethefilesystemcachestoresthefilenameandpathoftheharddiskrecentlyaccessed.Thelargerthecache,themorecontentcanbestored.Ifyouclick"ControlPanel"/"System"/"Performance"/"FileSystem"/"HardDisk",changethe"MainUseofThisComputer"from"Desktop"to"NetworkServer",youcanchangetheoriginal10KThecachehasincreasedtoabout50K.

CachingoffloppydriveandCD-ROMdrive

Generallyspeaking,thespeedofreadingandwritingdataoffloppydriveisrelativelyslow.Thisisbecausethespeedofthedisccannotbetoohigh.However,wecanincreasethefloppydriveTheread-writecacheallowsthefloppydrivetoreadandwritemoredataatatime.Themethodis:Type"Regedit"inthe"Start"/"Run"boxonthedesktoptoruntheregistryeditor,enterHKEY-LOCAL-MACHINE\System\CurrentControlSet\Services\Class\FDC\0000,andcreateanewoneasForeFifo"DWORDvalue",setitsvalueto"0",sothatthefloppydrivehasbeensoft-speededup.Manypeopleknowthatright-clickonthe"MyComputer"icononthedesktop,select"Properties"/"Performance"/"FileSystem"/"CD-ROM",andsetthebestaccessmethodto"QuadrupleSpeed​​orHigher",Dragtheadditionalcachesizeslidertothemaximumposition,whichcansignificantlyimprovethereadingspeedoftheCD-ROMdrive.Inadditiontothismethod,wecanalsosetthebuffervalueintheregistrybyenteringtheregistryandsettingCacheSize(thesizeofthecachevalue)underHKEY-LOCAL-MACHINE\System\CurrentControlSet\Control\FileSystem\CDFSAndPrefetch(pre-readingfilesize)aremanuallyadjusted,aslongasyouright-clicktheitemtobeselected,youcanmodifyit.

This article is from the network, does not represent the position of this station. Please indicate the origin of reprint
TOP