4. 定位 buffer Buffer 存放的位置: The hash bucket for a particular block header is determined based on the modulus of the Data Block Address (DBA) and the value of the _DB_BLOCK_HASH_BUCKETS parameter. For example, hash bucket = MOD(DBA, _DB_BLOCK_HASH_BUCKETS). 先在 PGA 中构造 buffer discriptor 内存结构,同需要的锁定模式一起传入搜索函数, hash 算法找到对应的 bucket 搜索函数: kcbget(descriptor,lock_mode)
8. Hash chain 上的搜索 For each buffer in the chain: - Ignore buffers that do not match RDBA - Wait for READING buffer and return them - Skip CR (consistent read) buffers - If the CUR (current) buffer is held in a compatible mode, then use it - Otherwise if all other users are CR state objects – Make it a CR copy and create a new EXLCUR copy of the buffer – Or wait for the current buffer to be released If no usable buffers exist in cache, read from disk 搜索的时候,需要持有 cache buffer chain latch
9. Working sets _db_block_lru_latches 缺省值为 DBWR 进程的数量 ×8 (允许的最大的 buffer pool 数量)
10. Working sets Each list that is shown above will have sublists called the auxiliary write list (AUX) and a MAIN list. For example, the LRU-P list will have a LRUP-AUX and a LRUP-MAIN list. LRU-XR, LRU-XO and LRU-P are also called write lists.buffers are linked to these due to a specific write action. these lists are candidates for immediate write-outs by the DBWR. enable write prioritization capabilities 一个 BH 只能在 LRU 或 LRUW 上,但能存在多个 write list 上
12. 确定可重用 buffer 的过程 8i: 从 list 的尾端开始 scan ,将冷端的 buffer head 所指向的内容牺牲掉 9i: 当查询所需要的块需要从磁盘读进来,挂在 lru 链上时, 从 list 的尾端开始 scan ,先扫描辅 list ,再扫描主 list lru 算法 +touch count 数 热块往主 list 上移动,从中插入主 list 。辅 list 上空了之后,执行相同的算法在 Lru 中找出可牺牲的块,换到辅 list 上
13. LRU 算法 IF ( touch count of scanned buffer >_db_aging_hot_criteria ) THEN Give buffer another chance (do not select as a victim) IF (_db_aging_stay_count >= _db_aging_hot_criteria) THEN Halve the buffer's touch count ELSE Set the buffer's touch count to _db_aging_stay_count END IF ELSE Select buffer as a victim END IF
14. LRUW LRUW list: The LRU-W (write) list is used to hold buffers that aged out of the LRU but need to be written to disk before they can be reused.
16. checkpoint Checkpoints ( checkpoint queue latch ) To ensure that the data blocks that have their redo generated up to a certain point in the redo log (RBA) are written to the disk Checkpoint structure includes: – Checkpoint SCN – Checkpoint RBA – Thread that allocated the checkpoint – Enabled thread bitmap Timestamp 对于 DDL: The Oracle server ensures that the DDL is successfully mini-checkpointed before the DROP (which depends on the SCN and seq# of the data blocks within the object).
17. CKPTQ & FQ Pre-Oracle8 DBWR scanned the entire cache to find buffers with checkpoint bit set. CKPTQ and FQs eliminate this scan. – When the buffer is first modified, it is inserted into the CKPTQ in RBA order – The buffer is also inserted into the appropriate FQ When a checkpoint is initiated, DBWR writes all buffers on the queue until the checkpoint RBA is less than the head of the CKPTQ RBA. 全量检查点发生条件: 发出命令: alter system checkpoint ; 除了 shutdown abort 以外的正常关闭数据库。
20. 等待事件 buffer busy waits P1=file# p2=block_id p3= reason code Reason code 130 和 220 是最常见 Free buffer waits If a session spends a lot of time on the free buffer waits event, it is usually due to one or a combination of the following five reasons: Inefficient SQL statements Not enough DBWR processes Slow I/O subsystem Delayed block cleanouts. Small buffer cache