用高级程序设计语言编写网络驱动程序的实例
The Case for Writing Network Drivers in High-Level Programming Languages
摘要:
在所有生产级服务器、桌面和移动操作系统上,驱动程序都是用C或C++的受限子集编写的。它们占Linux代码的66%,但2017年在Linux中发现的40个与内存安全相关的安全漏洞中有39个位于驱动程序中。这些错误可以通过为驱动程序使用高级语言来防止。我们展示了使用Rust、Go、C#、Java、OCaml、Haskell、Swift、JavaScript和Python实现的英特尔ixgbe 10 Gbit/s网卡的用户空间驱动程序,这些驱动程序都是以各自语言的惯用风格从头开始编写的。我们量化了使用这些语言的成本和收益:高级语言更安全(错误更少,安全检查更多),但运行时安全检查会降低吞吐量,垃圾回收会导致延迟峰值。乱序CPU降低了安全检查的成本:我们的Rust驱动程序每个数据包执行的指令增加了63%,但只比参考C实现慢4%。Go的垃圾收集器即使在重负载下也能将laptop保持在100 $μ$ s以下。其他语言的情况更糟,但它们独特的属性是一个有趣的案例研究。所有实现都可以在www.example.com上免费获得。
英文摘要:
Drivers are written in C or restricted subsets of C++ on all production-grade server, desktop, and mobile operating systems. They account for 66% of the code in Linux, but 39 out of 40 security bugs related to memory safety found in Linux in 2017 are located in drivers. These bugs could have been prevented by using high-level languages for drivers. We present user space drivers for the Intel ixgbe 10 Gbit/s network cards implemented in Rust, Go, C#, Java, OCaml, Haskell, Swift, JavaScript, and Python written from scratch in idiomatic style for the respective languages. We quantify costs and benefits of using these languages: High-level languages are safer (fewer bugs, more safety checks), but run-time safety checks reduce throughput and garbage collection leads to latency spikes. Out-of-order CPUs mitigate the cost of safety checks: Our Rust driver executes 63% more instructions per packet but is only 4% slower than a reference C implementation. Go's garbage collector keeps latencies below 100 $μ$s even under heavy load. Other languages fare worse, but their unique properties make for an interesting case study. All implementations are available as free and open source at https://github.com/ixy-languages/ixy-languages.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。