• Tuning 04 Sizing the Buffer Cache


    image

    image

    image

    image

    Buffer Cache 特性

    The buffer cache holds copies of the data blocks from the data files. Because the buffer cache is a part of the SGA, these blocks can be shared by all users. The server processes read data from the data files into buffer cache.(是server process 将数据从硬盘读取到内存的) To improve performance, the server process sometimes reads multiple blocks in a single read. The DBWn process writes data from the buffer cache into the data files. To improve performance, DBWn writes multiple blocks in a single write.

    DB_CACHE_SIZE: specifies the size of default buffer pool in bytes.

    DBA_KEEP_CACHE_SIZE: specifies the size of keep buffer pool in bytes.

    DBA_RECYCLE_CACHE_SIZE: specifies the size of recycle buffer pool in bytes.

    The blocks in the buffer cache are managed using two lists:

    - The least recently used(LRU) list is used to keep the most recently accessed blocks in memory. The blocks on the list are organized from the most recently used(MRU) to the recently used. (最后最多被使用)

    - The dirty list points to blocks in the buffer cache that have been modified but not written to disk.

    Blocks in the buffer cache can be in one or three states:

    - Free buffers are blocks that have the same image on disk and in memory. These blocks are availiable for reuse.

    - Dirty blocks are blocks with a different image in memory than the image on disk. These blocks must be written to disk before they can be reused.

    - Pinned buffers are memory blocks that are currently being accessed.

    imageimage

    When a server needs a block, it follows these steps to read the block:

    1. Firstm the server checks wether the required block is available in the buffer cache using a hash function. If the block is found, it is moved to another point in LRU list away from the LRU end. This is a logical read, because no actual I/O took place. If the block is not found in the buffer cache, the server process has to read the block from the data file.

    2. Before reading from the data file, the server process searches the LRU list for a free block.

    3. While searching the LRU list, the server process moves dirty blocks to the dirty list.

    4. If the dirty list exceeds its size threshold, the server signals DBWn to flush dirty blocks from the data buffer cache. If the server cannot find a free block within a search threshold, it signals DBWn to flush.

    5. After a free block is found, the server reads the block from the data file into the free block in the database buffer cache. Oracle server process moves the block away from the LRU end of the LRU list.

    6. If the block is not consistent, the server rebuilds an earlier version of the block from the current block and rollback segments.

    7. Dirty List Exceeds its Size Threshold: A server process finds that the dirty list has exceeded its size threshold, so it signals DBWn to flush. DBWn writes out the blocks on the dirty list.

    8. Search Threshold Exceeded: A server process that cannot find a free block on the LRU list within the search threshold signals DBWn to flush dirty blocks. DBWn writes out dirty blocks directly from the LRU list.

    image

    image

    可见, buffer cache 还是要提高命中率的问题, 即 让 server process 想找的block恰好在memory中, 直接进行操作.

    To improve the cache hit ratio, the DBA can:

    • Increase the size of buffer cache
    • Use multiple buffer pools to separate blocks by access characteristics
    • Configure the tables to be cached in memory
    • Configure to bypass the buffer cache for sorting and parallel reads if possible.

    另外一点可以看出, 监控系统的 I/O 操作也是很重要的

    image

    image

    image

    image

    image

    image

    image

    image

    image

    image

    image

    image

  • 相关阅读:
    爱奇艺笔试题 输出01020304... ...
    ThreadPoolExecutor 中为什么WorkQueue会在corePoolSize满了之后入队
    jvisualvm 的使用
    连续子数组的最大和
    最长连续子序列
    leetcode 需要了解的知识点储备
    java String
    mysql MVCC
    java 批量导出(zip文件)
    java 中接口调用
  • 原文地址:https://www.cnblogs.com/moveofgod/p/3629975.html
Copyright © 2020-2023  润新知