Organization of the Database Buffer Cache (80)

tsinglee發表於2007-10-23

The buffers in the cache are organized in two lists: the write list and the least recently
used (LRU) list. The write list holds dirty buffers, which contain data that has been
modified but has not yet been written to disk. The LRU list holds free buffers, pinned
buffers, and dirty buffers that have not yet been moved to the write list. Free buffers
do not contain any useful data and are available for use. Pinned buffers are currently
being accessed.
When an Oracle process accesses a buffer, the process moves the buffer to the most
recently used (MRU) end of the LRU list. As more buffers are continually moved to the
MRU end of the LRU list, dirty buffers age toward the LRU end of the LRU list.
The first time an Oracle user process requires a particular piece of data, it searches for
the data in the database buffer cache. If the process finds the data already in the cache
(a cache hit), it can read the data directly from memory. If the process cannot find the
data in the cache (a cache miss), it must copy the data block from a datafile on disk
into a buffer in the cache before accessing the data. Accessing data through a cache hit
is faster than data access through a cache miss.
Before reading a data block into the cache, the process must first find a free buffer. The
process searches the LRU list, starting at the least recently used end of the list. The
process searches either until it finds a free buffer or until it has searched the threshold
limit of buffers.
If the user process finds a dirty buffer as it searches the LRU list, it moves that buffer
to the write list and continues to search. When the process finds a free buffer, it reads
the data block from disk into the buffer and moves the buffer to the MRU end of the
LRU list.
If an Oracle user process searches the threshold limit of buffers without finding a free
buffer, the process stops searching the LRU list and signals the DBW0 background
process to write some of the dirty buffers to disk.

Database Buffer Cache結構
write list :髒列表 , 也就是被更改但還沒有寫入磁碟的資料 .
the least recently used (LRU) list :free buffers(無有用資料 , 可供使用), pinned buffers(正被訪問), 未轉移到write list的dirty buffers。
當Oracle訪問快取區 ,將該buffer移動到MRU .
當使用者程式請求一資料塊 , Oracle首先在database buffer cache查詢是否有該資料塊,如果找到 , 則稱為cache hit ,可以直接從記憶體中讀取 ,
如果沒有找到 ,則稱為cache miss, 這時候需要從磁碟上的資料檔案複製該資料塊到cache buffer後 , 才能訪問這些資料。
在讀取資料塊到cache之前 , 程式需要先從lru(從尾至頭)查詢一個free buffer, 要麼找到 ,要麼達到buffers閥值 .
如果找到一個dirty buffer , 把它移除到write list 並且繼續查詢 , 當找到free buffer後 ,程式將會從磁碟把資料塊讀入buffer ,
並且把buffer移到mru . 如果查詢達到buffer的閥值還沒有找到free buffer , 程式將停止查詢並且發出指令使dbw0後臺程式將dirty buffer
資料寫入磁碟

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10599713/viewspace-978170/,如需轉載,請註明出處,否則將追究法律責任。

相關文章