kmalloc() for any context
适用于任意上下文的 kmalloc()
Alexei Starovoitov then took over to run a joint session with the BPF track on work toward creating a version of kmalloc() (which is part of the slab allocator) that can be called from BPF programs in any context. Some BPF attachment points, including tracepoints, can be invoked from any context, even non-maskable interrupts (NMIs). The system's freedom to satisfy allocation requests can be highly constrained in those contexts, so care must be taken. The BPF subsystem has, for a few years, used a custom allocator to fill this need, but there is a desire to reduce the number of allocators (and object caches) in the kernel. See this article for an overview of his proposed solution.
随后,Alexei Starovoitov 接手主持了一场与 BPF 方向联合的会议,讨论创建一种可在任意上下文中从 BPF 程序调用的 kmalloc() 版本(kmalloc() 是 slab 分配器的一部分)。某些 BPF 挂载点(包括 tracepoints)可能在任何上下文中被调用,甚至是在不可屏蔽中断(NMI)中。在这些上下文里,系统满足内存分配请求的自由度受到极大限制,因此必须格外谨慎。BPF 子系统多年来一直使用一个自定义分配器来满足这一需求,但内核社区希望减少内核中分配器(以及对象缓存)的数量。关于他提出的解决方案概览,可参见相关文章。
Starovoitov began by thanking Babka for the 2024 LSFMM+BPF session on the slab allocator, without which he would not have had the courage to attempt this work. There are, he said, a lot of wrappers around the slab allocator in the kernel; there are different excuses for the existence of each. For BPF, the primary excuse was the need to be able to allocate in any context; performance is also important,