您好,欢迎访问三七文档
当前位置:首页 > 行业资料 > 纺织服装 > Oracle data buffer cache管理机制浅析
1databuffercache管理机制浅析2内容1.Oracle如何寻找到需要的buffer?2.Oracle如何管理databuffercache里面的块?3.Oracle如何确定哪些块应该写入数据文件,如何写?4.和Databuffercache相关的一些等待事件3引入•Instance最大的内存区域•db_cache_size参数•分配单位:granule•提供了default、keep、recyle三种不不同类型的cache•多种数据块尺寸(2、4、8、16或32k)的buffercache对应不同的blocksize数据块db_nk_cache_size4定位buffer•Buffer存放的位置:ThehashbucketforaparticularblockheaderisdeterminedbasedonthemodulusoftheDataBlockAddress(DBA)andthevalueofthe_DB_BLOCK_HASH_BUCKETSparameter.Forexample,hashbucket=MOD(DBA,_DB_BLOCK_HASH_BUCKETS).•先在PGA中构造bufferdiscriptor内存结构,同需要的锁定模式一起传入搜索函数,hash算法找到对应的bucket搜索函数:kcbget(descriptor,lock_mode)5Buffercache示意图_db_block_hash_buckets_db_block_hash_latches6BH结构视图:X$BHV$BHBH(0x0x5cfce8c4)file#:45rdba:0x0b417f8f(45/98191)class1ba:0x0x5c73e000set:5dbwrid:0obj:198268objn:198268hash:[6893c08c,6893c08c]lru:[61ff9348,57fee018]LRUflags:hot_bufferckptq:[NULL]fileq:[NULL]st:XCURRENTmd:NULLrsop:0x(nil)tch:2LRBA:[0x0.0.0]HSCN:[0xffff.ffffffff]HSUB:[255]RRBA:[0x0.0.0]7Hashchain+BHCHAIN:4889LOC:0x0x5a6e4100HEAD:[51fdf58c,56fcc874]BH(0x0x51fdf58c)file#:1rdba:0x00402432(1/9266)class1ba:0x0x51a1a000set:12dbwrid:0obj:3807objn:3807hash:[56fcc874,5a6e4100]lru:[51fdf8c4,51fdeff4]LRUflags:ckptq:[NULL]fileq:[NULL]st:XCURRENTmd:NULLrsop:0x(nil)tch:7LRBA:[0x0.0.0]HSCN:[0xffff.ffffffff]HSUB:[255]RRBA:[0x0.0.0]buffertsn:0rdba:0x00402432(1/9266)scn:0x0000.000071f9seq:0x01flg:0x04tail:0x71f90601frmt:0x02chkval:0x42eftype:0x06=transdata8Hashchain上的搜索Foreachbufferinthechain:-IgnorebuffersthatdonotmatchRDBA-WaitforREADINGbufferandreturnthem-SkipCR(consistentread)buffers-IftheCUR(current)bufferisheldinacompatiblemode,thenuseit-OtherwiseifallotherusersareCRstateobjects–MakeitaCRcopyandcreateanewEXLCURcopyofthebuffer–Orwaitforthecurrentbuffertobereleased-Ifnousablebuffersexistincache,readfromdisk搜索的时候,需要持有cachebufferchainlatch9Workingsets_db_block_lru_latches缺省值为DBWR进程的数量×8(允许的最大的bufferpool数量)10Workingsets•Eachlistthatisshownabovewillhavesublistscalledtheauxiliarywritelist(AUX)andaMAINlist.Forexample,theLRU-PlistwillhaveaLRUP-AUXandaLRUP-MAINlist.•LRU-XR,LRU-XOandLRU-Parealsocalledwritelists.buffersarelinkedtotheseduetoaspecificwriteaction.•theselistsarecandidatesforimmediatewrite-outsbytheDBWR.•enablewriteprioritizationcapabilities•一个BH只能在LRU或LRUW上,但能存在多个writelist上11workingsetsDumpofbuffercacheatlevel10(WS)size:501wsid:1state:0(WS_REPL_LIST)main_prev:5a6ff9bcmain_next:5a6ff9bcaux_prev:58fffd08aux_next:58fa4048curnum:501auxnum:501cold:5a6ff9bchbmax:0hbufs:0(WS_WRITE_LIST)main_prev:5a6ff9d8main_next:5a6ff9d8aux_prev:5a6ff9e0aux_next:5a6ff9e0curnum:0auxnum:0(WS_XOBJ_LIST)main_prev:5a6ff9f4main_next:5a6ff9f4aux_prev:5a6ff9fcaux_next:5a6ff9fccurnum:0auxnum:0(WS_XRNG_LIST)main_prev:5a6ffa10main_next:5a6ffa10aux_prev:5a6ffa18aux_next:5a6ffa18curnum:0auxnum:0(WS)fbwanted:0(WS)bgotten:0sumwrt:0sumscan:0(WS)numscan:0hotscan:0dmoves:0MAINRPL_LSTQueueheader(NEXT_DIRECTION)[NULL]MAINRPL_LSTQueueheader(PREV_DIRECTION)[NULL]AUXILIARYRPL_LSTQueueheader(NEXT_DIRECTION)[58fa4048,58fffd08]0x58fa4000=0x58fa42f0=0x58fa45e0=0x58fa48d0=0x58fa4bc0=0x58fa4eb0=0x58fa51a0=0x58fa54900x58fa5780=0x58fa5a70=0x58fa5d60=0x58fa6050=0x58fa6340=0x58fa6630=0x58fa6920=0x58fa6c100x58fa6f00=0x58fa71f0=0x58fa74e0=0x58fa77d0=0x58fa7ac0=0x58fa7db0=0x58fa80a0=0x58fa839012确定可重用buffer的过程•8i:从list的尾端开始scan,将冷端的bufferhead所指向的内容牺牲掉•9i:当查询所需要的块需要从磁盘读进来,挂在lru链上时,1.从list的尾端开始scan,先扫描辅list,再扫描主list2.lru算法+touchcount数3.热块往主list上移动,从中插入主list。辅list上空了之后,执行相同的算法在Lru中找出可牺牲的块,换到辅list上13LRU算法IF(touchcountofscannedbuffer_db_aging_hot_criteria)THENGivebufferanotherchance(donotselectasavictim)IF(_db_aging_stay_count=_db_aging_hot_criteria)THENHalvethebuffer'stouchcountELSESetthebuffer'stouchcountto_db_aging_stay_countENDIFELSESelectbufferasavictimENDIF14LRUW•LRUWlist:TheLRU-W(write)listisusedtoholdbuffersthatagedoutoftheLRUbutneedtobewrittentodiskbeforetheycanbereused.15block更改的过程•Updateblock的过程:假如我要修改BH2指向的块的内容1)oracle会将BH2从辅助LRU链表上摘下,同时插入主LRU链表的中间,也就是插入BH1和BH4中间,同时增加BH2的touch的数量。2) 将该BH2的标记设置为钉住(ping)。(latch保护)3) 更新BH2对应的内存数据块的内容。4) 更新完以后,取消钉住的标记。5) 将BH2从主LRU链表转移到主LRUW链表上。6) 如果这个时候又有进程发出更新BH2所对应的内存数据块的内容,则BH2再次被钉住,更新,取消钉住。7) DBWR启动以后,在扫描主LRUW链表时会将BH2转移到辅助LRUW链表上。8) DBWR将辅助LRUW链表上的BH2对应的数据块写入数据文件。9) 确认成功写入数据文件以后,将BH2从辅助LRUW链表上转移到辅助LRU链表上16checkpointCheckpoints(checkpointqueuelatch)•Toensurethatthedatablocksthathavetheirredogenerateduptoacertainpointintheredolog(RBA)arewrittentothedisk•Checkpointstructureincludes:–CheckpointSCN–CheckpointRBA–Threadthatallocatedthecheckpoint–Enabledthreadbitmap–Timestamp关于DDL:–TheOracleserverensuresthattheDDLissuccessfullymini-checkpointedbeforetheDROP(whichdependsontheSCNandseq#ofthedatablockswithintheobject).17CKPTQ&FQPre-Oracle8DBWRscannedtheentirecachetofindbufferswithcheckpointbitset.CKPTQandFQseliminatethisscan.–Whenthebufferisfirstmodified,itisinsertedintotheCKPTQinRBAorder–ThebufferisalsoinsertedintotheappropriateFQWhenacheckpointisinitiated,DBWRwritesallbuffersonthequeueuntilthecheckpointRBAislessthantheheadoftheCKPTQRBA.全量检查点发生条件:发出命令:altersy
本文标题:Oracle data buffer cache管理机制浅析
链接地址:https://www.777doc.com/doc-4457847 .html