大页内存管理在Oracle数据上的应用
Oracle对运行在机器内存超过32G上的数据库推荐使用HugePages 来容纳Oracle数据库的SGA,参见。
Note: 401749.1 - Shell Script to Calculate Values Recommended Linux HugePages / HugeTLB Configuration
Note: 361323.1 - HugePages on Linux: What It Is… and What It Is Not…
在linux上配置sga使用hugepage的方法参见: https://blog.csdn.net/weixin_43424368/article/details/104518609
在linux上大页管理使内存的管理单位从4K提高到2M,大大提高了系统的性能,我用swingbench测试的结果是使TPS值大约提高了10%。
配置成功后,数据库启动时在Oracle的alert log中有相应的提示,例如:
************************ Large Pages Information ******************* Per process system memlock (soft) limit = 227 GB Total Shared Global Region in Large Pages = 190 GB (100%) Large Pages used by this instance: 97281 (190 GB) Large Pages unused system wide = 3 (6144 KB) Large Pages configured system wide = 97284 (190 GB) Large Page size = 2048 KB ********************************************************************
daemon启动Oracle数据库时SGA无法使用大页管理
在大页管理的配置中需要对Oracle的用户增加memlock的设置,但用daemon启动Oracle的数据库时用以系统服务的方式进行的,并没有配置memlock参数,因此SGA无法使用大页管理,在alert log中有下面的提示:
************************ Large Pages Information ******************* Per process system memlock (soft) limit = 64 KB Total Shared Global Region in Large Pages = 0 KB (0%) Large Pages used by this instance: 0 (0 KB) Large Pages unused system wide = 97284 (190 GB) Large Pages configured system wide = 97284 (190 GB) Large Page size = 2048 KB RECOMMENDATION: Total System Global Area size is 190 GB. For optimal performance, prior to the next instance restart: 1. Large pages are automatically locked into physical memory. Increase the per process memlock (soft) limit to at least 190 GB to lock 100% System Global Area's large pages into physical memory ********************************************************************
Linux已经配置了大页而Oracle的SGA没有使用的后果
如果Linux已经配置了大页而Oracle的SGA没有,那么SGA将会放在普通的内存页面,将会造成内存耗尽,实际测试中,Centos和Redhat系统处于自我保护会把Oracle进程杀掉,而Oracle的linux(Unbreakable Enterprise Linux)不会。
[oracle@localhost scott]$ dstat -mt 20 ------memory-usage----- ----system---- used buff cach free| time 3721M 8192B 6104M 1693M|02-04 03:47:29 5018M 8192B 6146M 353M|02-04 03:47:49 5232M 8192B 6146M 140M|02-04 03:48:09 5277M 8192B 6146M 94.2M|02-04 03:48:29
解决方案
修改文件/etc/security/limits.conf进行配置对daemon是没有用的,因为这个文件是为通过PAM登录的用户设置资源限制。需要对应修改文件“/etc/init.d/daemon-agent ”,增加一行:
LimitMEMLOCK=unlimited
或者修改/usr/lib/systemd/system/daemon-agent.service
[Service] LimitMEMLOCK=infinity LimitNOFILE=65535
修改完,需要systemctl daemon-reload。
启动时在alert log中有下面的提示,注意memlock是unlimited。
************************ Large Pages Information ******************* Per process system memlock (soft) limit = UNLIMITED Total Shared Global Region in Large Pages = 190 GB (100%) Large Pages used by this instance: 97281 (190 GB) Large Pages unused system wide = 3 (6144 KB) Large Pages configured system wide = 97284 (190 GB) Large Page size = 2048 KB ********************************************************************