Oracle Share Pool內部管理機制
SHARE POOL利用堆(HEAP)的記憶體管理方式管理,在物理上由多個記憶體區(EXTENT)組成,記憶體區又由多個不同大小的CHUNK組成。而CHUNK又有可重用和空閑之分,並且它們分別有LRU LIST、FREE LIST、RESERVED LIST串聯起來。
堆管理
Shared Pool是利用堆記憶體管理方式管理的(KGH:Kernel Generic Heap).從Oracle 9i開始,可以有多個最進階堆(TOP-LEVLE HEAP),最進階堆可以分成多個副堆,副堆下面還擁有子堆。堆和副對結構基本相同。從物理上講,一個堆由多個記憶體區已link list的形式串連組成。一個記憶體區物理上使用一個Granule,一個記憶體區由多個chunk組成,所以chunk是heap的最小記憶體單位。
Chunk的使用方式可由X$KSMSP內部視圖查看。每個堆頭上則包含了可使用的chunk列表和已使用的chunk列表。通過dump heap命令可以在trace檔案中觀察heap和extent的關係。
alter system set events 'immediate trace name heapdump level 2';
--------------------------------------------------------------------------------
Linux-6-64下安裝Oracle 12C筆記
在CentOS 6.4下安裝Oracle 11gR2(x64)
Oracle 11gR2 在VMWare虛擬機器中安裝步驟
Debian 下 安裝 Oracle 11g XE R2
--------------------------------------------------------------------------------
案例:
SQL> select name,bytes/1024/1024 from v$sgainfo;
NAME BYTES/1024/1024
-------------------------------- ---------------
Fixed SGA Size 1.27566528
Redo Buffers 5.59765625
Buffer Cache Size 180
Shared Pool Size 104
Large Pool Size 4
Java Pool Size 4
Streams Pool Size 0
Shared IO Pool Size 0
Granule Size 4
Maximum SGA Size 498.875
Startup overhead in Shared Pool 52
NAME BYTES/1024/1024
-------------------------------- ---------------
Free SGA Memory Available 200
12 rows selected.
[oracle@node1 ~]$ more /u01/app/oracle/diag/rdbms/prod/prod/trace/prod_ora_14983.trc
Trace file /u01/app/oracle/diag/rdbms/prod/prod/trace/prod_ora_14983.trc
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options
ORACLE_HOME = /u01/app/oracle/product/11.2.0/db_1
System name: Linux
Node name: node1
Release: 2.6.18-194.el5
Version: #1 SMP Tue Mar 16 21:52:43 EDT 2010
Machine: i686
Instance name: prod
Redo thread mounted by this instance: 1
Oracle process number: 32
Unix process pid: 14983, image: oracle@node1 (TNS V1-V3)
*** 2014-07-02 14:58:47.532
*** SESSION ID:(32.758) 2014-07-02 14:58:47.532
*** CLIENT ID:() 2014-07-02 14:58:47.532
*** SERVICE NAME:(SYS$USERS) 2014-07-02 14:58:47.532
*** MODULE NAME:(sqlplus@node1 (TNS V1-V3)) 2014-07-02 14:58:47.532
*** ACTION NAME:() 2014-07-02 14:58:47.532
KGH Latch Directory Information
ldir state: 2 last allocated slot: 99
Slot [ 1] Latch: 0x200065ec Index: 1 Flags: 3 State: 2 next: (nil)
Slot [ 2] Latch: 0x3e75571c Index: 1 Flags: 3 State: 2 next: (nil)
......(省略)
Slot [ 99] Latch: 0x2002616c Index: 1 Flags: 3 State: 2 next: 0x1
******************************************************
HEAP DUMP heap name="sga heap" desc=0x200010b4
extent sz=0x7ad4 alt=124 het=32767 rec=9 flg=-126 opc=0
parent=(nil) owner=(nil) nex=(nil) xsz=0x0 heap=(nil)
fl2=0x60, nex=(nil)
ds for latch 1: 0x2002a990 0x2002b5c8 0x2002c200 0x2002ce38
reserved granule count 0 (granule size 4194304)
******************************************************
HEAP DUMP heap name="sga heap(1,0)" desc=0x2002a990
extent sz=0xfc4 alt=124 het=32767 rec=9 flg=-126 opc=0
parent=(nil) owner=(nil) nex=(nil) xsz=0x400000 heap=(nil)
fl2=0x20, nex=(nil)
latch set 1 of 1
durations enabled for this heap
reserved granules for root 0 (granule size 4194304)
EXTENT 0 addr=0x3b800000
Chunk 3b800038 sz= 24 R-freeable "reserved stoppe"
Chunk 3b800050 sz= 212888 R-free " "
Chunk 3b833fe8 sz= 24 R-freeable "reserved stoppe"
Chunk 3b834000 sz= 3981312 perm "perm " alo=3290272
EXTENT 1 addr=0x3bc00000
Chunk 3bc00038 sz= 24 R-freeable "reserved stoppe"
Chunk 3bc00050 sz= 212888 R-free " "
Chunk 3bc33fe8 sz= 24 R-freeable "reserved stoppe"
Chunk 3bc34000 sz= 3510272 perm "perm " alo=3510272
Chunk 3bf8d000 sz= 465920 perm "perm " alo=465920
Chunk 3bffec00 sz= 5120 free " "
EXTENT 2 addr=0x3c000000
Chunk 3c000038 sz= 24 R-freeable "reserved stoppe"
Chunk 3c000050 sz= 212888 R-free " "
Chunk 3c033fe8 sz= 24 R-freeable "reserved stoppe"
Chunk 3c034000 sz= 3850176 perm "perm " alo=3850176
Chunk 3c3dffc0 sz= 131088 perm "perm " alo=131088
Chunk 3c3fffd0 sz= 48 free " "
EXTENT 3 addr=0x3c400000
Chunk 3c400038 sz= 24 R-freeable "reserved stoppe"
Chunk 3c400050 sz= 212888 R-free " "
Chunk 3c433fe8 sz= 24 R-freeable "reserved stoppe"
Chunk 3c434000 sz= 3980368 perm "perm " alo=3980368
Chunk 3c7ffc50 sz= 944 free " "
EXTENT 4 addr=0x3c800000
Chunk 3c800038 sz= 24 R-freeable "reserved stoppe"
Chunk 3c800050 sz= 212888 R-free " "
Chunk 3c833fe8 sz= 24 R-freeable "reserved stoppe"
Chunk 3c834000 sz= 3672700 perm "perm " alo=3672700
Chunk 3cbb4a7c sz= 308240 perm "perm " alo=308240
Chunk 3cbffe8c sz= 372 free " "
CHUNK
Chunk是以鏈條(chain)的方式存在於記憶體區,每個chunk包含header和body兩部分,chunk的狀態大體上可以分為free(可立即使用)、recreatable(可再生)、freeable(只有在session或call期間內儲存必要的對象狀態)、permanent(永久、不可再生)等,其中free和recreatable狀態下的chunk可以重複使用。
FREE LIST
Free list主要用於管理閒置chunk,並且是用bucket管理的。從Oracle 9i開始,一個heap總共255個bucket,bucket所包含的free chunk大小隨bucket的編號增加而遞增,個bucket下的free chunk已linked list的形式連結。
(1)獲得shared pool latch在free list中尋找合適大小的空閑chunk。如果在擷取shared pool latch時發生了爭用,則會出現latch:shared pool等待事件。這時Oracle會一直持有shared pool latch,直到獲得所需的記憶體為止。所在記憶體片段化比較嚴重的shared pool中,進程持有shared pool latch的時間也會相應變長。
(2)如果不存在合適大小的空閑chunk,則在���找到更大的空閑chunk後分割(split)使用,分割後剩下的記憶體地區則重新登記到free list中。分割記憶體意味著記憶體中的片段開始增多。由於每個cursor所需記憶體的大小不同,所以shared pool的空閑記憶體不像buffer cache中的空閑記憶體一樣具有固定大小。
(3)如果檢索了free list也沒有找到所有合適的空閑chunk,則檢索lru list。lru list上的chunk是重建(recreatable)的,而且是當前不使用的(沒有處於pin狀態)。
(4)如果在lru list上也沒有找到合適的chunk,且所請求的記憶體還沒有達到隱含參數_shared_pool_reserved_min_alloc的閾值,則追加分配share pool中剩餘的記憶體空間。
(5)如果以上請求的記憶體均失敗,則出現ORA-4031錯誤
FREE LISTS:
Bucket 0 size=16
Bucket 1 size=20
Bucket 2 size=24
Bucket 3 size=28
Bucket 4 size=32
Bucket 5 size=36
Bucket 6 size=40
Bucket 7 size=44
Bucket 8 size=48
Chunk 3c3fffd0 sz= 48 free " "
Chunk 3ebfffd0 sz= 48 free " "
Bucket 9 size=52
Bucket 10 size=56
Bucket 11 size=60
Bucket 12 size=64
Bucket 13 size=68
Bucket 14 size=72
Bucket 15 size=76
Bucket 16 size=80
Bucket 17 size=84
Bucket 18 size=88
Chunk 3e7fffa8 sz= 88 free " "
Bucket 19 size=92
Bucket 20 size=96
Bucket 21 size=100
Bucket 22 size=104
Bucket 23 size=108
Bucket 24 size=112
Bucket 25 size=116
Bucket 26 size=120
Bucket 27 size=124
......
更多詳情見請繼續閱讀下一頁的精彩內容: