[20191223]關於共享記憶體段相關問題3.txt

lfree發表於2019-12-23

[20191223]關於共享記憶體段相關問題3.txt

--//我一直很好奇如果設定核心引數kernel.shmmax = 68719476736足夠大,為什麼我的測試例項還是建立3個共享記憶體段.
--//最後1個很特殊key=0xe8a8ec10,大小2M,我看過許多伺服器只要key<>=0x00000000,最後都會有1個2M的共享記憶體段.
--//上個星期連結http://blog.itpub.net/267265/viewspace-2669718/=>[20191220]關於共享記憶體段相關問題.txt
--//實際上已經給出答案,我沒有寫清楚.主要不好表達.

--//oracle啟動建立的第1個共享記憶體段主要包括Fixed SGA Size +Redo Buffers.
--//oracle啟動建立的第2個共享記憶體段主要包括buffer cache,java pool,large pool,shared pool.

--//如何驗證log buffer在第1個共享記憶體段呢?

1.環境:
SCOTT@book> @ ver1
PORT_STRING                    VERSION        BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx            11.2.0.4.0     Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production

2.看看log_buffer在哪裡.
$ ipcs -m
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 451674112  oracle    640        12582912   27
0x00000000 451706881  oracle    640        633339904  27
0xe8a8ec10 451739650  oracle    640        2097152    27

$ ipcs -m | awk '{print $5/1024/1024}' | grep -v "^0"
12
604
2

$ cat memalloc.sql
col component format a32
select min(BASEADDR), max(BASEADDR), count(1) Granules, sum(a.gransize)/1048576 MB, a.GRANFLAGS, component, a.GRANSTATE
from x$ksmge a, x$kmgsct b
where a.grantype = b.grantype (+)
group by a.GRANFLAGS, component, a.GRANSTATE
order by 1,2;

pause press enter .....

select a.BASEADDR, a.gransize, a.GRANFLAGS, b.component, a.GRANSTATE
from x$ksmge a, x$kmgsct b
where a.grantype = b.grantype (+)
order by 1,2;

SYS@book> @ memalloc
MIN(BASEADDR)    MAX(BASEADDR)      GRANULES         MB  GRANFLAGS COMPONENT                        GRANSTATE
---------------- ---------------- ---------- ---------- ---------- -------------------------------- ----------------
0000000060C00000 0000000061C00000          5         20          4 streams pool                     ALLOC
0000000062000000 0000000086400000         48        192          4 shared pool                      ALLOC
0000000063400000 000000007A000000         92        368          4 DEFAULT buffer cache             ALLOC
000000007A400000 000000007AC00000          3         12          4 java pool                        ALLOC
000000007B000000 000000007B800000          3         12          4 large pool                       ALLOC
press enter .....
--//後面一段太長,不貼上來了.

$ cat imu.sql
 $ cat imu.sql
SELECT INDX
      ,FIRST_BUF_KCRFA
      ,last_buf_kcrfa
      ,PNEXT_BUF_KCRFA_CLN nxtbufadr
      ,NEXT_BUF_NUM_KCRFA_CLN nxtbuf#
      ,BYTES_IN_BUF_KCRFA_CLN "B/buf"
      ,PVT_STRAND_STATE_KCRFA_CLN state
      ,STRAND_NUM_ORDINAL_KCRFA_CLN strand#
      ,PTR_KCRF_PVT_STRAND stradr
      ,INDEX_KCRF_PVT_STRAND stridx
      ,SPACE_KCRF_PVT_STRAND strspc
      ,TXN_KCRF_PVT_STRAND txn
      ,TOTAL_BUFS_KCRFA totbufs#
      ,STRAND_SIZE_KCRFA strsz
  FROM X$KCRFSTRAND ;

SYS@book> @ imu
      INDX FIRST_BUF_KCRFA  LAST_BUF_KCRFA   NXTBUFADR           NXTBUF#      B/buf      STATE    STRAND# STRADR               STRIDX     STRSPC        TXN   TOTBUFS#      STRSZ
---------- ---------------- ---------------- ---------------- ---------- ---------- ---------- ---------- ---------------- ---------- ---------- ---------- ---------- ----------
         0 0000000060227000 0000000060590E00 000000006050E800       5947          0          0 3735928559 00                        0          0          0       6992    3579904
         1 0000000060591000 00000000608FAE00 0000000060592C00         13          0          0 3735928559 00                        0          0          0       6992    3579904
         2 0000000081E27000 00               00                        0          0          0 3735928559 0000000081E27054 3735928559     126464          0        249     132096
         3 0000000081E49000 00               00                        0          0          0 3735928559 0000000081E49054 3735928559     126464          1        249     132096
         4 0000000081E6A000 00               00                        0          0          0 3735928559 0000000081E6A054 3735928559     126464          2        249     132096
         5 0000000081E8B000 00               00                        0          0          0 3735928559 0000000081E8B054 3735928559     126464          3        249     132096
         6 0000000081EAC000 00               00                        0          0          0 3735928559 0000000081EAC054 3735928559     126464          4        249     132096
         7 0000000081ECE000 00               00                        0          0          0 3735928559 0000000081ECE054 3735928559     126464          5        249     132096
         8 0000000081EEF000 00               00                        0          0          0 3735928559 00                        0          0          0        249     132096
         9 0000000081F10000 00               00                        0          0          0 3735928559 00                        0          0          0        249     132096
        10 0000000081F31000 00               00                        0          0          0 3735928559 00                        0          0          0        249     132096
        11 0000000081F53000 00               00                        0          0          0 3735928559 00                        0          0          0        249     132096
        12 0000000081F74000 00               00                        0          0          0 3735928559 00                        0          0          0        249     132096
        13 0000000081F95000 00               00                        0          0          0 3735928559 00                        0          0          0        249     132096
        14 0000000081FB6000 00               00                        0          0          0 3735928559 00                        0          0          0        249     132096
        15 0000000081FD8000 00               00                        0          0          0 3735928559 00                        0          0          0        249     132096
        16 0000000081835000 00               00                        0          0          0 3735928559 00                        0          0          0        249     132096
        17 0000000081856000 00               00                        0          0          0 3735928559 00                        0          0          0        249     132096
        18 0000000081877000 00               00                        0          0          0 3735928559 00                        0          0          0        249     132096
19 rows selected.

SYS@book> show parameter log_buffer
NAME       TYPE     VALUE
---------- -------- ---------
log_buffer integer  7159808

SYS@book> @ hide _log_parallelism_max
NAME                 DESCRIPTION                          DEFAULT_VALUE SESSION_VALUE SYSTEM_VALUE ISSES ISSYS_MOD
-------------------- ------------------------------------ ------------- ------------- ------------ ----- ---------
_log_parallelism_max Maximum number of log buffer strands TRUE          2             2            FALSE FALSE

SYS@book> show parameter cpu_count
NAME      TYPE    VALUE
--------- ------- -----
cpu_count integer 24

--//cpu_count=24,這樣_log_parallelism_max預設ceil(cpu_count/16)=2.
--//log_buffer/2 =  7159808/2 = 3579904 .與執行@ imu 看到的STRAND_SIZE_KCRFA大小3579904一致.也就是@imu顯示的前2行對應log_buffer資訊.

$ ps -ef | grep lgw[r]
oracle   21810     1  0 Dec20 ?        00:00:27 ora_lgwr_book

$ cat /proc/21810/smaps  | grep -A1 SYSV
60000000-60c00000 rw-s 00000000 00:0b 451674112                          /SYSV00000000 (deleted)
Size:              12288 kB
--
60c00000-86800000 rw-s 00000000 00:0b 451706881                          /SYSV00000000 (deleted)
Size:             618496 kB
--
86800000-86a00000 rw-s 00000000 00:0b 451739650                          /SYSVe8a8ec10 (deleted)
Size:               2048 kB

--//注意看第1個共享記憶體段範圍60000000-60c00000,查詢@ imu的FIRST_BUF_KCRFA  LAST_BUF_KCRFA在這個範圍之內.可以證明log_buffer在第1個共享記憶體段內.
--//0x0000000060590E00 - 0x0000000060227000 = 3579392(10進位制), 3579392+512 = 3579904.大小等於STRAND_SIZE_KCRFA.
--//0x00000000608FAE00 - 0x0000000060591000 = 3579392(10進位制).
--//512 = 0x200
--//0x0000000060590E00 + 0x200 = 0x0000000060591000,正好等於index=1的FIRST_BUF_KCRFA=0000000060591000.

3.繼續測試:
SYS@book> oradebug setmypid
Statement processed.

SYS@book> oradebug DUMPvar SGA kcsgscn_
kcslf kcsgscn_ [06001AE70, 06001AEA0) = 17750548 00000003 00000000 00000000 000422E2 00000000 00000000 00000000 00000000 00000000 6001AB50 00000000

--//可以發現一些重要引數實際都定位在第1個共享記憶體段內.

$ cat fv2.sql
column fv_ksmfsnam heading SGAVARNAME for a50 wrap
column fv_ksmfstyp heading DATATYPE for a25 wrap
column fv_ksmmval_dec heading KSMMVAL_DEC for 99999999999999999999

prompt Display Fixed SGA Variables matching &1

select /*+ ORDERED USE_NL(m) */
    f.addr
  , f.indx
  , f.ksmfsnam fv_ksmfsnam
  , to_number(m.ksmmmval, 'XXXXXXXXXXXXXXXX') fv_ksmmval_dec
  , m.ksmmmval
  , f.ksmfstyp fv_ksmfstyp
  , f.ksmfsadr
  , f.ksmfssiz
from
    x$ksmfsv f, x$ksmmem m
where
    f.ksmfsadr = m.addr
and (lower(ksmfsnam) like lower('&1') or lower(ksmfstyp) like lower('&1'))
order by
    ksmfsnam
/

SYS@book>  @ tpt/fv2  kcsgscn_
Display Fixed SGA Variables matching %kcsgscn_%
old  14: and (lower(ksmfsnam) like lower('&1') or lower(ksmfstyp) like lower('&1'))
new  14: and (lower(ksmfsnam) like lower('%kcsgscn_%') or lower(ksmfstyp) like lower('%kcsgscn_%'))
ADDR                   INDX SGAVARNAME                                                   KSMMVAL_DEC KSMMMVAL         DATATYPE                  KSMFSADR           KSMFSSIZ
---------------- ---------- -------------------------------------------------- --------------------- ---------------- ------------------------- ---------------- ----------
0000000009B159E0       3260 kcsgscn_                                                     13278447743 000000031775087F kcslf                     000000006001AE70         48

--//如果查詢@ tpt/fv2  %,可以發現KSMFSADR地址都在第1個共享記憶體段內.

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

相關文章