【论文速读 | ASPLOS‘24】Merlin: Multi-tier Optimization of eBPF Code for Performance and Compactness

2024-06-08 10:00:05 浏览数 (4)

研究背景

eBPF 技术因其在提高 Linux 内核的可观测性、性能和安全性方面的重要作用而被广泛应用于各种场景,如网络堆栈、系统调用和文件系统的监控。尽管已有编译器支持 eBPF 程序的编译,但现有的工具常常忽略了关键的优化机会,导致性能不佳。此外,eBPF 程序的优化需要考虑到内核安全性的要求,这增加了优化的复杂性。

研究问题

论文主要解决的问题是如何对 eBPF代码进行多级优化,以提高其在 Linux 内核中的性能和紧凑性。eBPF 是一种在内核中运行的虚拟机,它允许用户以安全的方式执行自定义程序,用于观察、分析和修改内核行为。然而,由于 eBPF 程序在执行前需要通过内核的严格验证,并且受限于指令数量和程序长度,这导致在不牺牲安全性的前提下进行性能优化成为一个挑战。

主要创新方法

简单总结文中的创新方法:

  1. Merlin 优化框架: 论文提出了一个名为 Merlin 的优化框架,该框架利用定制的 LLVM 传递和字节码重写技术,对指令表示(IR)进行转换和字节码细化
  2. 双策略优化: Merlin 采用了两种主要的优化策略,即指令合并和强度减弱。这些优化在 eBPF 验证之前部署,以确保优化后的程序能够通过内核验证。
  3. IR 优化和字节码细化: 通过在编译流程的早期阶段利用定制的 LLVM IR 优化传递,将领域知识(如寄存器和对齐)注入编译器 IR;在字节码加载到内核之前,直接优化字节码以针对验证器约束和利用 eBPF 虚拟机特性

效果:

  1. 性能和紧凑性提升: 论文通过在多个真实世界的 eBPF 程序上评估 Merlin,展示了其在减少指令数量、降低运行时开销、提高吞吐量和降低延迟方面的显著效果。
  2. 与现有技术的比较: 与现有的最先进技术 K2 相比,Merlin 在保持程序通过内核验证的同时,能够显著提高性能和紧凑性,且在优化速度和可扩展性方面具有明显优势。

其他解释:

  1. 指令合并(Instruction Merging):这是一种优化技术,它通过合并多个指令到更少的指令中来提高代码效率。这有助于减少执行的指令数量,从而降低运行时开销和内存消耗
  2. 强度减弱(Strength Reduction):这是一种编译器优化技术,旨在通过替换成本较高的操作为计算上更便宜的等效操作来提高程序的效率。这通常涉及到将高成本的操作(如乘法或指数运算)转换为成本较低的操作(如加法或位移运算)

原文引用

代码语言:javascript复制
@inproceedings{10.1145/3620666.3651387,
author = {Mao, Jinsong and Ding, Hailun and Zhai, Juan and Ma, Shiqing},
title = {Merlin: Multi-tier Optimization of eBPF Code for Performance and Compactness},
year = {2024},
isbn = {9798400703867},
publisher = {Association for Computing Machinery},
address = {New York, NY, USA},
url = {https://doi.org/10.1145/3620666.3651387},
doi = {10.1145/3620666.3651387},
abstract = {eBPF (extended Berkeley Packet Filter) significantly enhances observability, performance, and security within the Linux kernel, playing a pivotal role in various real-world applications. Implemented as a register-based kernel virtual machine, eBPF features a customized Instruction Set Architecture (ISA) with stringent kernel safety requirements, e.g., a limited number of instructions. This constraint necessitates substantial optimization efforts for eBPF programs to meet performance objectives. Despite the availability of compilers supporting eBPF program compilation, existing tools often overlook key optimization opportunities, resulting in suboptimal performance. In response, this paper introduces Merlin, an optimization framework leveraging customized LLVM passes and bytecode rewriting for Instruction Representation (IR) transformation and bytecode refinement. Merlin employs two primary optimization strategies, i.e., instruction merging and strength reduction. These optimizations are deployed before eBPF verification. We evaluate Merlin across 19 XDP programs (drawn from the Linux kernel, Meta, hXDP, and Cilium) and three eBPF-based systems (Sysdig, Tetragon, and Tracee, each comprising several hundred eBPF programs). The results show that all optimized programs pass the kernel verification. Meanwhile, Merlin can reduce number of instructions by 73% and runtime overhead by 60% compared with the original programs. Merlin can also improve the throughput by 0.59% and reduce the latency by 5.31%, compared to state-of-the-art technique K2, while being 106 times faster and more scalable to larger and more complex programs without additional manual efforts.},
booktitle = {Proceedings of the 29th ACM International Conference on Architectural Support for Programming Languages and Operating Systems, Volume 3},
pages = {639–653},
numpages = {15},
keywords = {eBPF optimization, LLVM},
location = {<conf-loc>, <city>La Jolla</city>, <state>CA</state>, <country>USA</country>, </conf-loc>},
series = {ASPLOS '24}
}

0 人点赞