linux 可以设置多个hugepage吗

linux 可以设置多个hugepage吗,第1张

Linux中使用Hugepages可以减少 *** 作系统对page的维护,增加TLB (translation Lookaside Buffer)的命中率,由于Hugepages和Oracled 的AMM不兼容,所以在Oracle 11g中使用Hugepages 需要禁用AMM。配置了之后,Linux对大页面内存的引入对减少TLB的失效效果不错,特别是内存大而密集型的程序,比如说在数据库中的使用,下面是实际的例子

说明在oracle实际库的配置方法:

(1) 配置之前

[oracle@db101 ~]$ grep -i hu /proc/meminfoVmallocChunk: 34359467367 kBHugePages_Total: 0HugePages_Free: 0HugePages_Rsvd: 0Hugepagesize: 2048 kB

(2) 首先修改limits.conf[root@db101 ~]# vi /etc/security/limits.conf 略小于总内存##daodao add 0122* soft memlock15826672* hard memlock15826672[oracle@db101 ~]$ ulimit -l --检查刚才的执行是否生效15826672

(3).确定所有的oracle数据库实例都启动,包括asm实例,然后用如下脚本计算参数“vm.nr_hugepages"的大小

------------------hugepages_settings.sh----------------------------#!/bin/bash## hugepages_settings.sh## Linux bash script to compute values for the# recommended HugePages/HugeTLB configuration## 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 textecho "This script is provided by Doc ID 401749.1 from My Oracle Support (http://support.oracle.com) where it is intended to compute values forthe recommended HugePages/HugeTLB configuration for the current shared memory segments. Before proceeding with the execution please 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 -mPress Enter to proceed..."read# Check for the kernel versionKERN=`uname -r | awk -F. '{ printf("%d.%d\n",$1,$2)}'`# Find out the www.heyzc.com HugePage sizeHPG_SZ=`grep Hugepagesize /proc/meminfo | awk '{print $2}'`# Initialize the counterNUM_PG=0# Cumulative number of pages required to handle the running shared memory segmentsfor SEG_BYTES in `ipcs -m | awk '{print $5}' | 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` fidoneRES_BYTES=`echo "$NUM_PG * $HPG_SZ * 1024" | bc -q`# An SGA less than 100MB does not make sense# Bail out if that is the caseif [ $RES_BYTES -lt 100000000 ]then echo "***********" echo "** ERROR **" echo "***********" echo "Sorry! There are not enough total of shared memory segments allocated forHugePages configuration. HugePages can only be used for shared memory segments that you can list by command: # ipcs -mof 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 1fi# Finish with resultscase $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"*) echo "Unrecognized kernel version $KERN. Exiting." esac# End

使用oracle用户执行sh脚本[oracle@db101 ~]$ sh hugepages_settings.

This script is provided by Doc ID 401749.1 from My Oracle Support (http://support.oracle.com) where it is intended to compute values forthe recommended HugePages/HugeTLB configuration for the current shared memory segments. Before proceeding with the execution please 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 -mPress Enter to proceed...Recommended setting: vm.nr_hugepages = 2562

(4)切换root用户修改sysctl.conf[root@db101 ~]$ vi /etc/sysctl.conf net.ipv4.ip_local_port_range = 1024 65000net.core.rmem_default = 262144net.core.rmem_max = 262144net.core.wmem_default = 262144net.core.wmem_max = 262144vm.nr_hugepages = 2562 --这一行是新加的

5

(5)关闭所有实例,然后重启服务器

6

6)[root@db101 ~]# grep -i hu /proc/meminfoVmallocChunk: 34359467239 kBHugePages_Total: 2562HugePages_Free: 2562HugePages_Rsvd: 0Hugepagesize: 2048 kB

hugepage已经生效

前言

一说到大页内存,很多人都比较懵逼,什么是大页内存?它有什么优缺点呢?主要是用来干什么的?下面我们来一一叙说一下。

什么是大页内存?

如何去设置

上述1、2的顺序不能乱,乱了系统就没办法在启动阶段申请PAGE了。

或者直接在一个命令中完成:

重置参数

使用大页内存

使用hugetlbfs

使用 perf 探测 缺页中断数,和TLB miss数,发现非常少。

得到的结果如下:

不使用hugepage的程序

使用 perf 探测 缺页中断数,和TLB miss数,发现相对使用大页的程序而言,就多多了。

得到的结果如下:

直接使用mmap

使用 perf 探测 缺页中断数,和TLB miss数,发现非常少。

得到的结果如下:

大页内存的优缺点:

Redhat有另一种便捷的方式,就是 透明大页,就是开启后,任何程序都默认使用2MB的大页,不需要修改程序源码,但是也带来了内存浪费。


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/11202710.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-14
下一篇 2023-05-14

发表评论

登录后才能评论

评论列表(0条)

保存