Sunday, October 5, 2014

Oracle Shared Pool Free Space



Comparing shared pool with buffer cache, buffer cache uses a single chuck size.  Requests to shared pool however varies in sizes.  Therefore, the management of buffer cache is relatively simplier.  To satisfy a request, the buffer cache just supplies the first item on the free list.  For shared pool, the objective is to find the chunch with the appropriate size quickly.

Oracle reserves about 5% of space from each granule (unit of allocation that make up each pool in SGA).  This is the reserved pool for large object (>4MB).  Separating the large objects from smaller ones reduce the degree of fragmentation.  Flanking the reserved pool chunk are 2 24-bytes chunks called reserved stopper.  The stopper is to help to ensure the free reserved pool will not be merged with adjacent free block.

In the extent dump, both chunks labelled recreate and freeable are free chunk.  The heap manager (which manage the shared pool) issue call to destroy the recreate chunk when it needs space.  The call will be issued to the specific SGA pool manager (e.g. Lib cache manager) which will actually carry out the destroy request.  The freeable chunks links to recreateable chunk.  When the recreateable chunk is freed, the associated freeable chunks will also be freed at the same time.  Note that there is no direct call to the Lib Manager to destroy a freeable chunk. Only call to destroying the recreateable chunk is available.

There are a large number of free lists for the shared pool because the size of space requests varies.  The first 176 lists holds chunk of increment of 4 bytes.  the next few increment by 12 bytes.  Then the next few increment by 64 bytes and so on.  If Oracle need to find space for a certain size and the best fit list does not have free space, Oracle look at the list with the next bigger size.  When a free chunk is used and the size of the free chunk is larger than the request (because there is no free chunk with exact size match), the remaining free space may be considered used or return to a free list of smaller size depending on the size differential.

LRU list in shared pool contain recreateable chunks only.  The LRU list is divided into 2 sub-lists: one list is called recurrent and the other called transient.  Recurrent list contains chunk that are used repeatedly recently (hot) and the transient list contains chunks that are not used recently (cold).  When a chunk is inserted, it is place in the head of the transient list.  When the chunk is reused, it is transferred to the head of the recurrent list.

When the freelist does not contain chunk with size large enough to satisfy the request, Oracle will go for the LRU list.  It will free some chunks which are not pinned from the transient list, transferred these chunk to the free list and check again if there is enough space for the request. If not, it will repeat this process for a few times.  After a definite time and no contiguous freespace is available, Oracle issue the 4031 error.

No comments: