找回密码
 立即注册
首页 业界区 业界 Linux标准大页没有使用案例分享

Linux标准大页没有使用案例分享

红弘丽 2025-9-24 13:09:41
背景介绍

一套在RHEL的集群上运行的Oracle实例,是用systemd服务启动Oracle实例的(方便集群的切换操作).在测试过程中发现标准大页没有被用上.
具体情况如下所示:
  1. $ grep HugePages /proc/meminfo
  2. AnonHugePages:         0 kB
  3. ShmemHugePages:        0 kB
  4. FileHugePages:         0 kB
  5. HugePages_Total:    2034
  6. HugePages_Free:     2034
  7. HugePages_Rsvd:        0
  8. HugePages_Surp:        0
复制代码
原因分析

如上所示,HugePages_Free的值为2034, HugePages_Total的值也是2034,也就是说标准大页完全没有使用.
Linux服务器的基本信息如下
  1. $ more /etc/redhat-release
  2. Red Hat Enterprise Linux release 8.10 (Ootpa)
  3. $ free -m
  4.               total        used        free      shared  buff/cache   available
  5. Mem:          11697        4929        5986          17         780        6612
  6. Swap:         16383           0       16383
复制代码
检查数据库的参数如下, 完全符合条件:
  1. SQL> select banner from v$version;
  2. BANNER
  3. --------------------------------------------------------------------------------
  4. Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
  5. SQL> col name for a20;
  6. SQL> col value for a32;
  7. SQL> select name, value from v$parameter
  8.   2  where name in ('memory_target','sga_target','use_large_pages');
  9. NAME                 VALUE
  10. -------------------- --------------------------------
  11. use_large_pages      TRUE
  12. sga_target           4261412864
  13. memory_target        0
  14. SQL>
