Linux内核中的哈希表
Linux 内核是否有可在内核代码中使用的通用哈希表实现?我知道链表、红黑树和基数树都是可用的,但还没有找到对通用哈希表实现的引用,尽管我知道哈希表在核心内核中大量使用。
Does the Linux kernel have a generic hash table implementation for use in kernel code? I know that linked lists, red-black trees, and radix trees are available, but haven't found reference to a generic hash table implementation, although I know hash tables are heavily used in the core kernel.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
冒着看起来像名声妓女的风险,让我总结一下我迄今为止获得的答案。
内核 3.7+
通用实现由 Sasha Levin 于 2012 年引入,合并用于 3.7 内核。
较旧的内核
内核(自 2.6.38 起)不包含通用哈希表实现,但包含一些部分:
uthash 是一个通用的 C 哈希表,实现为在单个头文件中定义的宏。该解决方案可能适用于许多第三方内核模块(例如,设备驱动程序)。然而,对 uthash 的依赖可能会阻碍模块的主线化。
At the risk of looking like a reputation whore, let me summarize the answers I've acquired so far.
Kernel 3.7+
A generic implementation was introduced by Sasha Levin in 2012 and merged for the 3.7 kernel.
Older Kernels
The kernel (as of 2.6.38) does not include a generic hash table implementation, but does include some pieces:
hlist_*/HLIST_*
in list.h are single-pointer-head doubly-linked list structs and macros useful for hash buckets. (answer below from adobriyan)pid_hash
in pid.c for an example constructed from these primitives.uthash is a generic hash table for C implemented as macros defined in a single header file. This solution may be appropriate for many third-party kernel modules (e.g., device drivers). However, reliance on
uthash
might impede mainlining of a module.没有通用的哈希表代码。
但是,看看如何使用
HLIST_*/hlist_*
内容。There is no generic hash table code.
But, see how
HLIST_*/hlist_*
stuff is used.