简体   繁体   English

在其他线程上进行动态分配会降低我的主处理线程的速度吗?

[英]Will dynamic allocations on a different thread slow down my main processing thread?

I have a critical thread that processes data in a tight loop. 我有一个关键线程,它在紧密循环中处理数据。 It is affinity bound and meant for high-performance processing. 它具有亲和力,适用于高性能处理。 It does no dynamic allocations. 它没有动态分配。

I have another thread that is running on a different core that does none critical work but however does do dynamic allocations. 我有另一个线程在不同的内核上运行,该线程没有做任何重要的工作,但是却做了动态分配。 It is affinity bound also. 也有亲和力。

Will the presence of this other thread doing dynamic allocations affect my critical thread? 这个进行动态分配的线程的存在会影响我的关键线程吗?

Definitely, yes. 当然可以。
Not only for indirect effect of memory layout and L3 trashing, but also an immediate effect once in a while. 不仅对内存布局和L3垃圾回收有间接影响,而且偶尔也会有立即影响。
When malloc is called it tries to reuse what was already allocated and freed, but sometimes has to extend the process memory space, and it does this by calling mmap , or brk . 调用malloc时 ,它将尝试重用已分配和释放的内容,但有时必须扩展进程的内存空间,并通过调用mmapbrk来做到这一点。
I'm not 100% sure about brk , but mmap definitely invalidates the TLB so you should expect slower handling of page faults right after these calls. 我对brk不确定100%,但是mmap肯定会使TLB失效,因此您应该在这些调用之后立即处理较慢的页面错误。
If you're on Linux, or *BSD, you can try fiddle with the kernel code to not invalidate in all cases, but don't expect it to be simple. 如果您使用的是Linux或* BSD,则可以尝试摆弄内核代码以确保在所有情况下都不会无效,但是不要指望它很简单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM