Oracle Memory Architecture - Oracle 体系结构篇 4

前言:SGA的组件之一 Database Buffer Cache 之 buffer I/O,buffer pools

Oracle Memory Architecture - Oracle 体系结构篇 3 http://blog.csdn.net/u010993297/article/details/9420247

1.     Buffer I/O

1.1.    Buffer Writes

            A logical I/O, also known as abuffer I/O, refers to reads and writes of buffers in the buffer cache. When a requested buffer is not found in memory, the database performs aphysical I/O to copy the buffer from either the flash cacheordisk into memory, and then alogical I/O to read the cached buffer.

           ---一个逻辑I/O,也被称为缓冲区I/O

           The  database writer(DBWn) process periodically writescold,dirty buffers to disk.DBWn writes buffers in the following circumstances:

           >>A server process cannot find clean buffers for reading new blocks into the database buffer cache.

               As buffers aredirtied, the number of free buffers decreases.

              If the number drops below an internal threshold,and if clean buffers are required,

              then server processes signal DBWn to write.   ---服务器进程通知DBWn写。

 

              --LRU最近最少使用原则

              The database uses theLRU to determine which dirty buffers to write.

              When dirty buffers reach the cold end ofthe LRU,

              the database moves them off the LRU to awrite queue.DBWn writes buffers in the queue to disk,

              using multiblock writes if possible.

              This mechanism prevents the end of theLRU from becoming clogged withdirty buffers and allowsclean buffers

               to be found for reuse.

          >>The database must advance the checkpoint, which is the position in the redo thread from which instance  recovery must begin.

          >>Tablespaces are changed to read-only status or taken offline.

 

1.2.    Buffer Reads

1.2.1.   Flash Cache Setting

            When the number ofclean or unused buffers is low, the database must remove buffers from the buffer cache. The algorithm depends on whether the flash cache is enabled:

            >>Flash cache disabled

            The database re-useseach clean buffer as needed,overwriting it.

             If the overwritten buffer is neededlater,

             then the database mustread it from magnetic disk.

            >>Flash cache enabled

            DBWn can write the body of aclean buffer to the flash cache,

            enabling reuse of itsin-memory buffer.

            The database keeps thebuffer header in anLRU list in main memory to track the state and location of

            the buffer body in the flash cache.

            If this buffer is needed later, then the database canread it from the flash cache instead of frommagnetic disk.

 

1.2.2.   Buffer Search Order
1.2.2.1    The buffer search

                                                    图1 buffer search

 

1.2.2.2    The buffer search order 

               A cache hit occurs if the database finds the buffer in memory. ---高速缓存命中

              <<---- 第一步 server process- buffer cache- logical read  --->>

               >>Theserver process searches for the whole buffer in thebuffer cache.

                   If the process finds the whole buffer, then the database performs alogical read of this buffer.

 

              <<---- 第二步 server process- flash cache LRU- physical read- in-memory cache. --->>

               >>Theserver process searches for the buffer header in theflash cache LRU list.

                    If the process finds thebuffer header,

                    then the database performs anoptimized physical read of the buffer body from the flash cache into thein-memory cache.

 

                <<----第三步 cache miss -server process- physical read-logical read--->>

                If the process does not find the buffer in memory (acache miss), then the server process performs the following steps:

                 >>Copies the block from a data file into memory (aphysical read)

                 >>Performs a logical read of the buffer that was read into memory

 

<<----总结:cache hit & cache miss- physical reads(data file & temp file)--->>

         In general, accessing data through acache hit is faster than through acache miss. Thebuffer cache hit ratio measures how often the database found a requested block in the buffer cache without needing to read it from disk.

        The database can performphysical reads from either adata file or a temp file. Reads from a data file are followed by logical I/Os. Reads from a temp file occur when insufficient memory forces the database write data to a temporary table and read it back later. These physical reads bypass the buffer cache and do not incur a logical I/O.

1.3.    Buffer Touch Counts

<< ----LRU—touch count ---- >>

          The database measures the frequency of access of buffers on the LRU list using atouch count. This mechanism enables the database to increment a counter when a buffer is pinned instead of constantly shuffling buffers on the LRU list.

          When a buffer ispinned, the database determines when its touch count was last incremented. If the count was incremented overthree seconds ago, then the count is incremented; otherwise, the count stays the same. Thethree-second rule prevents a burst of pins on a buffer counting as many touches. For example, a session may insert several rows in a data block, but the database considers these inserts as one touch.

          If a buffer is on the cold end of theLRU, but its touch count ishigh, then the buffer moves to the hot end. If the touch count islow, then the buffer ages out of the cache.

1.4.    Buffer and Full Table Scans

           When buffers must be read from disk, the database inserts the buffers into the middle of theLRU list. In this way,hot blocks can remain in the cache so that they do not need to be read from disk again.

           A problem is posed bya full table scan, which sequentially reads all rows under the tablehigh water mark. Suppose that the total size of the blocks in a table segment is greater than the size of the buffer cache. A full scan of this table could clean out the buffer cache, preventing the database from maintaining a cache of frequently accessed blocks.

           Blocks read into the database cache as the result of a full scan of a large table are treated differently from other types of reads. The blocks are immediately available for reuse to prevent the scan from effectivelycleaning out the buffer cache.

           In the rare case where the default behavior is not desired, you can change the  CACHE attribute of the table. In this case, the database does not force or pin the blocks in the buffer cache, but ages them out of the cache in the same way as any other block. Use care when exercising this option because a full scan of a large table may clean most of the other blocks out of the cache.

 

2.     Buffer Pools

2.1.    The structure of the buffer cache

                                    图2  Database buffer cache

2.2.    The buffer pools

            The cache containsdefault,keep, andrecycle pools. Thedefault block size is 8 KB. The cache contains separate pools for tablespaces that use the nonstandard block sizes of 2 KB, 4 KB, and 16 KB. --参考图2.

            The possible buffer pools are as follows:

            >>Default pool

                This pool is thelocation where blocks arenormally cached. Unless you manually configure separate pools, thedefault pool is the only buffer pool.

            >>Keep pool

                This pool is intended forblocks that wereaccessed frequently, but which aged out of the default pool because of lack of space. The goal of thekeep buffer pool is to retain objects in memory, thus avoiding I/O operations.

             >>Recycle pool

                 This pool is intended for blocks that are usedinfrequently. A recycle pool prevent objects fromconsuming unnecessary space in the cache.

 

今天学到这里。下一次redo log buffer 于shared pool....

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值