内核反馈优化
背景
当今大多数服务器只运行单个或少数的特定应用,因此根据特定的运行程序对操作系统进行优化,将获得更多的性能收益。
DEMO
- 下载内核源码
yum install -y kernel-source
- 编译插装代码进入内核源码目录,进行内核选项配置,这里以openEuler 5.10内核为例
cd /usr/src/linux-5.10.0*** make openeuler_defconfig make menuconfig 在菜单中,进入General setup,选择Local Version-append to kernel release,填入合适的后缀名,例如-test-going 双击esc回到上一级目录,进入General architecture-dependent options > GCOV-based kernel profiling,双击esc回到主目录,进入kernel hacking > Compile-time checks and compiler options profiling,关闭Compile the kernel debug,保存并退出。
- 编译rpm包(96可替换为机器最大核数)
make binrpm-pkg -j 96
- 使用插桩内核
在服务器端安装插桩内核,设置为默认内核并重启
rpm -ivh kernel*** --force grub2-set-default 0 reboot
- 执行目标优化的应用测试,这里以Nginx的wrk测试套为例。在服务器端开Nginx 服务器
nginx -c nginx.conf
在客户端运行Nginx wrk测试套
wrk -c 2000 -d 60s -t 20 --latency --timeout 5s -H "Connection: close" http://192.168.1.10:10000/index.html
- 执行profile收集脚本,将profile信息从内存写入磁盘中。
- (可选)如果需要针对多个应用编译优化内核,可以尝试合并多个应用的profile,这里以应用A和应用B为例
gcov-tool merge a/gcovdata b/gcovdata
- 编译优化后的内核,进入内核源码目录,进行内核选项配置。
make openeuler_defconfig make menuconfig 在菜单中,进入General Setup.选在Local version-append to kernel release,填写合适的后缀名,例如-test-pgoed,双击回到主目录,关闭Compile the kernel with debug info,保存并退出。
- 编译rpm包(96可替换为机器最大核数)
make binrpm-pkg -j 96 KCFLAGS="-fprofile-use -fprofile-correction -Wno-error=coverage-mismatch -Wno-error=missing-profile -fprofile-dir=gcovdata"
父主题: PGO