当在不同的处理器(GC 逻辑堆)上安排任务延续时会发生什么?

What's happens when a Task continuation is scheduled on a different processor (GC logical heaps)?

据我了解,当为 .NET 应用程序启用服务器 GC 模式时,它会为每个处理器分配一个逻辑堆,每个处理器上调度的线程将分配内存。

分配给具有多个等待的 Task 的内存会怎样?它可能会在线程池中的任何线程上执行,因此可以在逻辑堆之间跳转。

在之前的逻辑堆上分配的内存是否被复制到当前正在执行的逻辑堆?在相同的逻辑 heap/core 上不执行 Task 延续是否有任何成本?

What happens to the memory allocated to a Task with multiple awaits? It could potentially be executed on any Thread from the ThreadPool, so could jump between logical heaps.

一个线程可以看到整个地址 space,无论逻辑分隔如何。堆对象可以无边界地指向另一个堆中的不同对象。请记住,不同的线程仍然可以在不同的时间片中安排在同一个 CPU 上。

Does memory allocated on a previous logical heap get copied to the current executing logical heap? Is there any cost to not executing Task continuations on the same logical heap/core?

不,如果 运行 时间被迫在堆之间复制对象,那将导致巨大的 运行 时间性能下降。同样,线程不能 运行 在分配它的同一逻辑堆上这一事实并不意味着它不能引用该堆。每个核心堆背后的想法是能够扩展分配并能够改进并行 gc 集合。