[20210902]為什麼會使用多個共享記憶體段.txt

lfree發表於2021-09-02

[20210902]為什麼會使用多個共享記憶體段.txt

--//昨天測試kernel.sem = SEMMSL SEMMNS SEMOPM SEMMNI引數時遇到的問題,做一個記錄.

1.環境:
--//為了反覆測試,我建立一個例項,沒有資料檔案.
$ cat /tmp/test.ora
test.__db_cache_size=1258291200
test.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
test.__shared_pool_size=1048576000
*.db_name='test'
*.processes=200
*.sga_target=2500M
*.undo_management='auto'

--//設定環境變數:
$ export ORACLE_SID=test

# egrep "^kernel.s[he]|^vm.nr_" /etc/sysctl.conf
kernel.shmmax = 68719476736
kernel.shmall = 4294967296
kernel.shmmni = 4096
kernel.sem = 102 26112 204 128
vm.nr_hugepages = 404
vm.nr_overcommit_hugepages = 1300

# sysctl -p

--//kernel.shmmax=68719476736, 68719476736/1024/1024/1024 = 64G,理論sga_target=2500M,11g下正常建立3個共享記憶體段.
--//可是實際情況確實6個.透過例子說明.

2.測試:
SYS@test> startup force nomount pfile='/tmp/@.ora';
ORACLE instance started.
Total System Global Area 2622255104 bytes
Fixed Size                  2256112 bytes
Variable Size            1124074256 bytes
Database Buffers         1476395008 bytes
Redo Buffers               19529728 bytes

$ ipcs -m

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 45645826   oracle    640        33554432   18
0x00000000 45678595   oracle    640        654311424  18
0x00000000 45711364   oracle    640        134217728  18
0x00000000 45744133   oracle    640        16777216   18
0x00000000 45776902   oracle    640        1795162112 18
0x8a931fb8 45809671   oracle    640        2097152    18
--//使用6個共享記憶體段.

$ ipcs -m -u
------ Shared Memory Status --------
segments allocated 8
pages allocated 643681
pages resident  79750
pages swapped   0
Swap performance: 0 attempts     0 successes
--//segments allocated 8 ,實際上有2個被root使用者使用.如果仔細看alert日誌:

Starting ORACLE instance (normal)
************************ Large Pages Information *******************
Per process system memlock (soft) limit = 60 GB
Total Shared Global Region in Large Pages = 802 MB (31%)
Large Pages used by this instance: 401 (802 MB)
Large Pages unused system wide = 3 (6144 KB)
Large Pages configured system wide = 404 (808 MB)
Large Page size = 2048 KB

RECOMMENDATION:
  Total System Global Area size is 2514 MB. For optimal performance,
  prior to the next instance restart:
  1. Increase the number of unused large pages by
 at least 853 (page size 2048 KB, total size 1706 MB) system wide to
  get 100% of the System Global Area allocated with large pages
********************************************************************

--//噢,我給hugepages僅僅404,完全不能滿足需求,但是我定義了vm.nr_overcommit_hugepages = 1300,1300*2M=2600M,完全滿足不需要
--//建立使用這麼多的共享記憶體段.為什麼呢?
--//仔細看http://blog.itpub.net/267265/viewspace-2145481/=>0927hugepages與nr_overcommit_hugepages
--//才發現要定義use_large_pages=only才可以使用.

$ cat /tmp/test.ora
test.__db_cache_size=1258291200
test.__oracle_base='/u01/app/oracle'#ORACLE_BASE set from environment
test.__shared_pool_size=1048576000
*.db_name='test'
*.processes=200
*.sga_target=2500M
*.undo_management='auto'
*.use_large_pages=only

SYS@test> startup force nomount pfile='/tmp/@.ora';
ORACLE instance started.
Total System Global Area 2622255104 bytes
Fixed Size                  2256112 bytes
Variable Size            1124074256 bytes
Database Buffers         1476395008 bytes
Redo Buffers               19529728 bytes

$ ipcs -m
------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x00000000 45875202   oracle    640        33554432   18
0x00000000 45907971   oracle    640        2600468480 18
0x8a931fb8 45940740   oracle    640        2097152    18

$ ipcs -m -u
------ Shared Memory Status --------
segments allocated 5
pages allocated 643681
pages resident  131681
pages swapped   0
Swap performance: 0 attempts     0 successes

--//這樣就對了.有時候陷入困境,思維一下子跳不出來.
--//alert.log
************************ Large Pages Information *******************
Parameter use_large_pages = only
Per process system memlock (soft) limit = 60 GB

Total Shared Global Region in Large Pages = 2514 MB (100%)

Large Pages used by this instance: 1257 (2514 MB)
Large Pages unused system wide = 0 (0 KB)
Large Pages configured system wide = 1257 (2514 MB)
Large Page size = 2048 KB
********************************************************************

# grep -i pages /proc/meminfo
AnonPages:        277180 kB
AnonHugePages:     86016 kB
HugePages_Total:    1257
HugePages_Free:     1000
HugePages_Rsvd:     1000
HugePages_Surp:      853
Hugepagesize:       2048 kB

--//HugePages_Total: 1257,從vm.nr_overcommit_hugepages借用了853,853+404 = 1257.
--//HugePages_Total-HugePages_Free+HugePages_Rsvd 就是 目前例項需要的頁面數量.

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

相關文章