复制代码
内核参数vm.nr_hugepages也是正确设置的,具体如下所示
  1. $ grep vm.nr_hugepages /etc/sysctl.conf
  2. vm.nr_hugepages = 2034
  3. $ ./hugepages_settings.sh
  4. This script is provided by Doc ID 401749.1 from My Oracle Support
  5. (http://support.oracle.com) where it is intended to compute values for
  6. the recommended HugePages/HugeTLB configuration for the current shared
  7. memory segments on Oracle Linux. Before proceeding with the execution please note following:
  8. * For ASM instance, it needs to configure ASMM instead of AMM.
  9. * The 'pga_aggregate_target' is outside the SGA and
  10.    you should accommodate this while calculating the overall size.
  11. * In case you changes the DB SGA size,
  12.    as the new SGA will not fit in the previous HugePages configuration,
  13.    it had better disable the whole HugePages,
  14.    start the DB with new SGA size and run the script again.
  15. And make sure that:
  16. * Oracle Database instance(s) are up and running
  17. * Oracle Database 11g Automatic Memory Management (AMM) is not setup
  18.    (See Doc ID 749851.1)
  19. * The shared memory segments can be listed by command:
  20.      # ipcs -m
  21. Press Enter to proceed...
  22. Recommended setting: vm.nr_hugepages = 2034
复制代码
资源限制配置文件limits.conf中的memlock的设置也是正确的.如下所示:
  1. # grep memlock /etc/security/limits.conf
  2. #        - memlock - max locked-in-memory address space (KB)
  3. oracle   soft   memlock    10485760
  4. oracle   hard   memlock    10485760
  5. # su - oracle
  6. Last login: Fri Aug  8 13:54:36 CST 2025 on pts/0
  7. $ ulimit -l
  8. 10485760
  9. $ grep memlock /etc/security/limits.conf
  10. #        - memlock - max locked-in-memory address space (KB)
  11. oracle   soft   memlock    10485760
  12. oracle   hard   memlock    10485760
复制代码
很是纳闷为什么配置都是正确,但是Oracle就是不用标准大页,于是重启一下Oracle实例,在告警日志中发现了蛛丝马迹,如下所示:
  1. **********************************************************************
  2. 2025-08-08T13:50:16.662256+08:00
  3. Dump of system resources acquired for SHARED GLOBAL AREA (SGA)
  4. 2025-08-08T13:50:16.662285+08:00
  5. Domain name: system.slice/bpsdbsvr.service
  6. 2025-08-08T13:50:16.662302+08:00
  7. Per process system memlock (soft) limit = 64K
  8. 2025-08-08T13:50:16.662318+08:00
  9. Expected per process system memlock (soft) limit to lock
  10. instance MAX SHARED GLOBAL AREA (SGA) into memory: 4066M
  11. 2025-08-08T13:50:16.662356+08:00
  12. Available system pagesizes:
  13.   4K, 2048K
  14. 2025-08-08T13:50:16.662387+08:00
  15. Supported system pagesize(s):
  16. 2025-08-08T13:50:16.662404+08:00
  17.   PAGESIZE  AVAILABLE_PAGES  EXPECTED_PAGES  ALLOCATED_PAGES  ERROR(s)
  18. 2025-08-08T13:50:16.662421+08:00
  19.         4K       Configured              11          1040395        NONE
  20. 2025-08-08T13:50:16.662450+08:00
  21.      2048K             2034            2033                0        NONE
  22. 2025-08-08T13:50:16.662466+08:00
  23. RECOMMENDATION:
  24. 2025-08-08T13:50:16.662483+08:00
  25. 1. Increase per process memlock (soft) limit to at least 4066MB
  26. to lock 100% of SHARED GLOBAL AREA (SGA) pages into physical memory
  27. 2025-08-08T13:50:16.662514+08:00
  28. **********************************************************************
复制代码
检查Oracle进程的限制,发现进程的Max locked memory为65536,也就是64K.
  1. # oracle_pid=$(pgrep -f "_pmon_")
  2. # cat /proc/$oracle_pid/limits
  3. Limit                     Soft Limit           Hard Limit           Units     
  4. Max cpu time              unlimited            unlimited            seconds   
  5. Max file size             unlimited            unlimited            bytes     
  6. Max data size             unlimited            unlimited            bytes     
  7. Max stack size            33554432             unlimited            bytes     
  8. Max core file size        0                    unlimited            bytes     
  9. Max resident set          unlimited            unlimited            bytes     
  10. Max processes             46635                46635                processes
  11. Max open files            262144               262144               files     
  12. Max locked memory         65536                65536                bytes     
  13. Max address space         unlimited            unlimited            bytes     
  14. Max file locks            unlimited            unlimited            locks     
  15. Max pending signals       46635                46635                signals   
  16. Max msgqueue size         819200               819200               bytes     
  17. Max nice priority         0                    0                    
  18. Max realtime priority     0                    0                    
  19. Max realtime timeout      unlimited            unlimited            us        
复制代码
也就是说systemd服务启动Oracle实例时,由于某些原因memlock依然是64K,即日志中的提示"er process system memlock (soft) limit = 64K"
于是改用手工启动数据库实例,检查发现标准大页被Oracle使用了,但是systemd服务启动Oracle实例就会出现上面标准大页不被使用的情况
  1. $ grep HugePages /proc/meminfo
  2. AnonHugePages:         0 kB
  3. ShmemHugePages:        0 kB
  4. FileHugePages:         0 kB
  5. HugePages_Total:    2034
  6. HugePages_Free:        4
  7. HugePages_Rsvd:        3
  8. HugePages_Surp:        0
复制代码
后面和同事查资料,发现systemctl启动的服务默认不读取资源限制配置文件(limits.conf). limits.conf中的限制是针对用户会话级别的资源控制,
由PAM模块在用户登录时生效。而systemd服务是通过systemd进程直接启动的,属于非登录会话,默认不会触发PAM的pam_limits.so模块,
因此/etc/security/limits.conf 中为oracle用户设置的所有资源限制都不会自动应用到通过 systemd 服务启动的进程.
解决方案

如果想让systemd服务启动Oracle实例时memlock限制生效,可以在oracle.service 中直接配置 memlock 限制或者通过PAM让服务读取limits.conf.
网上资料推荐直接在systemd服务文件中配置(这是 systemd 推荐的方式,比依赖limits.conf更可靠), 如下所示:
oracle.service原始的配置
  1. [Unit]
  2. Description=Oracle Database Service
  3. After=network.target
  4. [Service]
  5. Type=forking
  6. User=oracle
  7. Group=oinstall
  8. ExecStart=/home/oracle/xxxx/ora19c.sh start
  9. ExecStop=/home/oracle/xxxx/ora19c.sh shutdown
  10. StandardOutput=append:/var/log/rhcs_resource_logs/xxx/xxx.log
  11. RemainAfterExit=yes
  12. KillMode=none
  13. [Install]
  14. WantedBy=multi-user.target
复制代码
注意: oracle.service配置做了一点混淆,不影响大家理解.
oracle.service修改后配置
  1. [Unit]
  2. Description=Oracle Database Service
  3. After=network.target
  4. [Service]
  5. Type=forking
  6. User=oracle
  7. Group=oinstall
  8. ExecStart=/home/oracle/xxxx/ora19c.sh start
  9. ExecStop=/home/oracle/xxxx/ora19c.sh shutdown
  10. StandardOutput=append:/var/log/rhcs_resource_logs/xxx/xxx.log
  11. RemainAfterExit=yes
  12. KillMode=none
  13. # oracle /etc/security/limits.conf
  14. LimitNPROC=16384
  15. LimitNOFILE=65536
  16. LimitSTACK=10485760
  17. LimitMEMLOCK=10737418240
  18. [Install]
  19. WantedBy=multi-user.target
复制代码
这样配置后,通过systemd服务启动Oracle实例就能正常使用标准大页了.问题Troubleshooting完美解决. 究其原因还是因为对Linux的systemd服务了解得不够多.不够深入!
扫描上面二维码关注我如果你真心觉得文章写得不错,而且对你有所帮助,那就不妨帮忙“推荐"一下,您的“推荐”和”打赏“将是我最大的写作动力!本文版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接.
来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!

相关推荐

您需要登录后才可以回帖 登录 | 立即注册