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.
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.
可见, buffer cache 还是要提高命中率的问题, 即 让 server process 想找的block恰好在memory中, 直接进行操作.
To improve the cache hit ratio, the DBA can:
另外一点可以看出, 监控系统的 I/O 操作也是很重要的