____cacheline_aligned_in_smp用于Linux内核中的结构 [英] ____cacheline_aligned_in_smp for structure in the Linux kernel

查看:713
本文介绍了____cacheline_aligned_in_smp用于Linux内核中的结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux内核中,为什么许多结构使用____cacheline_aligned_in_smp宏?访问结构时是否有助于提高性能?如果是,那怎么办?

In the Linux kernel, why do many structures use the ____cacheline_aligned_in_smp macro? Does it help increase performance when accessing the structure? If yes then how?

推荐答案

任何缓存(dcache或icache)中的每个缓存行都是64字节(在x86中)体系结构.需要进行高速缓存对齐,以避免错误共享高速缓存行.如果高速缓存行在全局变量之间共享(在内核中更多),如果全局变量之一被其高速缓存中的处理器之一更改,则它将该高速缓存行标记为脏.在剩余的CPU高速缓存行中,它变为陈旧的条目,需要刷新并从内存中重新获取.这可能会导致高速缓存行丢失,这需要更多的CPU周期.这会降低系统的性能.请记住,这是针对全局变量的.大多数内核数据结构师都使用此方法来避免高速缓存行遗漏.

Each cache line in any cache (dcache or icache) is 64 bytes (in x86) architecture. Cache alignment is required to avoid false sharing of cache lines. If the cache lines are shared between global variables (happens more in kernel) If one of the global variables changed by one of the processor in its cache then it marks that cache line as dirty. In remaining CPU cache line it becomes stale entry, which needs to be flushed and re-fetched from memory. This might lead to cache line misses, which requires more CPU cycles. This reduces the performance of the system. Remember this is for global variables. Most of the kernel data strucuters use this to avoid cache line misses.

这篇关于____cacheline_aligned_in_smp用于Linux内核中的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