一、关闭透明大页
vi /etc/default/grub
GRUB_CMDLINE_LINUX="crashkernel=auto rhgb quiet numa=off numa_balancing=0 intel_idle.max_cstate=1 transparent_hugepage=never cgroup_disable=cpu"
grub2-mkconfig -o /boot/grub2/grub.cfg
grub2-mkconfig -o /boot/efi/EFI/redhat/grub.cfg
init 6
--quiet 后面的numa=off numa_balancing=0 intel_idle.max_cstate=1 transparent_hugepage=never cgroup_disable=cpu 是新增
grep AnonHugePages /proc/meminfo
AnonHugePages: 0 kB
//大于0就是开启了
cat /sys/kernel/mm/transparent_hugepage/enabled
always madvise [never]
--备注:
禁用NUMA,numa=off
禁用 NUMA 自动均衡 numa_balancing=0
设置 C-State 最大变迁深度小于 1、或0完全禁用 intel_idle.max_cstate=1
# cat /proc/cpuinfo | grep -i 'cpu mhz'
查看个CPU MHZ是否相同,如果不同,一般都不是跑在C0模式下---C0 :工作状态,CPU完全运行。
禁用 CPU 的cgroups 控制:cgroup_disable=cpu
二、开启大内存页
1) 设置memlock
/etc/security/limits.conf
如物理内存是64G,可以设置如下
* soft memlock 60397977
* hard memlock 60397977
备注:
设置的memlock值大于sga,小于物理内存(一般设备物理内存的85%)
2) 设置shmmax
vi /etc/sysctl.conf
kernel.shmmax = 60397977000
--备注
Kernel.shmmax = memlock*1024(单位不一样)
// shmmax不能大于memlock
3) 验证memlock
Su – oracle
ulimit -l
64 //默认64K --注意这里一定要和memlock配置的一样才可以
4) oracle 11g 禁用AMM
11G默认会使用AMM,禁用即可:
Alter system set memory_target =0 scope=spfile sid=’*’;
Alter system set memory_max_target = 0 scope=spfile sid=’*’;
5) 设置vm.nr_hugepages
cat /proc/meminfo | grep Huge
HugePages_Total: 0 //总的大页的数量
HugePages_Free: 0 //剩余的大页的数量
HugePages_Rsvd: 0 //保留的大页的数量
HugePages_Surp: 0 //常驻的大页的数量
Hugepagesize: 2048 kB //一个大内存页是2M
//默认linux 的内存页是4k
[root@test ~]# getconf PAGESIZE
4096
[root@test ~]#
vi /etc/sysctl.conf
vm.nr_hugepages = 30000
systcl -p
//以上是按60G计算的。
注意:
(1)vm.nr_hugepages 大于oracle 内存,小于物理内存
(2)不超过物理内存85%,不能大于memlock
(3)注意内存保留问题,别全占用了,一定要预留系统内存。
一般设置依据:
第一种:(SGA+1G)/2M
第二种:比物理内存低一点,直接除以2,比如60G/2M=30720页
第一种的话每次sga变化或者增减实例都需要重新调整HugePages。所以推荐第二种。
6) 停止数据库实例才能生效
重启数据库实例
7) 验证大页已生效
第一步:
[oracle@test ~]$ cat /proc/meminfo | grep Page
AnonPages: 159684 kB
PageTables: 37372 kB
AnonHugePages: 28672 kB
HugePages_Total: 608 //总页数
HugePages_Free: 331 //空闲
HugePages_Rsvd: 144 //保留
HugePages_Surp: 0
脚本 huge_pages_settings.sh: Doc ID 401749.1
#!/bin/bash
#
# hugepages_settings.sh
#
# Linux bash script to compute values for the
# recommended HugePages/HugeTLB configuration
# on Oracle Linux
#
# Note: This script does calculation for all shared memory
# segments available when the script is run, no matter it
# is an Oracle RDBMS shared memory segment or not.
#
# This script is provided by Doc ID 401749.1 from My Oracle Support
# http://support.oracle.com
# Welcome text
echo "
This script is provided by Doc ID 401749.1 from My Oracle Support
(http://support.oracle.com) where it is intended to compute values for
the recommended HugePages/HugeTLB configuration for the current shared
memory segments on Oracle Linux. Before proceeding with the execution please note following:
* For ASM instance, it needs to configure ASMM instead of AMM.
* The 'pga_aggregate_target' is outside the SGA and
you should accommodate this while calculating the overall size.
* In case you changes the DB SGA size,
as the new SGA will not fit in the previous HugePages configuration,
it had better disable the whole HugePages,
start the DB with new SGA size and run the script again.
And make sure that:
* Oracle Database instance(s) are up and running
* Oracle Database 11g Automatic Memory Management (AMM) is not setup
(See Doc ID 749851.1)
* The shared memory segments can be listed by command:
# ipcs -m
Press Enter to proceed..."
read
# Check for the kernel version
KERN=`uname -r | awk -F. '{ printf("%d.%d\n",$1,$2); }'`
# Find out the HugePage size
HPG_SZ=`grep Hugepagesize /proc/meminfo | awk '{print $2}'`
if [ -z "$HPG_SZ" ];then
echo "The hugepages may not be supported in the system where the script is being executed."
exit 1
fi
# Initialize the counter
NUM_PG=0
# Cumulative number of pages required to handle the running shared memory segments
for SEG_BYTES in `ipcs -m | cut -c44-300 | awk '{print $1}' | grep "[0-9][0-9]*"`
do
MIN_PG=`echo "$SEG_BYTES/($HPG_SZ*1024)" | bc -q`
if [ $MIN_PG -gt 0 ]; then
NUM_PG=`echo "$NUM_PG+$MIN_PG+1" | bc -q`
fi
done
RES_BYTES=`echo "$NUM_PG * $HPG_SZ * 1024" | bc -q`
# An SGA less than 100MB does not make sense
# Bail out if that is the case
if [ $RES_BYTES -lt 100000000 ]; then
echo "***********"
echo "** ERROR **"
echo "***********"
echo "Sorry! There are not enough total of shared memory segments allocated for
HugePages configuration. HugePages can only be used for shared memory segments
that you can list by command:
# ipcs -m
of a size that can match an Oracle Database SGA. Please make sure that:
* Oracle Database instance is up and running
* Oracle Database 11g Automatic Memory Management (AMM) is not configured"
exit 1
fi
# Finish with results
case $KERN in
'2.4') HUGETLB_POOL=`echo "$NUM_PG*$HPG_SZ/1024" | bc -q`;
echo "Recommended setting: vm.hugetlb_pool = $HUGETLB_POOL" ;;
'2.6') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
'3.8') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
'3.10') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
'4.1') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
'4.14') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
'4.18') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
'5.4') echo "Recommended setting: vm.nr_hugepages = $NUM_PG" ;;
*) echo "Kernel version $KERN is not supported by this script (yet). Exiting." ;;
esac
# End
--当没有启动实例时,会报错提示:
***********
** ERROR **
***********
Sorry! There are not enough total of shared memory segments allocated for
HugePages configuration. HugePages can only be used for shared memory segments
that you can list by command:
「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




