加入收藏 | 设为首页 | 会员中心 | 我要投稿 应用网_丽江站长网 (http://www.0888zz.com/)- 科技、建站、数据工具、云上网络、机器学习!
当前位置: 首页 > 运营中心 > 网站设计 > 教程 > 正文

Linux系统中HugePage内存功能配置详解

发布时间:2022-06-15 10:49:02 所属栏目:教程 来源:互联网
导读:我相信各位做linux系统性能优化的朋友对于 HugePage并不陌生了,今天我们来为各位分享一篇HugePage用法例子. 在Linux环境性能优化实践中,HugePage是一个经常提到的方法,简单的说,HugePage就是Linux内核上一种是用内存块的方法,作为传统4K Page的替代,HugePa
  我相信各位做linux系统性能优化的朋友对于 HugePage并不陌生了,今天我们来为各位分享一篇HugePage用法例子.
 
  在Linux环境性能优化实践中,HugePage是一个经常提到的方法,简单的说,HugePage就是Linux内核上一种是用内存块的方法,作为传统4K Page的替代,HugePage在大部分场景下可以提升Oracle实例的运行性能效率.
 
  一、基础环境准备
 
  我们选择Kernel2.6下的centos版本进行实验。
 
  [oracle@361way ~]$ uname -r
 
  2.6.18-128.el5
 
  此时Oracle实例为11gR2(11.2.0.3),运行在AMM内存管理方式下,共享内存段信息如下.
 
  [oracle@361way ~]$ ipcs -m
  ------ Shared Memory Segments --------
  key        shmid      owner      perms      bytes      nattch     status
  0x00000000 32768      oracle    640        4096       0
  0x00000000 65537      oracle    640        4096       0
  0x01606d30 98306      oracle    640        4096       0
  [oracle@361way ~]$ grep Huge /proc/meminfo
  HugePages_Total:     0
  HugePages_Free:      0
  HugePages_Rsvd:      0
  Hugepagesize:     4096 kB
  注意两个问题:一个是当前我们在meminfo中没有启用HugePage,所以没有对应的记录,另一个是AMM下,ipcs –m显示出的共享内存大小只有三个每个大小4096bytes.
 
  这个问题是比较复杂的,本篇就介绍一个开头,在10g中,Oracle引入了sga_target系列参数,实现了ASMM(Automatic Shared Memory Management),ASMM的本质是实现SGA和PGA内部各个池之间的动态调整,但是在11g中,推出了AMM(Automatic Memory Management),实现了PGA和SGA之间的调节.
 
  AMM其实是复杂的,SGA在Linux中是通过系统共享内存实现,而PGA是通过进程私有空间实现,AMM实际上最大的功能是将SGA和PGA空间调节的通道打通,这必然带来对原有SGA共享内存方式架构的影响,在AMM时,ipcs –m显示的虚拟空共享段就是实际效果的一部分.
 
  二、用户内存配置
 
  启用HugePage的第一步就是进行用户参数限制打通,当前内存大小如下:
 
  --内存信息
 
  [root@361way ~]# free -t
               total       used       free     shared    buffers     cached
  Mem:        918380     205044     713336          0      14744     152996
  -/+ buffers/cache:      37304     881076
  Swap:      2455788          0    2455788
  Total:     3374168     205044    3169124
  修改/etc/security/limits.conf参数文件,添加数据库实例用户的memlock限制.
 
  [root@361way ~]# cat /etc/security/limits.conf
  # /etc/security/limits.conf
  #
  (篇幅原因,有省略……)
  #        - fsize - maximum filesize (KB)
  #        - memlock - max locked-in-memory address space (KB)
  #        - nofile - max number of open files
  #ftp             hard    nproc           0
  #@student        -       maxlogins       4
  oracle soft nproc 2047
  oracle hard nproc 16384
  oracle soft nofile 1024
  oracle hard nofile 65536
  oracle soft memlock 918380
  oracle hard memlock 918380
  # End of file  //phpfensi.com
  这个过程中使用memlock标记,用于设置每个用户允许的最大内存使用情况,这个取值可以设置为数据库服务器物理内存大小,切换到指定用户(oracle),查看设置.
 
  [oracle@361way ~]$ ulimit -l
  918380
  
       三、Oracle设置
 
  如果是使用11g Oracle版本,一定需要进行额外的配置,就是将使用的AMM退化为ASMM,在早期的11.2.0.1版本中,这个步骤很重要,因为AMM是不支持HugePage的,如果强在AMM+HugePage模式下打开数据库,是会遇到失败信息.
 
  在最新的11.2.0.2版本以及之后,引入了参数use_large_pages,避免了这样的问题,但是AMM与HugePage不兼容的情况,还是存在.
 
  当前是使用AMM的数据库.
 
  SQL> show parameter target
  NAME                                 TYPE        VALUE
  ------------------------------------ ----------- ------------------------------
  archive_lag_target                   integer     0
  db_flashback_retention_target        integer     1440
  fast_start_io_target                 integer     0
  fast_start_mttr_target               integer     0
  memory_max_target                    big integer 360M
  memory_target                        big integer 360M
  parallel_servers_target              integer     16
  pga_aggregate_target                 big integer 0
  sga_target                           big integer 0
  AMM的关键在于两个方面,一个是memory_target和memory_max_target设置非空,另一个是sga_target和pga_aggregate_target参数设置为空,如果要关闭AMM,退化开启ASMM,就需要进行实例启动参数的设置.
 
  说明:本篇不是以修改AMM到ASMM作为重点,这部分内容略,留待其他文章进行说明,修改之后,需要重启服务器,因为一些参数属于静态参数.
 
  SQL> conn / as sysdba
  Connected.
  SQL> show parameter target
  NAME                                 TYPE        VALUE
  ------------------------------------ ----------- ------------------------------
  archive_lag_target                   integer     0
  db_flashback_retention_target        integer     1440
  fast_start_io_target                 integer     0
  fast_start_mttr_target               integer     0
  memory_max_target                    big integer 0
  memory_target                        big integer 0
  parallel_servers_target              integer     16
  pga_aggregate_target                 big integer 108M
  sga_target                           big integer 252M
  注意,此时共享内存机制才真正实现,我们从ipcs –m中,可以看到真正的共享段.
 
  [oracle@361way dbs]$ ipcs -m
  ------ Shared Memory Segments --------
  key        shmid      owner      perms      bytes      nattch     status
  0x00000000 327680     oracle    640        4194304    27
  0x00000000 360449     oracle    640        260046848  27
  0x01606d30 393218     oracle    640        4194304    27
  
        四、经验脚本计算HugePage最大值
 
  在MOS 401749.1中,Oracle推荐了一个Shell脚本来计算HugePage值,运行这个脚本,将计算出的取值设置在系统参数中.
 
  [oracle@361way upload]$ ls -l | grep huge
  -rwxr-xr-x 1 oracle oinstall   3037 Oct 22 09:42 hugepages_settings.sh
  执行脚本,注意这个过程中要求Oracle所有实例,包括数据库和ASM都启动、AMM关闭,以及SGA大小超过100M.
 
  [oracle@361way upload]$ ./hugepages_settings.sh
  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. 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 SGA 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  //phpfensi.com
  Press Enter to proceed...
  Recommended setting: vm.nr_hugepages = 67
  将计算出的67更改参数/etc/sysctl.conf
 
  --设置参数
 
  [root@361way ~]# vi /etc/sysctl.conf
 
  (添加内容如下……)
 
  vm.nr_hugepages = 67
 
  "/etc/sysctl.conf" 49L, 1325C written
 
  使用sysctl –p生效设置。
 
  [root@361way ~]# sysctl -p
 
  net.ipv4.ip_forward = 0
 
  (篇幅原因,有省略……)
 
  net.core.wmem_max = 1048586
 
  vm.nr_hugepages = 67
 
  五、HugePage启动检验
 
  设置之后,最好重新启动服务器,包括Oracle.
 
  [oracle@361way ~]$ ipcs -m
  ------ Shared Memory Segments --------
  key        shmid      owner      perms      bytes      nattch     status
  0x00000000 32768      oracle    640        4194304    26
  0x00000000 65537      oracle    640        260046848  26
  0x01606d30 98306      oracle    640        4194304    26
  [oracle@361way ~]$ grep Huge /proc/meminfo
  HugePages_Total:    67
  HugePages_Free:      3
  HugePages_Rsvd:      0
  Hugepagesize:     4096 kB
  在meminfo文件中,可以查到HugePages的信息,说明启用成功.
 

 

(编辑:应用网_丽江站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    热点阅读