版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
MemoryHierarchy
UpperLevelInstrOperands Faster
Earlier:
Caches
Blocks
Blocks
NextUp:VirtualMemory
Pages
Files
7/30/2012
Summer2012--Lecture#24
LargerLowerLevel
3
Tape
Disk
Memory
L2Cache
L1Cache
Regs
MemoryHierarchyRequirements
PrincipleofLocality
Allowscachestooffer(closeto)speedofcachememorywithsizeofDRAMmemory
CanweusethisatthenextleveltogivespeedofDRAMmemorywithsizeofDiskmemory?
Whatotherthingsdoweneedfromour
memorysystem?
7/30/2012
Summer2012--Lecture#24
4
MemoryHierarchyRequirements
Allowmultipleprocessestosimultaneouslyoccupymemoryandprovideprotection
Don’tletprogramsreadfromorwritetoeach
other’smemories
Giveeachprogramtheillusionthatithasitsownprivateaddressspace(viatranslation)
Supposecodestartsataddress0x00400000,thendifferentprocesseseachthinktheircoderesidesatthesameaddress
Eachprogrammusthaveadifferentviewofmemory
7/30/2012 Summer2012--Lecture#24 5
VirtualMemory
Nextlevelinthememoryhierarchy
Providesillusionofverylargemainmemory
Workingsetof“pages”residinginmainmemory(subsetofallpagesresidingondisk)
Maingoal:Avoidreachingallthewaybacktodiskasmuchaspossible
Additionalgoals:
LetOSsharememoryamongmanyprogramsandprotectthemfromeachother
Eachprocessthinksithasallthememorytoitself
7/30/2012
Summer2012--Lecture#24
6
VirtualtoPhysicalAddressTranslation
Virtual
Address(VA)
(inst.fetchload,store)
load,store)
Eachprogramoperatesinitsownvirtualaddress
spaceandthinksit’stheonlyprogramrunning
Eachisprotectedfromtheother
OScandecidewhereeachgoesinmemory
Hardwaregivesvirtual→physicalmapping
7/30/2012 Summer2012--Lecture#24
7
Programoperatesinitsvirtualaddressspace
Physicalmemory(includingcaches)
HW
mapping
Physical
Address(PA)
(inst.fetch
VMAnalogy(1/2)
TryingtofindabookintheUCBsystem
Booktitleislikevirtualaddress(VA)
Whatyouwant/arerequesting
Bookcallnumberislikephysicaladdress(PA)
Whereitisactuallylocated
Cardcatalogueislikeapagetable(PT)
Mapsfrombooktitletocallnumber
Doesnotcontaintheactualthatdatayouwant
Thecatalogueitselftakesupspaceinthelibrary
7/30/2012 Summer2012--Lecture#24 8
VMAnalogy(2/2)
Indicationofcurrentlocationwithinthe
librarysystemislikevalidbit
Validifincurrentlibrary(mainmemory)vs.invalidifinanotherbranch(disk)
Foundonthecardinthecardcatalogue
Availability/termsofuselikeaccessrights
Whatyouareallowedtodowiththebook(abilitytocheckout,duration,etc.)
Alsofoundonthecardinthecardcatalogue
7/30/2012
Summer2012--Lecture#24
9
北京航空航天大學(xué)計算機學(xué)院
提綱
內(nèi)容主要取材:CS61C的24講
虛擬存儲器
頁表(PageTables)
TLB(TranslationLookasideBuffer)
VM性能
VM總結(jié)
UserC
UserB
UserA
OS
Heap
Static
MappingVMtoPM
Divideintoequalsizedchunks(about4KiB-8KiB)
AnychunkofVirtualMemorycanbeassignedtoanychunkofPhysical
Memory(“page”)
PhysicalMemory
VirtualMemory
64MB
7/30/20120 Summer2012--Lecture#24 0 12
page0
page1
page2
VirtualMemoryMappingFunction
Howlargeismainmemory?Disk?
Don’tknow!Designedtobeinterchangeablecomponents
Needasystemthatworksregardlessofsizes
Uselookuptable(pagetable)todealwitharbitrarymapping
Indexlookuptableby#ofpagesinVM(notallentrieswillbeused/valid)
SizeofPMwillaffectsizeofstoredtranslation
7/30/2012
Summer2012--Lecture#24
14
AddressMapping
Pagesarealignedinmemory
Borderaddressofeachpagehassamelowestbits
PagesizeissameinVMandPM,sodenotelowestO=log2(pagesize/B)bitsaspageoffset
Useremainingupperaddressbitsinmapping
Tellsyouwhichpageyouwant(similartoTag)
PhysicalPage#PageOffset
VirtualPage# PageOffset
Notnecessarily
thesamesize
7/30/2012
SameSize
Summer2012--Lecture#24
15
AddressMapping:PageTable
PageTablefunctionality:
IncomingrequestisVirtualAddress(VA),wantPhysicalAddress(PA)
PhysicalOffset=VirtualOffset(aligned)
SojustswapVirtualPageNumber(VPN)forPhysicalPageNumber(PPN)
VirtualPage# PageOffset
Implementation?
UseVPNasindexintoPT
StorePPNandmanagementbits(Valid,AccessRights)
DoesNOTstoreactualdata(thedatasitsinPM)
7/30/2012 Summer2012--Lecture#24 16
PhysicalPage#
V
AR
PPN
X
XX
2)CheckValidandAccessRightsbits
...
PageTableEntryFormat
ContainseitherPPNorindicationnotinmainmemory
Valid=Validpagetableentry
1→virtualpageisinphysicalmemory
0→OSneedstofetchpagefromdisk
AccessRightscheckedoneveryaccesstoseeifallowed(providesprotection)
ReadOnly:Canread,butnotwritepage
Read/Write:Readorwritedataonpage
Executable:Canfetchinstructionsfrompage
7/30/2012
Summer2012--Lecture#24
18
PageTables(1/2)
Apagetable(PT)containsthemappingofvirtualaddressestophysicaladdresses
Pagetableslocatedinmainmemory–Why?
Toolargetofitinregisters(220entriesfor4KiBpages)
Fastertoaccessthandiskandcanbesharedbymultipleprocessors
TheOSmaintainsthePTs
Eachprocesshasitsownpagetable
“State”ofaprocessisPC,allregisters,andPT
OSstoresaddressofthePTofthecurrentprocessinthePageTableBaseRegister
7/30/2012 Summer2012--Lecture#24 19
PageTables(2/2)
Solvesfragmentationproblem:allpagesare
thesamesize,socanutilizeallavailableslotsOSmustreserve“swapspace”ondisk
foreachprocess
Runningprogramsrequiresharddrivespace!
Togrowaprocess,askOperatingSystem
IfunusedpagesinPM,OSusesthemfirst
Ifnot,OSswapssomeoldpages(LRU)todisk
7/30/2012
Summer2012--Lecture#24
20
Paging/VirtualMemoryMultipleProcesses
UserA: UserB:
VirtualMemory
VirtualMemory
Physical
Memory
64MB
Code
7/30/2012
Page
TableA
Page
TableB
Summer2012--Lecture#24
21
Static
Stack
Static
Code
Review:PagingTerminology
Programsusevirtualaddresses(VAs)
Spaceofallvirtualaddressescalledvirtualmemory(VM)
Dividedintopagesindexedbyvirtualpagenumber(VPN)
Mainmemoryindexedbyphysicaladdresses(PAs)
Spaceofallphysicaladdressescalledphysicalmemory(PM)
Dividedintopagesindexedbyphysicalpagenumber(PPN)
7/30/2012 Summer2012--Lecture#24 22
Question:Howmanybitswidearethefollowing
fields?
16KiBpages
40-bitvirtualaddresses
64GiBphysicalmemory
?
?
?
?
VPN PPN
26 26
24
22
20
22
23
北京航空航天大學(xué)計算機學(xué)院
提綱
內(nèi)容主要取材:CS61C的24講
虛擬存儲器
頁表(PageTables)
TLB(TranslationLookasideBuffer)
VM性能
VM總結(jié)
RetrievingDatafromMemory
PTUser1 Physical
Memory
VA1
1)Accesspage
tableforaddresstranslation
PTUser2
User1Virtual
AddressSpace
VA2
2)Accesscorrect
physicaladdress
User2Virtual
AddressSpace
7/30/2012
Requirestwoaccesses
ofphysicalmemory!
Summer2012--Lecture#24
25
VirtualMemoryProblem
2physicalmemoryaccessesperdataaccess
=SLOW!
Sincelocalityinpagesofdata,theremustbelocalityinthetranslationsofthosepages
BuildaseparatecacheforthePageTable
Forhistoricalreasons,cacheiscalledaTranslationLookasideBuffer(TLB)
NoticethatwhatisstoredintheTLBisNOTdata,
buttheVPN→PPNmappingtranslations
7/30/2012
Summer2012--Lecture#24
26
TLBsvs.Caches
Memory
Address
D$/I$
Dataatmemoryaddress
VPN
TLB
PPN
Onmiss:Accessnext
cachelevel/mainmemory
Onmiss:AccessPage
Tableinmainmemory
TLBsusuallysmall,typically16–512entries
TLBaccesstimecomparabletocache(?mainmemory)
TLBscanhaveassociativity
–Usuallyfully/highlyassociative
7/30/2012 Summer2012--Lecture#24 27
WhereAreTLBsLocated?
Whichshouldwecheckfirst:CacheorTLB?
Cancacheholdrequesteddataifcorrespondingpageisnotinphysicalmemory?No
WithTLBfirst,doescachereceiveVAorPA?
CPU
VA
TLB
hit
PA
miss
Cache
Main
dataMemory
miss hit
Page Noticethatitisnowthe
Table TLBthatdoestranslation,notthePageTable!
7/30/2012
Summer2012--Lecture#24
28
BasedVirtual-MemoryMachine
(HardwareTableWalk)
PageFault? PageFault?
Protectionviolation? Protectionviolation?
Virtual Virtual
Address
PhysicalAddress
Address
Inst.
PC TLB
Inst.Cache
D
Decode
E +M
DataTLB
PhysicalAddress
DataCache
W
Miss?
Miss?
BaseRegister
PhysicalAddress
PhysicalAddress
PhysicalAddress
Assumespagetablesheldinuntranslatedphysicalmemory
February16,2012
CS152,Spring2012
29
MainMemory(DRAM)
MemoryController
HardwarePageTableWalker
TLBTag
PPN
(usedjust
likeinacache)
...
Tag
BlockData
...
Valid
Dirty
Ref
AccessRights
TLBTag
PPN
X
X
X
XX
Valid
Dirty
Ref
AccessRights
TLBTag
PPN
X
X
X
XX
FetchingDataonaMemoryRead
CheckTLB(input:VPN,output:PPN)
TLBHit:Fetchtranslation,returnPPN
TLBMiss:Checkpagetable(inmemory)
PageTableHit:LoadpagetableentryintoTLB
PageTableMiss(PageFault):Fetchpagefromdisktomemory,updatecorrespondingpagetableentry,thenloadentryintoTLB
Checkcache(input:PPN,output:data)
CacheHit:Returndatavaluetoprocessor
CacheMiss:Fetchdatavaluefrommemory,storeitincache,returnittoprocessor
7/30/2012 Summer2012--Lecture#24 33
PageFaults
Loadthepageoffthediskintoafreepageofmemory
Switchtosomeotherprocesswhilewewait
Interruptthrownwhenpageloadedandtheprocess'pagetableisupdated
Whenweswitchbacktothetask,thedesireddatawillbeinmemory
Ifmemoryfull,replacepage(LRU),writingbackifnecessary,andupdatebothpagetables
Continuousswappingbetweendiskandmemorycalled“thrashing”
7/30/2012 Summer2012--Lecture#24 34
PerformanceMetrics
VMperformancealsousesHit/MissRatesandMissPenalties
TLBMissRate:FractionofTLBaccessesthatresultinaTLBMiss
PageTableMissRate:FractionofPTaccessesthatresultinapagefault
Cachingperformancedefinitionsremainthesame
Somewhatindependent,asTLBwillalwayspassPAtocacheregardlessofTLBhitormiss
7/30/2012
Summer2012--Lecture#24
35
DataFetchScenarios
Arethefollowingscenariosforasingledata
accesspossible?
TLBMiss,PageFault Yes
TLBHit,PageTableHit No
TLBMiss,CacheHit Yes
PageTableHit,CacheMiss Yes
PageFault,CacheHit No
7/30/2012
Summer2012--Lecture#24
36
Question:AprogramtriestoloadawordatXthatcausesaTLBmissbutnotapagefault.ArethefollowingstatementsTRUEorFALSE?
ThepagetabledoesnotcontainavalidmappingforthevirtualpagecorrespondingtotheaddressX
Thewordthattheprogramistryingtoloadispresentinphysicalmemory
37
1 2
F F
T F
F T
UpdatingScenarios
UsingV=valid,D=dirty,R=reftomeanthatfieldissettotheshownvalueforanyentryineitherPTorTLB
Whichofthefollowingscenariosforasingledataaccessarepossible?
Read,D=1 No
Write,R=1 Yes
Read,V=0 Yes
Write,D=0 No
7/30/2012 Summer2012--Lecture#24 38
Question:AssumethepagetableentryinquestionispresentintheTLBandweareusingauniprocessorsystem.ArethefollowingstatementsTRUEorFALSE?
ThevalidbitforthatpagemustbethesameinthePTandTLB
ThedirtybitforthatpagemustbethesameinthePTandTLB
39
1 2
F F
F T
T F
北京航空航天大學(xué)計算機學(xué)院
提綱
內(nèi)容主要取材:CS61C的24講
虛擬存儲器
頁表(PageTables)
TLB(TranslationLookasideBuffer)
VM性能
VM總結(jié)
VMPerformance
VirtualMemoryisthelevelofthememory
hierarchythatsitsbelowmainmemory
TLBcomesbeforecache,butaffectstransferofdatafromdisktomainmemory
Previouslyweassumedmainmemorywaslowestlevel,nowwejusthavetoaccountfordiskaccesses
SameCPI,AMATequationsapply,butnowtreatmainmemorylikeamid-levelcache
7/30/2012
Summer2012--Lecture#24
41
TypicalPerformanceStats
secondarymemory
primarymemory
Caching Demandpaging
cacheentry pageframe
cacheblock(≈32bytes) page(≈4Kibytes)
cachemissrate(1%to20%) pagemissrate(<0.001%)
cachehit(≈1cycle) pagehit(≈100cycles)cachemiss(≈100cycles) pagemiss(≈5Mcycles)
7/30/2012
Summer2012--Lecture#24
42
cache
CPU
CPU
primarymemory
ImpactofPagingonAMAT(1/2)
MemoryParameters:
L1cachehit=1clockcycles,hit95%ofaccesses
L2cachehit=10clockcycles,hit60%ofL1misses
DRAM=200clockcycles(≈100nanoseconds)
Disk=20,000,000clockcycles(≈10milliseconds)
AverageMemoryAccessTime(nopaging):
1+5%×10+5%×40%×200=5.5clockcycles
AverageMemoryAccessTime(withpaging):
5.5(AMATwithnopaging)+?
7/30/2012 Summer2012--Lecture#24 43
ImpactofPagingonAMAT(2/2)
AverageMemoryAccessTime(withpaging)=
5.5+5%×40%×(1-HRMem)×20,000,000
AMATifHRMem=99%?
5.5+0.02×0.01×20,000,000=4005.5(≈728xslower)
1in20,000memoryaccessesgoestodisk:10secprogramtakes2hours!
AMATifHRMem=99.9%?
5.5+0.02×0.001×20,000,000=405.5
AMATifHRMem=99.9999%
5.5+0.02×0.000001×20,000,000=5.9
7/30/2012
Summer2012--Lecture#24
44
ImpactofTLBsonPerformance
EachTLBmisstoPageTable~L1Cachemiss
TLBReach:AmountofvirtualaddressspacethatcanbesimultaneouslymappedbyTLB:
TLBtypicallyhas128entriesofpagesize4-8KiB
128×4KiB=512KiB=just0.5MiB
Whatcanyoudotohavebetterperformance?
Multi-levelTLBs Conceptuallysameasmulti-levelcaches
Variablepagesize(segments)
Specialsituationally-used“superpages”
Notcovered
here
7/30/2012 Summer2012--Lecture#24 45
北京航空航天大學(xué)計算機學(xué)院
提綱
內(nèi)容主要取材:CS61C的24講
虛擬存儲器
頁表(PageTables)
TLB(TranslationLookasideBuffer)
VM性能
VM總結(jié)
VirtualMemoryMotivation
Memoryascachefordisk(reducediskaccesses)
Diskissoslowitsignificantlyaffectsperformance
Pagingmaximizesmemoryusagewithlarge,evenly-sizedpagesthatcangoanywhere
Allowsprocessortorunmultipleprocessessimultaneously
Giveseachprocessillusionofitsown(large)VM
EachprocessusesstandardsetofVAs
Accessrightsprovideprotection
7/30/2012
Summer2012--Lecture#24
47
PagingSummary
Pagingrequiresaddresstranslation
Canrunprogramslargerthanmainmemory
Hidesvariablemachineconfigurations(RAM/HD)
Solvesfragmentationproblem
Addressmappingsstoredinpagetablesinmemory
AdditionalmemoryaccessmitigatedwithTLB
CheckTLB,thenPageTable(ifnecessary),then
Cache
7/30/2012
Summer2012--Lecture#24
48
Hardware/SoftwareSupportfor
MemoryProtection
Differenttaskscansharepartsoftheirvirtualaddressspaces
Butneedtoprotectagainsterrantaccess
RequiresOSassistance
HardwaresupportforOSprotection
Privilegedsupervisormode(a.k.a.kernelmode)
Privilegedinstructions
Pagetablesandotherstateinformationonlyaccessibleinsupervisormode
Systemcallexception(e.g.syscallinMIPS)
7/30/2012
Summer2012--Lecture#24
49
ContextSwitching
Howdoesasingleprocessorrunmany
programsatonce?
Con
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年烏魯木齊貨運從業(yè)資格考試模擬考試題目及答案
- 洛陽師范學(xué)院《企業(yè)級網(wǎng)絡(luò)架構(gòu)》2023-2024學(xué)年第一學(xué)期期末試卷
- 2024年度文化產(chǎn)業(yè)實習(xí)生勞動合同范本3篇
- 2024年某城市地鐵線路 extension 建設(shè)承包合同
- 軟件測試與驗收協(xié)議
- 房屋租賃保證書-礦山開采
- 哈爾濱市建筑工地消防管理
- 河北省滄衡名校聯(lián)盟2025屆高三上學(xué)期11月期中考試數(shù)學(xué)試題(解析版)
- 2024年版電動汽車充電站點施工協(xié)議版B版
- 2024年度電商平臺用戶協(xié)議補充條款3篇
- 2014年吉林省長春市中考模擬數(shù)學(xué)
- 上汽-最詳細(xì)的整車開發(fā)流程(CPMP)
- 論文巖棉用酚醛樹脂體系
- 設(shè)計開發(fā)記錄總表
- 通風(fēng)填寫范例
- 盲人無障礙出行調(diào)查問卷分析報告(20220215150515)
- 財務(wù)審批權(quán)限管理辦法
- 許昌特產(chǎn)介紹
- 歐姆龍AD081、DA08C輸入輸出模塊的使用手冊
- 外墻真石漆施工合同書
- 一千個傷心的理由(張學(xué)友)原版五線譜鋼琴譜正譜樂譜.docx
評論
0/150
提交評論