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.
Функционална роля
Кешът на твърдия диск играе главно триролки:
Pre-reading
WhentheharddiskiscontrolledbytheCPUinstruction,itstartstoread.Whenfetchingdata,thecontrolchipontheharddiskwillcontroltheheadtoreadthedatainthenextorseveralclustersoftheclusterbeingreadintothecache(becausethedataontheharddiskisstoredcontinuously,thereadhitrateisrelativelyhighHigh),whenthedatainthenextorseveralclustersneedstoberead,theharddiskdoesnotneedtoreadthedataagain,justtransferthedatainthecachetothememorydirectly,becausethecacherateismuchhigherthanThereadandwritespeedofthemagneticheadcanachievethepurposeofsignificantlyimprovingperformance.
Запис
Кеш (16 снимки)
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.
Принцип на работа
1.Ред на четене
WhentheCPUwantstoreadapieceofdata,itfirstlooksintheCache,ifIfitisfound,itwillbereadimmediatelyandsenttotheCPUforprocessing;ifitisnotfound,itwillbereadfromthememoryatarelativelyslowspeedandsenttotheCPUforprocessing.Atthesametime,thedatablockwherethedataislocatedcanbetransferredtotheCache,whichcanmakesubsequentadjustments.TheblockdataisreadfromtheCache,andthereisnoneedtocallthememory.
ItisthisreadmechanismthatmakesthehitrateofCPUreadCacheveryhigh(mostCPUscanreachabout90%),whichmeansthat90%ofthedatatobereadbytheCPUnexttimeareinIntheCache,onlyabout10%needtobereadfrommemory.ThisgreatlysavesthetimefortheCPUtodirectlyreadthememory,andalsomakestheCPUbasicallynoneedtowaitwhenreadingdata.Ingeneral,theorderinwhichtheCPUreadsdataisCachefirstandthenmemory.
2,Класификация на кеша
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.
Кеширане
Кешът може да бъде разделен на кеш за директно картографиране, групов пасосоциативен кеш и напълно асоциативен кеш.
Кеш с директно картографиране
В този тип кеш, всяка група е само един ред, E=1, и структурата е много проста. Целият кеш е еквивалентен на едномерен масив от групи. Замяната на реда в случай на пропуски е твърде проста, справедлива линия, което не е заместване на удара. За да се адаптира към малкия капацитет, определен блок данни в след това+1-ви слой от паметта може да бъде поставен само от поднабор на определено местоположение в горния слой (това е, след това десетия слой) на паметта. Ако приемем, че директно картографиран кеш, (S, E, B,m)=(4,1,2,4),това да кажем,дреска за глава4бита(16),има четири групи,всяка група един ред,два байта блок. Тъй като има 16 адреса, представляващи 16 байта, има общо 8 блока, но има само 4 групи, тоест 4 реда. ecachegroup.Например, 0 и 4 са картографирани към група 1, 1 и 5 са картографирани към група 2 и скоро. Тук идва проблемът. Например, когато първо се прочете блок0, данните на блок0 се кешират в група 0. След това чета блок4 отново, тъй като блок4 също е присвоен на група0, а група0 има само един ред, така че данните от предишния блок0 ще бъдат презаписани. Ако прочета блок0 по-късно, данните ще бъдат загубени. velmemorytofindit.В реалната програма за цикъл е лесно да се причини тази ситуация, която се нарича трептене. Наличието на тази ситуация естествено значително влияе върху производителността. Следователно е необходима по-добра схема за картографиране.
Групов пасоциативен кеш
В груповия пасосоциативен кеш, E е по-голям от 1, което означава, че има множество кеш линии в група. Тъй като Eise е равно на, се нарича като много пътища, така че се нарича Epath групова връзка.
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.
Thebasicideaoftheprocessorcacheistouseasmallamountofsramasthebufferbetweenthecpuandthedramstoragesystem,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)Основните причини за забавяне на достъпа на клиенти са:
①Thecontentcachedintheproxyservercanbeobtaineddirectlyfromtheproxyinsteadoffromtheremoteserver.Reducedtransmissiondelay;
②Thecontentthatisnotcachedcanbequicklyobtainedbycustomersduetonetworkcongestionandthereductionofserverload.
(3) Тъй като част от съдържанието на заявката на клиента може да бъде получено от агента, натоварването на отдалечения сървър е намалено.
(4)Iftheremoteserverfailstorespondtotheclient'srequestduetoaremoteserverfailureornetworkfailure,theclientcanobtainacopyofthecachedcontentfromtheproxy,whichenhancestherobustnessoftheWWWservice.
Webcachingsystemwillalsobringthefollowingproblems:
(1) Съдържанието, получено от клиента чрез проксито, може да е остаряло.
(2)Ifacachefailureoccurs,theclient'saccessdelaywillincreaseduetotheadditionalproxyprocessingoverhead.Therefore,whendesigningaWebcachingsystem,weshouldstrivetomaximizethecachehitrateandminimizethecostoffailure.
(3)Theproxymaybecomeabottleneck.Therefore,anupperlimitofthenumberofservicecustomersandalowerlimitofserviceefficiencyshouldbesetforanagent,sothattheefficiencyofanagentsystemisatleastthesameastheefficiencyofaclientdirectlyconnectedtoaremoteserver.
AffecttheInternetaccessrate
TheprocessofaccessingthewebsiteiscompletedbytheHTTPprotocolbuiltontopoftheTCP/IPprotocol.SincetheclientsendsanHTTPrequest,thewaitingtimeexperiencedbytheuserismainlydeterminedbytheresponsetimeoftheDNSandthewebsite.ThedomainnameofthewebsitemustfirstberesolvedtoanIPaddressbytheDNSserver,andthedelayofHTTPisdeterminedbythenumberofround-triptimesbetweentheclientandtheserver.Theround-triptimereferstothetimetheclientwaitsfortheresponseofeachrequest.Theaverageround-triptimedependsonthreeaspects:
Забавяне насървъра на уебсайта
Thedelaycausedbythewebserveraccountsforthemainproportionoftheroundtriptime.WhenaserverreceivesmultipleconcurrentHTTPrequests,queuingdelaywilloccur.SincerespondingtoanHTTPrequestoftenrequiresmultipleaccesstothelocalharddisk,evenaserverwithasmallloadmayhaveadelayoftensorhundredsofmicroseconds.
Забавяне, въведено отрутери, шлюзове, прокси сървъри и защитни стени
ThereareusuallymultiplenetworksinthepathbetweentheclientandtheserverEquipment,suchasrouters,gateways,proxies,firewalls,etc.Theyallneedtostore/forwardthepassingIPpackets,soqueuingdelayandprocessingdelaywillbeintroduced.Whenthenetworkiscongested,thesedevicesmayevenlosepackets.Atthistime,theyhopethattheclientandserverwillresumecommunicationthroughanend-to-endprotocol.
Различни комуникационни връзкиСкорост на предаване на данни
Inawideareanetwork,fromonenetworkdevicetoanothernetworkdeviceThedatatransferratebetweentimeisanimportantfactorindeterminingtheround-triptime.Buttheroleofbasicbandwidthisnotasimportantaspeoplethink.AtestshowsthatwhenawebsiteusesT3speedtoaccesstheInternet,only2%ofwebpagesorobjectscanbeprovidedtotheclientatarateof64kbps,whichisobviouslyShowsthatbandwidthisnotthemostcriticalfactorinnetworkperformance.
TheInternetisextendingtoeverycorneroftheworld.Auser'srequesttoaservermaytraveladistanceof8,000kilometersto16,000kilometers.ThedelaycausedbythespeedoflightandthedelayofnetworkequipmentisthenetworkThemostfundamentalreasonforsuchslowness.
Кеширането на мрежата решава основния проблем
Sincethereasonthataffectsthenetworkspeediscausedbydistanceandthespeedoflight,theonlywaytospeedupWebaccessistoshortentheclientThedistancefromthewebsite.Bystoringthepagesandobjectsfrequentlyvisitedbyusersclosertotheuser,thedelayintroducedbythespeedoflightcanbereduced.Atthesametime,thedelayintroducedbyrouters,firewallsandproxiesisalsoreducedduetothereductionoflinksintherouting..
Thetraditionalsolutionistoestablishamirrorservertoachievethepurposeofshorteningthedistance.Butthismethodhasgreatshortcomings.Foracertainsite,itisimpossibletoestablishamirrorsiteclosetoeachusergroup.Itisevenmoreuneconomicaltousethismethodformostofthesites,anditwillbemanagedatthesametime.Andmaintainingmirrorsitesisaverydifficulttask.
NetworkcachingisanemergingnetworktechnologythatreducesInternettrafficandimprovesend-userresponsetime.Itsconceptcomesfromotherareasofcomputersandnetworks.Forexample,thereisacacheinthepopularIntel-basedCPUtoincreasetherateofmemoryaccess;variousoperatingsystemsalsousecachetoincreasetheratewhenaccessingdisks.;Distributedfilesystemsusuallyalsousecachingtoimprovethespeedbetweentheclientandtheserver.
Тип
Може да има две форми на кеширане на статични страници: Всъщност, основната разлика е дали самата CMS е отговорна за управлението на актуализацията на кеша на свързаното съдържание.
1.Staticcaching:Itisastaticpagethatgeneratescorrespondingcontentimmediatelywhennewcontentisreleased.Forexample,onMarch22,2003,aftertheadministratorenteredanarticlethroughthebackgroundcontentmanagementinterface,Andsynchronouslyupdatethelinksontherelevantindexpages.
2.Dynamiccaching:Afterthenewcontentisreleased,thecorrespondingstaticpageisnotgeneratedinadvanceuntilthecorrespondingcontentisrequested,ifthefront-endcacheservercannotfindthecorrespondingcache,itwillsendtheback-endcontentThemanagementserversendsarequest,andthebackgroundsystemgeneratesastaticpageofthecorrespondingcontent.Theusermaybeslowerwhenaccessingthepageforthefirsttime,butinthefuture,itwilldirectlyaccessthecache.
Недостатъци на статичното кеширане:
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.
Прокси кеширанеСтратегия
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.
Добавяне, изтриване и промяна на данни за сесия
Memcachedclient,whenadding,deleting,andmodifyingsessioninformationdata,youmustnotonlyadd,delete,ModifytheMemcachedserverdatainthisprovince,andatthesametimedothesameoperationonMemcahedserversinotherprovinces,sothatuserscanaccessthesamesessiondatawhenaccessingthefunctionalmodulesofserversinotherprovinces.TheMemcachedclientserverlistusestheintranetIPofthelocalareanetwork(suchas:192.168.1.179)tooperatetheMemcahedserverinthisprovince,andthepublicIP(suchas:202.183.62.210)tooperatetheMemcaheserverinotherprovinces.
Четене на данни от сесията
ThelistofMemcachedclientserversforallmodulesofthesystemtoreadsessiondataaresettotheintranetIPoftheMemcachedserveraddressinthisprovinceToreadthesessiondatafromtheMemcahedserver.
Потвърждение на същата сесия
Usecookiestokeepthecustomerintouchwiththeserver.Atthebeginningofeachsession,aGUIDisgeneratedastheSessionIDandstoredinthecookieoftheclient.Thescopeisthetop-leveldomainname,sothatthesecond-levelandthird-leveldomainnamescansharethiscookie,andthesystemusesthisSessionIDtoconfirmwhetheritisthesameAconversation.
Уникалният ИД на данните за сесията
TheuniquekeyofthesessiondatastoredontheMemcachedserver.TheKey,whichistheuniqueIDofthesessiondata,isdefinedas:SessionID_Name,SessionIDistheSessionIDstoredintheclientcookie,andNameisthenameofthesessiondata.TheNameofeachsessiondatainthesamesessionmustbeunique,otherwisethenewsessiondatawilloverwritetheoldsessiondata.
Време на изтичане на сесията
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.
Кеш на твърдия диск
Щракнете върху "Старт"/"Изпълни" на работния плот на компютъра, въведете "Msconfig", за да стартирате "Помощната програма за конфигуриране на системата", и след това изберете раздела "system.ini" Под елемента "Vcache" можете да коригирате кеша на твърдия диск според действителната ситуация на системата. Обикновено има три реда на съдържание inthisoption:ChunkSize=1024, MaxFileCache=10240иMinFileCache=10240;първият ред е стойността на единицата за четене и запис на буфер, вторият и третият ред са максималната и минималната стойност на буферана твърдия диск, а знакът за равенствоСледните стойностимогат да бъдат модифицирани, докато щракнете с десния бутон и изберете всеки ред, можете да го промените. нашата памет е 128MB, стойността на горните три реда е по-разумна, разбира се, можете също да я персонализирате. Ако не знаете как да зададете подходящата стойност на буфера, моля, "WindowsOptimizer" за помощ. В този софтуер има елемент "DiskCacheOptimizer" и можете лесно да зададете кеша с мишката; или позволява на "WindowsOptimizer" автоматично да ви помогне да оптимизирате настройките. Когато стойността на кеша на твърдия диск е достатъчно голяма, твърдият диск не трябва да чете и записва диска често, което може да удължи живота на твърдия диск и да увеличи скоростта на предаване на данни.
Освен това, настройването на "кеша на файловата система" на твърдия диск на "мрежов сървър" може да ускори достъпа на системата до твърдия диск, тъй като кешът на файловата система съхранява името на файла и пътя на твърдия диск, до който сте имали наскоро достъп. Колкото по-голям е кешът, толкова повече съдържание може да бъде съхранено. Ако щракнете върху "Контролен панел"/"Система"/"Производителност" "/"Файлова система"/"Твърд диск",променете"Основното използване на този компютър"от" Desktop"към"NetworkServer",можете да променитеоригиналните10KКеш паметта е увеличена до около 50K.
Кеширане на дискетно устройство и CD-ROM устройство
Като цяло скоростта на четене и запис на данни от дискетно устройство е сравнително ниска. Това е така, защото скоростта на диска не може да бъде твърде висока. Ние обаче можем да увеличим флопидисковото устройство. pe "Regedit" в полето "Старт"/"Изпълнение" на работния плот за стартиране на редактора на регистър, въведете HKEY-LOCAL-MACHINE\System\CurrentControlSet \Services\Class\FDC\0000,andcreateanewoneasForeFifo"DWORDvalue",setitsvalueto"0",sothatthefloppydrivehasbeensoft-speededup.Manypeopleknowthatright-clickonthe"MyComputer"icononthedesktop,select"Properties"/"Performance"/"FileSystem"/"CD-ROM", и задайте най-добрия метод за достъп на „Четирикратна скоростили по-висока“, плъзгач за допълнителни размери на кеша на Dragthead на максимална позиция, което може значително да подобри скоростта на четене на CD-ROM устройството. В допълнение към този метод можем също да зададем стойността на буфера в регистъра, като въведете регистъра и зададете CacheSize (размера на стойността на кеша) под HKEY-LOCAL-MACHINE\System\CurrentControlSet\Control\FileSystem\CDFSAnd Prefetch (размер на файла преди четене) се коригират ръчно, докато щракнете с десния бутон върху елемента, който ще изберете, можете да го промените.