缓存对齐的链表

时间:2012-06-25 15:13:19

标签: caching memory-management linked-list memory-alignment

我知道数据类型或结构对齐,打包,填充问题等的概念。我已经实现了单个链表,其中每个节点占用大约250个字节,即大约64字节高速缓存行大小的4倍。我的机器是Intel 64位架构。

现在,单个链表实际上是一个追逐数据结构的指针,因此会遇到大量的缓存未命中。为了减少缓存未命中,我使用* posix_memalign *函数对每个数据结构节点进行对齐,以缓存64字节的行内容。现在,所有链接列表节点都是缓存对齐的。

这样做之后,我发现链表的内存消耗大大增加,而且性能实际上也在恶化。任何人都可以解释可能出现的问题吗?

1 个答案:

答案 0 :(得分:0)

我不知道您使用的malloc是什么,但这来自tcmalloc

// For use by exported routines below that want specific alignments
//
// Note: this code can be slow for alignments > 16, and can
// significantly fragment memory.  The expectation is that
// memalign/posix_memalign/valloc/pvalloc will not be invoked very
// often.  This requirement simplifies our implementation and allows
// us to tune for expected allocation patterns.