[20170927]hugepages與內核參數nr_overcommit_hugepages.txt/proc/sys/vm/nr_overcommit_hugepages specifies how large the pool of huge pages can grow, if more h ...
[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 ([email protected]) (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,而導致一些記憶體浪費,而且不使用時可以回收.