[20260505]关于内核参数kernel.shmmax.txt

[20260505]关于内核参数kernel.shmmax.txt

--//在探究ipcs -m 输出shmid值遇到的问题,单独写一篇blog。

1.环境:
# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)

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.

2.测试:
SYS@book> startup nomount force
ORACLE instance started.
Total System Global Area 1107294056 bytes
Fixed Size                  9684840 bytes
Variable Size             654311424 bytes
Database Buffers          436207616 bytes
Redo Buffers                7090176 bytes

# ipcs -m --human
------ Shared Memory Segments --------
key        shmid      owner      perms      size       nattch     status
0x00000000 0          oracle     600           10M     34
0x00000000 32769      oracle     600            1G     34
0x00000000 65538      oracle     600            8M     34
0xafa94c20 98307      oracle     600            2M     34
--//显示1G,实际上是1090519040=1040M。

# ipcs -m
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 0          oracle     600        10485760   34
0x00000000 32769      oracle     600        1090519040 34
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
0x00000000 65538      oracle     600        8388608    34
0xafa94c20 98307      oracle     600        2097152    34

--//4个共享内存段,想人为拆分建立7个共享内存段。这样需要将1090519040/1024/1024 = 1040M分成4份。
--//1040/4 = 260M, 这样建立每个300M看看,换算成字节位 300*1024*1024 = 314572800。

3.继续:
# sysctl -w kernel.shmmax=$((300*1024*1024))
kernel.shmmax = 314572800

SYS@book> startup nomount force
ORACLE instance started.

Total System Global Area 1107294056 bytes
Fixed Size                  9684840 bytes
Variable Size             654311424 bytes
Database Buffers          436207616 bytes
Redo Buffers                7090176 bytes

#  ipcs -m --human
------ Shared Memory Segments --------
key        shmid      owner      perms      size       nattch     status
0x00000000 131072     oracle     600           10M     34
0x00000000 163841     oracle     600          288M     34
0x00000000 196610     oracle     600          288M     34
0x00000000 229379     oracle     600          288M     34
0x00000000 262148     oracle     600          176M     34
0x00000000 294917     oracle     600            8M     34
0xafa94c20 327686     oracle     600            2M     34

# ipcs -m
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 131072     oracle     600        10485760   34
0x00000000 163841     oracle     600        301989888  34
0x00000000 196610     oracle     600        301989888  34
0x00000000 229379     oracle     600        301989888  34
0x00000000 262148     oracle     600        184549376  34
0x00000000 294917     oracle     600        8388608    34
0xafa94c20 327686     oracle     600        2097152    34
--//建立7个共享内存段.
--//301989888/1024/1024 = 288M,实际上拆分的共享内存段选择的并不是300M,而是288+288+288+176 = 1040.
--//实际上上午的测试选择260M,实际上拆分的共享内存段选择的256M,这样拆分成5个段,加起来建立8个共享内存段.
--//没有满足测试需求,感觉应该与Granule Size大小相关。
SYS@book> select  *  from v$sgainfo where name = 'Granule Size';
NAME                                          BYTES RESIZE     CON_ID
---------------------------------------- ---------- ------ ----------
Granule Size                               16777216 No              0
--//猜测应该按照16倍数来选择共享段大小。这样如果按16倍数是256,272,288,304,这样选择304正好拆分.

# sysctl -w kernel.shmmax=$((304*1024*1024))
kernel.shmmax = 318767104

--//SYS@book> startup nomount force

#  ipcs -m --human
------ Shared Memory Segments --------
key        shmid      owner      perms      size       nattch     status
0x00000000 360448     oracle     600           10M     34
0x00000000 393217     oracle     600          304M     34
0x00000000 425986     oracle     600          304M     34
0x00000000 458755     oracle     600          304M     34
0x00000000 491524     oracle     600          128M     34
0x00000000 524293     oracle     600            8M     34
0xafa94c20 557062     oracle     600            2M     34
--//验证正确。

