ITPub博客

首页 > 数据库 > Oracle > [20260920]skgm表示什么.txt

[20260920]skgm表示什么.txt

原创 Oracle 作者:lfree 时间:2026-09-21 21:19:56 0 删除 编辑

[20260920]skgm表示什么.txt

--//最近通过跟踪shmget,知道oracle内部通过skgmhash函数计算ipcs -m的key值.这里的skgm表示什么意思呢?
--//oracle 许多函数采用英文的缩略写.
$ ./lookup.awk skgm
skgm : operating system dependent kernel generic memory (os dependent)

--// k表示kernel g表示generic m表示memory,前面的s也许表示system.

--//如果查看oradebug ipc的转储,可以发现其中1个共享内存段skgm overhead.

1.环境:
SYS@book> @ ver2
==============================
PORT_STRING                   : x86_64/Linux 2.4.xx
VERSION                       : 21.0.0.0.0
BANNER                        : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
BANNER_FULL                   : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0
BANNER_LEGACY                 : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
CON_ID                        : 0
PL/SQL procedure successfully completed.

$ ipcs -m
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 0          oracle     600        10485760   78
0x00000000 1          oracle     600        1140850688 78
0x00000000 2          oracle     600        8388608    78
0xafa94c20 3          oracle     600        2097152    78

2.查看oradebug ipc的转储.

SYS@book> oradebug setmypid
Statement processed.

SYS@book> oradebug ipc
IPC information written to the trace file

--//查看跟踪文件内容:

*** 2026-09-21T16:01:42.483661+08:00 (CDB$ROOT(1))
Processing Oradebug command 'ipc'
Dump of unix-generic skgm context
areaflags            00001fb7
realmflags           0003ffff
mapsize              00001000
protectsize          00001000
lcmsize              00001000
seglen               00001000
largestsize  0000040000000000
smallestsize 0000000001000000
stacklimit     0x7fff843737b2
stackdir                   -1
mode                      600
magic                acc01ade
 Dump of unix-generic realm handle `/u01/app/oracle/product/21.0.0/dbhome_1book', flags = 00000100
  key 2947107872 actual_key 2947107872 num_areas 4 num_subareas 4
  primary shmid: 3 primary sanum 3 version 3
  deferred alloc: FALSE (0) def_post_create: FALSE (0) exp_memlock: 1108M
 Area #0 `Fixed Size' containing Subareas 2-2
  Total size 000000000093c7f8 Minimum Subarea size 00000000
   Area  Subarea    Shmid    Segment Addr    Stable Addr    Actual Addr
      0        2        0 0x00000060000000 0x00000060000000 0x00000060000000
               Subarea size     Segment size   Req_Protect  Cur_protect
                          000000000093d000 0000000000a00000 default       readwrite
 Area #1 `Variable Size' containing Subareas 0-0
  Total size 0000000044000000 Minimum Subarea size 01000000
   Area  Subarea    Shmid    Segment Addr    Stable Addr    Actual Addr
      1        0        1 0x00000061000000 0x00000061000000 0x00000061000000
               Subarea size     Segment size   Req_Protect  Cur_protect
                          0000000044000000 0000000044000000 default       readwrite
 Area #2 `Redo Buffers' containing Subareas 1-1
  Total size 00000000006c3000 Minimum Subarea size 00001000
   Area  Subarea    Shmid    Segment Addr    Stable Addr    Actual Addr
      2        1        2 0x000000a5000000 0x000000a5000000 0x000000a5000000
               Subarea size     Segment size   Req_Protect  Cur_protect
                          00000000006c3000 0000000000800000 default       readwrite
 Area #3 `skgm overhead' containing Subareas 3-3
  Total size 0000000000004000 Minimum Subarea size 00000000
   Area  Subarea    Shmid    Segment Addr    Stable Addr    Actual Addr
      3        3        3 0x000000a6000000 0x000000a6000000 0x000000a6000000
               Subarea size     Segment size   Req_Protect  Cur_protect
                          0000000000004000 0000000000200000 default       readwrite
--//第一部分是'Fixed Size',即固定 SGA ;第二部分是'Variable Size',包含共享池和缓冲缓存;第三部分是'Redo Buffers',即日
--//志缓存;第四部分是'skgm overhead',即该实例共享内存结构的索引,可以猜测里面保存其他共享内存段的相关信息,oracle的登录
--//连接数据库,先通过读取它,获取其他数据库的相关信息。

$ strace  -f  -e ipc  sqlplus -s -l / as sysdba <<<"host sleep 2"
strace: Process 3569 attached
[pid  3569] shmget(0xafa94c20, 0, 000)  = 3
[pid  3569] shmctl(3, IPC_STAT, {shm_perm={uid=54321, gid=54321, mode=0600, key=2947107872, cuid=54321, cgid=54321}, shm_segsz=2097152, shm_cpid=3026, shm_lpid=3563, shm_nattch=56, shm_atime=1789977953, shm_dtime=1789977955, shm_ctime=1789977489}) = 0
[pid  3569] shmat(3, NULL, 0)           = 0x7fc048200000
[pid  3569] shmdt(0x7fc048200000)       = 0
[pid  3569] shmget(0xafa94c21, 0, 000)  = -1 ENOENT (No such file or directory)
[pid  3569] shmget(0xafa94c22, 0, 000)  = -1 ENOENT (No such file or directory)
[pid  3569] shmget(0xafa94c23, 0, 000)  = -1 ENOENT (No such file or directory)
[pid  3569] shmat(3, 0xa6000000, 0)     = 0xa6000000
[pid  3569] shmat(1, 0x61000000, 0)     = 0x61000000
[pid  3569] shmat(2, 0xa5000000, 0)     = 0xa5000000
[pid  3569] shmat(0, 0x60000000, 0)     = 0x60000000
[pid  3569] shmget(0xa93a2388, 0, 000)  = -1 ENOENT (No such file or directory)
[pid  3569] shmget(0xa93a2389, 0, 000)  = -1 ENOENT (No such file or directory)
[pid  3569] shmget(0xa93a238a, 0, 000)  = -1 ENOENT (No such file or directory)
[pid  3569] shmget(0xa93a238b, 0, 000)  = -1 ENOENT (No such file or directory)
[pid  3569] --- SIGSEGV {si_signo=SIGSEGV, si_code=SEGV_MAPERR, si_addr=0x2} ---
strace: Process 3570 attached
[pid  3570] +++ exited with 0 +++
[pid  3568] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=3570, si_uid=54321, si_status=0, si_utime=0, si_stime=0} ---

[pid  3569] shmdt(0x61000000)           = 0
[pid  3569] shmdt(0xa5000000)           = 0
[pid  3569] shmdt(0x60000000)           = 0
[pid  3569] shmdt(0xa6000000)           = 0
[pid  3568] +++ exited with 0 +++
+++ exited with 0 +++
--//先shmat(3, NULL, 0) = 0x7fc048200000,获取地址,然后shmdt(0x7fc048200000) = 0断开。
--//再次连接上,第2次参数不在时NULL,直接知道开始地址。
shmat(3, 0xa6000000, 0)     = 0xa6000000
shmat(1, 0x61000000, 0)     = 0x61000000
shmat(2, 0xa5000000, 0)     = 0xa5000000
shmat(0, 0x60000000, 0)     = 0x60000000

--//另外可以发现skgm overhead共享内存段大小等于2m,因为启动设置use_large_pages=only,这样全部建立的共享内存端使用都是
--//hugepages,这样最小分配2M。

3.设置use_large_pages=true.

$ cat /u01/app/oracle/dbs/initbook.ora
SPFILE='/u01/app/oracle/dbs/spfilebook.ora'
use_large_pages=true

--//关闭并重新启动数据库.
SYS@book> startup pfile=/u01/app/oracle/dbs/initbook.ora
ORACLE instance started.
Total System Global Area 1157625848 bytes
Fixed Size                  9684984 bytes
Variable Size             704643072 bytes
Database Buffers          436207616 bytes
Redo Buffers                7090176 bytes
Database mounted.
Database opened.

$ ipcs -m
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 4          oracle     600        10485760   56
0x00000000 5          oracle     600        1140850688 56
0x00000000 6          oracle     600        8388608    56
0xafa94c20 7          oracle     600        16384      56
--//对比前面第四部分是'skgm overhead'仅仅16384字节。

$ pmap -X $(pgrep pmon) | grep -E "SYSV|Address"
 Address Perm   Offset Device    Inode    Size   Rss  Pss Referenced Anonymous LazyFree ShmemPmdMapped FilePmdMapped Shared_Hugetlb Private_Hugetlb Swap SwapPss Locked THPeligible Mapping
60000000 rw-s 00000000  00:10        4   10240     0    0          0         0        0              0             0           4096               0    0       0      0           0 SYSV00000000 (deleted)
61000000 rw-s 00000000  00:10        5 1114112     0    0          0         0        0              0             0          83968               0    0       0      0           0 SYSV00000000 (deleted)
a5000000 rw-s 00000000  00:10        6    8192     0    0          0         0        0              0             0              0               0    0       0      0           0 SYSV00000000 (deleted)
a6000000 rw-s 00000000  00:01        7      16    16   12         16         0        0              0             0              0               0    0       0      0           0 SYSVafa94c20 (deleted)

$ pmap -x $(pgrep pmon) | grep -E "SYSV|shmid|^Address"
Address           Kbytes     RSS   Dirty Mode  Mapping
0000000060000000   10240       0       0 rw-s- SYSV00000000 (deleted)
0000000061000000 1114112       0       0 rw-s- SYSV00000000 (deleted)
00000000a5000000    8192       0       0 rw-s- SYSV00000000 (deleted)
00000000a6000000      16       4       4 rw-s-   [ shmid=0x7 ]

$ xxd -a -c 32 -g 4 -s 0x00000000a6000000  -l 16384 /proc/3786/mem
a6000000: 2f753031 2f617070 2f6f7261 636c652f 70726f64 7563742f 32312e30 2e302f64  /u01/app/oracle/product/21.0.0/d
a6000020: 62686f6d 655f3162 6f6f6b00 00000000 00000000 00000000 00000000 00000000  bhome_1book.....................
a6000040: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000  ................................
*
a6000100: 2b000000 00000000 53484152 45442047 4c4f4241 4c204152 45412028 53474129  +.......SHARED GLOBAL AREA (SGA)
a6000120: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000  ................................
a6000140: 00000000 00000000 00000000 00000000 00000060 00000000 00000000 00800000  ...................`............
a6000160: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000  ................................
*
a6000260: 00000000 00000000 00000000 00000000 204ca9af 204ca9af 04000000 04000000  ................ L.. L..........
a6000280: 07000000 03000000 03000000 00000000 3879557e 00000000 00000000 00000000  ................8yU~............
a60002a0: 00000000 00000000 00000000 00000000 01000000 00000000 00000000 00000000  ................................
a60002c0: 00000000 00000000 00000000 00000000 00402045 00000000 00100000 00000000  .................@ E............
a60002e0: 01000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000  ................................
a6000300: 00000000 00000000 00000000 00000000 04000000 00000000 04000000 00000000  ................................
a6000320: 00002000 00000000 01000000 00000000 00000000 00000000 00000000 00000000  .. .............................
a6000340: 00000000 00000000 00000000 00000000 00000000 00000000 29020000 00000000  ........................).......
a6000360: 29020000 00000000 00000000 00000000 00000000 00000000 00000000 00000000  )...............................
a6000380: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000  ................................
*
a6000500: 00000000 00000000 00000000 00000000 00000000 00000000 02000000 02000000  ................................
a6000520: 11baceba 00000000 00000001 00000000 00000000 00000000 00000000 00000000  ................................
a6000540: 00000000 00000000 00000000 04000000 00000000 00000000 00000060 00000000  ...........................`....
a6000560: 00000000 204ca9af 46697865 64205369 7a650000 00000000 00000000 00000000  .... L..Fixed Size..............
a6000580: 00000000 00000000 0a000000 00000000 00000060 00000000 00000000 00000000  ...................`............
a60005a0: f8c79300 00000000 00000000 00000000 00000000 00000000 17120000 00000000  ................................
a60005c0: 00000000 00000000 ffffffff ffffffff 05000000 00000000 02000000 01000000  ................................
a60005e0: 56617269 61626c65 2053697a 65000000 00000000 00000000 00000000 00000000  Variable Size...................
a6000600: 0d000000 00000000 00000000 00000000 00000000 00000000 00000044 00000000  ...........................D....
a6000620: 00000001 00000000 00000000 00000000 12020000 00000000 00000000 00000000  ................................
a6000640: ffffffff ffffffff 05000000 00000000 00000000 01000000 5265646f 20427566  ........................Redo Buf
a6000660: 66657273 00000000 00000000 00000000 00000000 00000000 0c000000 00000000  fers............................
a6000680: 00000000 00000000 00000000 00000000 00306c00 00000000 00100000 00000000  .................0l.............
a60006a0: 00000000 00000000 13120000 00000000 00000000 00000000 ffffffff ffffffff  ................................
a60006c0: 05000000 00000000 01000000 01000000 736b676d 206f7665 72686561 64000000  ................skgm overhead...
a60006e0: 00000000 00000000 00000000 00000000 0d000000 00000000 00000000 00000000  ................................
a6000700: 00400000 00000000 00400000 00000000 00000000 00000000 00000000 00000000  .@.......@......................
a6000720: 13020010 00000000 00000000 00000000 ffffffff ffffffff 05000000 00000000  ................................
a6000740: 03000000 01000000 00000061 00000000 00000061 00000000 00000044 00000000  ...........a.......a.......D....
a6000760: 00000044 00000000 00000000 00000000 00002000 00000000 05000000 01000000  ...D.............. .............
a6000780: 00000000 00000000 00000000 01000000 01000000 00000000 00000000 ca0e0000  ................................
a60007a0: 00000000 01000000 000000a5 00000000 000000a5 00000000 00306c00 00000000  .........................0l.....
a60007c0: 00008000 00000000 00000000 00000000 00002000 00000000 06000000 02000000  .................. .............
a60007e0: 01000000 00000000 00000000 01000000 01000000 00000000 00000000 ca0e0000  ................................
a6000800: 00000000 01000000 00000060 00000000 00000060 00000000 00d09300 00000000  ...........`.......`............
a6000820: 0000a000 00000000 00000000 00000000 00002000 00000000 04000000 00000000  .................. .............
a6000840: 02000000 00000000 00000000 01000000 01000000 00000000 00000000 ca0e0000  ................................
a6000860: 00000000 01000000 000000a6 00000000 000000a6 00000000 00400000 00000000  .........................@......
a6000880: 00400000 00000000 00000000 00000000 00100000 00000000 07000000 03000000  .@..............................
a60008a0: 03000000 00000000 00000000 01000000 00000000 00000000 00000000 00000000  ................................
a60008c0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000  ................................
*
a6003fe0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000  ................................

--//这样不直观,intel cpu 使用Little endian,key=0xafa94c20 大小头对调 0x204ca9af,其他地址类似。
$ xxd -a -c 32 -g 4 -s 0x00000000a6000000  -l 16384 /proc/3786/mem | egrep "204ca9af|000000a6|00000061|00000060|000000a5"
a6000140: 00000000 00000000 00000000 00000000 00000060 00000000 00000000 00800000  ...................`............
a6000260: 00000000 00000000 00000000 00000000 204ca9af 204ca9af 04000000 04000000  ................ L.. L..........
a6000540: 00000000 00000000 00000000 04000000 00000000 00000000 00000060 00000000  ...........................`....
a6000560: 00000000 204ca9af 46697865 64205369 7a650000 00000000 00000000 00000000  .... L..Fixed Size..............
a6000580: 00000000 00000000 0a000000 00000000 00000060 00000000 00000000 00000000  ...................`............
a6000740: 03000000 01000000 00000061 00000000 00000061 00000000 00000044 00000000  ...........a.......a.......D....
a60007a0: 00000000 01000000 000000a5 00000000 000000a5 00000000 00306c00 00000000  .........................0l.....
a6000800: 00000000 01000000 00000060 00000000 00000060 00000000 00d09300 00000000  ...........`.......`............
                                              ~~~~~~~~          ~~~~~~~~
a6000860: 00000000 01000000 000000a6 00000000 000000a6 00000000 00400000 00000000  .........................@......

--//再次贴出oradebug ipc的输出。
 Dump of unix-generic realm handle `/u01/app/oracle/product/21.0.0/dbhome_1book', flags = 00000100
  key 2947107872 actual_key 2947107872 num_areas 4 num_subareas 4
  primary shmid: 3 primary sanum 3 version 3
  deferred alloc: FALSE (0) def_post_create: FALSE (0) exp_memlock: 1108M
 Area #0 `Fixed Size' containing Subareas 2-2
  Total size 000000000093c7f8 Minimum Subarea size 00000000
   Area  Subarea    Shmid    Segment Addr    Stable Addr    Actual Addr
      0        2        0 0x00000060000000 0x00000060000000 0x00000060000000
               Subarea size     Segment size   Req_Protect  Cur_protect
                          000000000093d000 0000000000a00000 default       readwrite
                          ~~~~~~~~~~~~~~~~
 Area #1 `Variable Size' containing Subareas 0-0
  Total size 0000000044000000 Minimum Subarea size 01000000
   Area  Subarea    Shmid    Segment Addr    Stable Addr    Actual Addr
      1        0        1 0x00000061000000 0x00000061000000 0x00000061000000
               Subarea size     Segment size   Req_Protect  Cur_protect
                          0000000044000000 0000000044000000 default       readwrite
 Area #2 `Redo Buffers' containing Subareas 1-1
  Total size 00000000006c3000 Minimum Subarea size 00001000
   Area  Subarea    Shmid    Segment Addr    Stable Addr    Actual Addr
      2        1        2 0x000000a5000000 0x000000a5000000 0x000000a5000000
               Subarea size     Segment size   Req_Protect  Cur_protect
                          00000000006c3000 0000000000800000 default       readwrite
 Area #3 `skgm overhead' containing Subareas 3-3
  Total size 0000000000004000 Minimum Subarea size 00000000
   Area  Subarea    Shmid    Segment Addr    Stable Addr    Actual Addr
      3        3        3 0x000000a6000000 0x000000a6000000 0x000000a6000000
               Subarea size     Segment size   Req_Protect  Cur_protect
                          0000000000004000 0000000000200000 default       readwrite

--//下划线对应实际使用的Segment size,也可以在grep的过滤里面发现。
--//例子:
0x00d09300 大小头对调 0x0093d000 = 9687040 ,而共享内存段大小 0xa00000 = 10485760。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/267265/viewspace-3183394/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
熟悉oracle相关技术,擅长sql优化,rman备份与恢复,熟悉linux shell编程。

注册时间:2008-01-03

  • 博文量
    4006
  • 访问量
    7969199