0927hugepages與nr_overcommit_hugepages

lfree發表於2017-09-27

[20170927]hugepages與核心引數nr_overcommit_hugepages.txt

/proc/sys/vm/nr_overcommit_hugepages specifies how large the pool of huge pages can grow, if more huge pages than
/proc/sys/vm/nr_hugepages are requested by applications. Writing any non-zero value into this file indicates that the
hugetlb subsystem is allowed to try to obtain that number of "surplus" huge pages from the kernel's normal page pool,
when the persistent huge page pool is exhausted. As these surplus huge pages become unused, they are freed back to the
kernel's normal page pool.

--//從上面的說明可以看出設定這個引數可以減少hagepages的使用,避免設定過大導致的浪費.
--//我以前提到引數use_large_pages可以設定auto.參考連結:
--//  [20170313]11G use_large_pages引數.txt => http://blog.itpub.net/267265/viewspace-2135210/
--//  [20170516]11G use_large_pages引數2.txt => http://blog.itpub.net/267265/viewspace-2145480/

--//我提到設定引數use_large_pages=auto,雖然/etc/sysctl.conf配置vm.nr_hugepages = 105.
--//但是可以透過oradism命令啟動修改核心引數.但是如果關閉資料庫,我的測試配置的hugepage不會回收.

--//測試設定nr_overcommit_hugepages會發生什麼情況?

1.環境:
# cat /proc/version
Linux version 2.6.39-300.26.1.el5uek (mockbuild@ca-build56.us.oracle.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-52)) #1 SMP Thu Jan 3 18:31:38 PST 2013

# cat /proc/sys/vm/nr_overcommit_hugepages
0
--//預設是0.

# cat /proc/meminfo | grep -i hugepage
AnonHugePages:         0 kB
HugePages_Total:     305
HugePages_Free:       96
HugePages_Rsvd:       96
HugePages_Surp:      200
Hugepagesize:       2048 kB

--//資料庫配置情況:
SCOTT@book> show sga
Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes

SCOTT@book> show parameter use_large_pages
NAME            TYPE   VALUE
--------------- ------ -----
use_large_pages string AUTO

SYS@book> alter system set use_large_pages=only scope=spfile;
System altered.

--//如果引數為是Only,從含義上,表示Oracle例項只會使用HugePage作為記憶體使用。如果系統在AMM模式或者HugePage用盡的時候,數
--//據庫就不能啟動或者報錯。

--//關閉資料庫,修改/etc/sysctl.conf,再啟動看看:
SYS@book> shutdown immediate ;
Database closed.
Database dismounted.
ORACLE instance shut down.

--//修改/etc/sysctl.conf
vm.nr_hugepages = 105
vm.nr_overcommit_hugepages=1000

# sysctl -p

# cat /proc/meminfo | grep -i hugepage
AnonHugePages:         0 kB
HugePages_Total:     105
HugePages_Free:      105
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB
--//現在HugePages_Total: 105

--//注意檢查修改/etc/security/limits.conf內容:
oracle soft    memlock        unlimited
oracle hard    memlock        unlimited

--//再啟動資料庫看看:
SYS@book> startup
ORACLE instance started.
Total System Global Area  634732544 bytes
Fixed Size                  2255792 bytes
Variable Size             197133392 bytes
Database Buffers          427819008 bytes
Redo Buffers                7524352 bytes
Database mounted.
Database opened.

--//可以發現現在可以正常啟動!!檢查alert檔案:

Starting ORACLE instance (normal)
Specified value of sga_max_size is too small, bumping to 637534208
************************ Large Pages Information *******************
Parameter use_large_pages = ONLY
Per process system memlock (soft) limit = 51 GB
Total Shared Global Region in Large Pages = 610 MB (100%)
Large Pages used by this instance: 305 (610 MB)
Large Pages unused system wide = 0 (0 KB)
Large Pages configured system wide = 305 (610 MB)
Large Page size = 2048 KB
********************************************************************

--//可以發現我現在設定vm.nr_hugepages = 105,實際上使用305,但是資料庫可以正常啟動,而且use_large_pages = ONLY,也就是強制使
--//用hugepages.透過如下命令也可以發現:

# cat /proc/meminfo | grep -i hugepage
AnonHugePages:         0 kB
HugePages_Total:     305
HugePages_Free:       97
HugePages_Rsvd:       97
HugePages_Surp:      200
Hugepagesize:       2048 kB

SYS@book> shutdown immediate ;
Database closed.
Database dismounted.
ORACLE instance shut down.

# cat /proc/meminfo | grep -i hugepage
AnonHugePages:         0 kB
HugePages_Total:     105
HugePages_Free:      105
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB

--//可以發現使用的hupepages回收了.也就是使用的記憶體空間回收了.這樣的使用方式,可以一定程度避免記憶體浪費.

3.繼續測試現在設定vm.nr_overcommit_hugepages=0.
--//修改/etc/sysctl.conf
vm.nr_hugepages = 105
vm.nr_overcommit_hugepages=0

# sysctl -p
# cat /proc/meminfo | grep -i hugepage
AnonHugePages:         0 kB
HugePages_Total:     105
HugePages_Free:      105
HugePages_Rsvd:        0
HugePages_Surp:        0
Hugepagesize:       2048 kB

SYS@book> startup
ORA-27137: unable to allocate large pages to create a shared memory segment
Linux-x86_64 Error: 12: Cannot allocate memory
Additional information: 624951296
Additional information: 1

--//可以這樣無法獲得足夠的hugepages,資料庫無法啟動.修改回來後在啟動正常.
vm.nr_overcommit_hugepages=1000

總結:
透過設定這個引數,一定程度避免記憶體浪費,必須設定大的hugepages,而導致一些記憶體浪費,而且不使用時可以回收.

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

相關文章