4.顺便测试最小kernel.shmmax等于多少。
# sysctl -w kernel.shmmax=$((16*1024*1024))
kernel.shmmax = 16777216

--//SYS@book> startup nomount force
#  ipcs -m --human
------ Shared Memory Segments --------
key        shmid      owner      perms      size       nattch     status
0x00000000 589824     oracle     600           10M     34
0x00000000 622593     oracle     600           16M     34
0x00000000 655362     oracle     600           16M     34
0x00000000 688131     oracle     600           16M     34
0x00000000 720900     oracle     600           16M     34
0x00000000 753669     oracle     600           16M     34
0x00000000 786438     oracle     600           16M     34
0x00000000 819207     oracle     600           16M     34
0x00000000 851976     oracle     600           16M     34
0x00000000 884745     oracle     600           16M     34
0x00000000 917514     oracle     600           16M     34
0x00000000 950283     oracle     600           16M     34
0x00000000 983052     oracle     600           16M     34
0x00000000 1015821    oracle     600           16M     34
0x00000000 1048590    oracle     600           16M     34
0x00000000 1081359    oracle     600           16M     34
0x00000000 1114128    oracle     600           16M     34
0x00000000 1146897    oracle     600           16M     34
0x00000000 1179666    oracle     600           16M     34
0x00000000 1212435    oracle     600           16M     34
0x00000000 1245204    oracle     600           16M     34
0x00000000 1277973    oracle     600           16M     34
0x00000000 1310742    oracle     600           16M     34
0x00000000 1343511    oracle     600           16M     34
0x00000000 1376280    oracle     600           16M     34
0x00000000 1409049    oracle     600           16M     34
0x00000000 1441818    oracle     600           16M     34
0x00000000 1474587    oracle     600           16M     34
0x00000000 1507356    oracle     600           16M     34
0x00000000 1540125    oracle     600           16M     34
0x00000000 1572894    oracle     600           16M     34
0x00000000 1605663    oracle     600           16M     34
0x00000000 1638432    oracle     600           16M     34
0x00000000 1671201    oracle     600           16M     34
0x00000000 1703970    oracle     600           16M     34
0x00000000 1736739    oracle     600           16M     34
0x00000000 1769508    oracle     600           16M     34
0x00000000 1802277    oracle     600           16M     34
0x00000000 1835046    oracle     600           16M     34
0x00000000 1867815    oracle     600           16M     34
0x00000000 1900584    oracle     600           16M     34
0x00000000 1933353    oracle     600           16M     34
0x00000000 1966122    oracle     600           16M     34
0x00000000 1998891    oracle     600           16M     34
0x00000000 2031660    oracle     600           16M     34
0x00000000 2064429    oracle     600           16M     34
0x00000000 2097198    oracle     600           16M     34
0x00000000 2129967    oracle     600           16M     34
0x00000000 2162736    oracle     600           16M     34
0x00000000 2195505    oracle     600           16M     34
0x00000000 2228274    oracle     600           16M     34
0x00000000 2261043    oracle     600           16M     34
0x00000000 2293812    oracle     600           16M     34
0x00000000 2326581    oracle     600           16M     34
0x00000000 2359350    oracle     600           16M     34
0x00000000 2392119    oracle     600           16M     34
0x00000000 2424888    oracle     600           16M     34
0x00000000 2457657    oracle     600           16M     34
0x00000000 2490426    oracle     600           16M     34
0x00000000 2523195    oracle     600           16M     34
0x00000000 2555964    oracle     600           16M     34
0x00000000 2588733    oracle     600           16M     34
0x00000000 2621502    oracle     600           16M     34
0x00000000 2654271    oracle     600           16M     34
0x00000000 2687040    oracle     600           16M     34
0x00000000 2719809    oracle     600           16M     34
0x00000000 2752578    oracle     600            8M     34
0xafa94c20 2785347    oracle     600            2M     34
--//2785347 = 0x2a8043,0x43+1 = 68,建立68个共享内存段。
--//顺便验证上午确定shmid的计算公式是否正确,确定下次启动ipcs -m 的shmid值:
2^16 * (B+S/2)
--//B:前次相乘因子 开始0,S 前次启动共享内存段数量, 开始0.

--//589824: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3
--//B = 9 ,S=68
2^16 * (B+S/2)  = 2^16 * (9+68/2) = 2818048

# sysctl -w kernel.shmmax=4398046511104
kernel.shmmax = 4398046511104

--//SYS@book> startup nomount force

# ipcs -m
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 2818048    oracle     600        10485760   34
0x00000000 2850817    oracle     600        1090519040 34
0x00000000 2883586    oracle     600        8388608    34
0xafa94c20 2916355    oracle     600        2097152    34
--//2818048,与猜测一致.
--//2818048: 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 43

5.继续测试:
# sysctl -w kernel.shmmax=$((8*1024*1024))
kernel.shmmax = 8388608

SYS@book> startup nomount force
ORA-12547: TNS:lost contact

--//无法在会话执行startup nomount force,连接已经断开.
--//只能重新登录,但是报ORA-12547: TNS:lost contact,kernel.shmmax只要小于16M,无法登录.
$ sqlplus -s -l / as sysdba
ERROR:
ORA-12547: TNS:lost contact
SP2-0751: Unable to connect to Oracle.  Exiting SQL*Plus

$ oerrz ORA-12547
12547, 00000, "TNS:lost contact"
// *Cause: Partner has unexpectedly gone away, usually during process
// startup.
// *Action: Investigate partner application for abnormal termination. On an
// Interchange, this can happen if the machine is overloaded.
--//这个提示能把dba带偏.

# sysctl -w kernel.shmmax=$((16*1024*1024))
kernel.shmmax = 16777216

$ sqlplus / as sysdba
SQL*Plus: Release 21.0.0.0.0 - Production on Tue May 5 16:10:43 2026
Version 21.3.0.0.0
Copyright (c) 1982, 2021, Oracle.  All rights reserved.
Connected to an idle instance.
SYS@book>

--//也就是最小设置kernel.shmmax = 16777216,这样与Granule Size也没有关系.

# sysctl -w kernel.shmmax=$((15*1024*1024))
kernel.shmmax = 15728640

--//即使停止监听,也是报一样的错误。

$ lsnrctl stop
LSNRCTL for Linux: Version 21.0.0.0.0 - Production on 05-MAY-2026 16:24:54
Copyright (c) 1991, 2021, Oracle.  All rights reserved.
Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.56.101)(PORT=1521)))
The command completed successfully

$ sqlplus -s -l / as sysdba <<<quit
ERROR:
ORA-12547: TNS:lost contact
SP2-0751: Unable to connect to Oracle.  Exiting SQL*Plus
--//如果这样定位问题需要一定难度,不会想到kernel.shmmax设置太小.

$ strace -f -y -o test9.txt sqlplus -s -l / as sysdba <<<quit
ERROR:
ORA-12547: TNS:lost contact
SP2-0751: Unable to connect to Oracle.  Exiting SQL*Plus

$ grep kernel test9.txt
5037  open("/proc/sys/kernel/shmmax", O_RDONLY) = 8
5037  fstat(8</proc/sys/kernel/shmmax>, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
5037  read(8</proc/sys/kernel/shmmax>, "15728640\n", 1024) = 9
5037  close(8</proc/sys/kernel/shmmax>) = 0
5038  open("/proc/sys/kernel/shmmax", O_RDONLY) = 4
5038  fstat(4</proc/sys/kernel/shmmax>, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
5038  read(4</proc/sys/kernel/shmmax>, "15728640\n", 1024) = 9
5038  close(4</proc/sys/kernel/shmmax>) = 0
--//涉及到内核参数仅仅取出kernel.shmmax值。


posted @ 2026-05-06 21:18  lfree  阅读(4)  评论(0)    收藏  举报