|
我的应用程序中有一堆缓冲区(其中25到30个)相当大(.5mb)并且访问了simulataneousley.更糟糕的是,它们中的数据通常只读取一次,并且经常更新(例如每秒30次).排序非理想缓存使用的完美风暴.
无论如何,我想到如果我能将一块内存标记为不可缓存的话会很酷……从理论上讲,这将为缓存中的其他所有内容留出更多空间.
那么,他们是一种在Linux中标记为不可缓存的内存块的方法吗?
解决方法
如何避免使用这样的数据来污染缓存
What Every Programmer Should Know About Memory(PDF) – 这是从红帽开发的角度编写的,非常适合您.但是,大部分都是跨平台的.
您想要的是“非时间访问”,并告诉处理器期望您现在正在阅读的值暂时不再需要.然后处理器避免缓存该值.
请参阅上面链接的PDF的第49页.它使用intel内在函数在缓存周围进行流式处理.
On the read side,processors,until recently,lacked support aside from weak hints using non-temporal access (NTA) prefetch instructions. There is no equivalent to write-combining for reads,which is especially bad for uncacheable memory such as memory-mapped I/O. Intel,with the SSE4.1 extensions,introduced NTA loads. They are implemented using a small number of streaming load buffers; each buffer contains a cache line. The first movntdqa instruction for a given cache line will load a cache line into a buffer,possibly replacing another cache line. Subsequent 16-byte aligned accesses to the same cache line will be serviced from the load buffer at little cost. Unless there are other reasons to do so,the cache line will not be loaded into a cache,thus enabling the loading of large amounts of memory without polluting the caches. The compiler provides an intrinsic for this instruction:
#include <smmintrin.h>
__m128i _mm_stream_load_si128 (__m128i *p);
This intrinsic should be used multiple times,with addresses of 16-byte blocks passed as the parameter,until each cache line is read. Only then should the next cache line be started. Since there are a few streaming read buffers it might be possible to read from two memory locations at once
如果在读取时,缓冲区通过内存以线性顺序读取,那将是完美的.您使用流式读取来执行此操作.当您想要修改它们时,缓冲区将按线性顺序进行修改,如果您不希望在同一个线程中很快再次读取它们,则可以使用流式写入来执行此操作. (编辑:安卓应用网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|