[论文解读] BOLT: A Practical Binary Optimizer for Data Centers and Beyond
BOLT 是一个基于 LLVM 的后链接二进制优化器,通过利用高精度的基于采样的性能分析数据,对代码布局进行优化,从而提升大规模数据中心应用的性能。它在生产工作负载上实现了最高 8.0% 的性能提升,在 GCC 和 Clang 等编译器上实现了最高 20.4% 的性能提升,即使在结合了反馈驱动优化和链接时优化后依然有效,表明后链接优化与早期阶段的优化相辅相成,而非相互替代。
Performance optimization for large-scale applications has recently become more important as computation continues to move towards data centers. Data-center applications are generally very large and complex, which makes code layout an important optimization to improve their performance. This has motivated recent investigation of practical techniques to improve code layout at both compile time and link time. Although post-link optimizers had some success in the past, no recent work has explored their benefits in the context of modern data-center applications. In this paper, we present BOLT, a post-link optimizer built on top of the LLVM framework. Utilizing sample-based profiling, BOLT boosts the performance of real-world applications even for highly optimized binaries built with both feedback-driven optimizations (FDO) and link-time optimizations (LTO). We demonstrate that post-link performance improvements are complementary to conventional compiler optimizations, even when the latter are done at a whole-program level and in the presence of profile information. We evaluated BOLT on both Facebook data-center workloads and open-source compilers. For data-center applications, BOLT achieves up to 8.0% performance speedups on top of profile-guided function reordering and LTO. For the GCC and Clang compilers, our evaluation shows that BOLT speeds up their binaries by up to 20.4% on top of FDO and LTO, and up to 52.1% if the binaries are built without FDO and LTO.
研究动机与目标
- 解决由于代码局部性差以及对缓存和分支预测器等硬件结构造成压力,导致大规模复杂数据中心应用出现性能瓶颈的问题。
- 探究后链接二进制优化是否能在真实工作负载中优于或补充传统的编译时和链接时反馈驱动优化(FDO)。
- 证明基于二进制级别的采样性能分析能够实现比必须将性能数据映射回中间表示的编译器方法更精确的代码布局。
- 构建一个实用的、开源的、可移植的二进制优化器,集成 LLVM 基础设施,并可扩展至生产级工作负载。
- 独立评估 BOLT 的性能提升效果,以及其与现有优化技术(如 FDO 和 LTO)结合使用时的性能增益。
提出的方法
- BOLT 作为后链接优化器运行于完全链接的二进制文件之上,利用从生产工作负载中收集的基于采样的性能分析数据,指导代码布局优化。
- 它利用来自硬件性能计数器的低级别性能分析信息,包括 LBR(最后分支记录)数据,以在二进制级别获得细粒度且精确的执行性能分析。
- 该工具基于反馈驱动的启发式算法(如调用频率和执行热度)对函数和基本块进行重排,以提高指令缓存和分支预测器的效率。
- BOLT 基于 LLVM 基础设施实现,支持多种指令集架构的可移植性,并可与现有编译流水线无缝集成。
- 它执行静态二进制分析,从机器代码中重构控制流和数据流信息,从而在无需源代码或中间表示的情况下实现精确的布局决策。
- 该系统支持增量部署,可在未经修改的二进制文件上运行,最大限度降低运行时开销,支持生产环境使用。
实验结果
研究问题
- RQ1通过避免将性能数据映射回中间表示,后链接二进制优化器是否能实现比基于编译器的 FDO 更高的代码布局精度?
- RQ2在大规模应用中,后链接优化在多大程度上与现有的反馈驱动优化和链接时优化互补而非重叠?
- RQ3当应用于已使用 FDO 和 LTO 优化的高优化级别二进制文件时,后链接代码布局优化带来的性能提升有多大?
- RQ4细粒度性能分析(如基于 LBR 的数据)对生产二进制文件中基本块和函数重排的有效性有何影响?
- RQ5基于 LLVM 构建的实用型、可投入生产的二进制优化器是否能在多样化的实际数据中心工作负载中实现可测量的性能提升?
主要发现
- 在 Facebook 的生产数据中心工作负载上,BOLT 在 FDO 和 LTO 之后应用,实现了最高 8.0% 的性能提升,表明即使在高度优化的二进制文件上也能获得显著收益。
- 对于 GCC 和 Clang 编译器,BOLT 在 FDO 和 LTO 基础上实现了最高 20.4% 的性能提升,若二进制文件未使用 FDO 和 LTO,则性能提升最高可达 52.1%。
- 性能提升主要源于改进的代码布局,其中基本块重排的贡献大于函数重排,尤其是在使用基于 LBR 的性能分析时更为显著。
- 二进制级别的性能分析精度优于编译器方法,后者必须将性能数据映射回中间表示,常引入不准确性。
- 后链接优化并非劣于早期阶段的 FDO;相反,它具有互补性,FDO 与 BOLT 联合使用可获得高于任一单独使用时的性能。
- LBR 的使用在 HHVM 中贡献了约 2% 的总性能提升,凸显了细粒度性能分析对低级别布局优化的价值。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。