多核架构中的 CPU 和内存访问

2023-12-01

我想知道如果,例如,CPU 的 2 个核心尝试同时访问内存(通过内存控制器),“一般”如何处理内存访问?实际上,当内核和启用 DMA 的 IO 设备尝试以相同方式访问时,同样适用。

I think,内存控制器足够智能,可以利用地址总线并同时处理这些请求,但是我不确定当它们尝试访问同一位置或 IO 操作独占地址总线并且 CPU 没有移动空间时会发生什么在。

Thx


简短的回答是“这很复杂,但访问肯定可以潜在地在某些情况下同时发生”。

我认为你的问题有点太黑白分明:你可能正在寻找像“是的,多个设备可以访问内存”这样的答案。same时间”或“不,他们不能”,但现实是,首先您需要描述一些特定的硬件配置,包括一些低级实现细节和优化功能,以获得准确的答案。最后您会需要准确定义“同时”的含义。

一般来说,一个好的一阶近似是硬件能够实现appear所有硬件都可以几乎同时访问内存,但可能会由于争用而导致延迟增加和带宽减少。在非常细粒度的时序级别,一个设备的访问确实可能会推迟另一设备的访问,也可能不会,具体取决于许多因素。您极不可能需要此信息来实现软件正确地,而且您不太可能需要了解细节才能最大限度地提高性能。

也就是说,如果您确实需要了解详细信息,请继续阅读,我可以对某种理想化的笔记本电脑/台式机/服务器规模硬件给出一些一般性观察。

正如 Matthias 提到的,您首先必须考虑缓存。缓存意味着任何受缓存影响的读或写操作(包括几乎所有 CPU 请求和许多其他类型的请求)可能根本不接触内存,因此从这个意义上说,许多内核可以“访问”内存(至少是缓存)它的图像)同时进行。

If you then consider requests that miss in all cache levels, you need to know about the configuration of the memory subsystem. In general a RAM chips can only do "one thing" at a time (i.e., commands1 such a read and write apply to the entire module) and that usually extends to DRAM modules comprised of several chips and also to a series of DRAMs connected via a bus to a single memory controller.

So you can say that electrically speaking, the combination of one memory controller and its attached RAM is likely to be doing only on thing at once. Now that thing is usually something like reading bytes out of a physically contiguous span of bytes, but that operation could actually help handle several requests from different devices at once: even though each devices sends separate requests to the controller, good implementations will coalesce requests to the same or nearby2 area of memory.

此外,甚至 CPU 也可能具有这样的能力:当出现新请求时,它可以/必须注意到现有请求正在针对重叠区域进行,并将新请求与旧请求联系起来。

Still, you can say that for a single memory controller you'll usually be serving the request of one device at a time, absent unusual opportunities to combine requests. Now the requests themselves are typically on the order of nanoseconds, so many separate requests can be served in a small unit of time, so this "exclusiveness" fine-grained and not generally noticeable3.

Now above I was careful to limit the discussion to a single memory-controller - when you have multiple memory controllers4 you can definitely have multiple devices accessing memory simultaneously even at the RAM level. Here each controller is essentially independent, so if the requests from two devices map to different controllers (different NUMA regions) they can proceed in parallel.

这是很长的答案。


1 In fact, the command stream is lower level and more complex than things like "read" or "write" and involves concepts such as opening a memory page, streaming bytes from it, etc. What every programmer should know about memory serves as an excellent intro to the topic.

2 For example, imagine two requests for adjacent bytes in memory: it is possible the controller can combine them into a single request if they fit within the bus width.

3 Of course if you are competing for memory across several devices, the overall impact may be very noticeable: a reduction in per-device bandwidth and an increase in latency, but what I mean is that the sharing is fine-grained enough that you can't generally tell the difference between finely-sliced exclusive access and some hypothetical device which makes simultaneous progress on each request in each period.

4 The most common configuration on modern hardware is one memory controller per socket, so on a 2P system you'd usually have two controllers, also other rations (both higher and lower) are certainly possible.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

多核架构中的 CPU 和内存访问 的相关文章

  • WaitForSingleObject 是否充当内存屏障?

    昨天一个关于双重检查锁定的问题引发了一系列的想法 让我对一个简单的情况感到不确定 在下面的代码中 是否可以点击printf 不再同步 在这个简单的示例中 这些值可能位于同一缓存行上 因此我认为这种可能性较小 假设一开始可能性 gt 0 如果
  • 独占锁定ConcurrentHashMap

    我知道不可能锁定 ConcurrentHashMap 进行独占访问 但是 我找不到原因 是因为构成CHM的 Segment 没有被api公开吗 据推测 如果是的话 客户端代码可以执行 交接 锁定 Cheers 我知道不可能锁定 Concur
  • rdstate()返回值是什么意思?

    istream Read istream is std string buf while is gt gt buf cout lt lt is eofbit lt lt lt lt is failbit lt lt lt lt is bad
  • 序列化对于对象大小估计可靠吗?

    我使用序列化来估计对象使用的内存量 我已经读过this https stackoverflow com questions 426396 how much memory does a c net object use and this ht
  • 在运行的 Swing 应用程序中替换 AWT EventQueue 的安全方法

    我维护的 Swing 应用程序中的各种零星问题似乎是由它使用自己的自定义版本替换默认 AWT 事件队列的方式引起的Toolkit getDefaultToolkit getSystemEventQueue push new AEventQu
  • 可以禁用“应用程序错误”对话框吗?

    我使用 Hudson 作为持续集成服务器来测试 C C 代码 不幸的是 我在某个地方有一个错误导致内存损坏 因此在某些 Windows 计算机上我有时会收到一个 应用程序错误 对话框 解释一条指令引用了无法读取的内存 弹出此对话框并基本上挂
  • 为什么结构中“[0]byte”的位置很重要?

    0 byte在golang中不应该占用任何内存空间 但这两个结构体的大小不同 type bar2 struct A int 0 byte type bar3 struct 0 byte A int 那么为什么这个位置 0 byte这里重要吗
  • PHP 对象创建和内存使用

    一个基本的虚拟类 class foo var bar 0 function foo function boo echo memory get usage echo n foo new foo echo memory get usage ec
  • 为什么在 Linux 上字符串文字的内存地址与其他字符串文字的内存地址如此不同?

    我注意到字符串文字在内存中的地址与其他常量和变量 Linux 操作系统 非常不同 它们有许多前导零 未打印 Example const char h Hi int i 1 printf p n void h printf p n void
  • 如何从标准输入读取一行,阻塞直到找到换行符?

    我试图从命令行的标准输入一次读取任意长度的一行 我不确定是否能够包含 GNU readline 并且更喜欢使用库函数 我读过的文档表明getline应该可以工作 但在我的实验中它不会阻塞 我的示例程序 include
  • 什么是内部类的合成反向引用

    我正在寻找应用程序中的内存泄漏 我正在使用的探查器告诉我寻找这些类型的引用 但我不知道我在寻找什么 有人可以解释一下吗 Thanks Elliott 您可以对 OUTER 类进行合成反向引用 但不能对内部类实例进行合成 e g class
  • Guzzle 中的“并发”到底是什么?

    我没有找到太多关于concurrency选项中Pool 如果这是可以在服务器上打开的 TCP 套接字数量 那么问题是 我可以使用多少并发来更快地处理请求 我有这个使用的例子Pool I am using Laravel this is ba
  • Objective-C 使用字符串池吗?

    我知道Java https stackoverflow com questions 3801343 what is string pool in java and C http msdn microsoft com en us librar
  • C 中带有指针的结构的内存开销[重复]

    这个问题在这里已经有答案了 我意识到当我的结构包含指针时 它们会产生内存开销 这里有一个例子 typedef struct int num1 int num2 myStruct1 typedef struct int p int num2
  • NodeJS CPU 一次飙升至 100%

    我有一个用 NodeJS 编写的 SOCKS5 代理服务器 我正在使用原生net and dgram打开 TCP 和 UDP 套接字的库 它可以正常工作大约 2 天 所有 CPU 的最大利用率约为 30 两天没有重新启动后 一个 CPU 峰
  • 跟踪 Linux 程序中活跃使用的内存

    我想跟踪各种程序在特定状态下接触了多少内存 例如 假设我有一个图形程序 最小化时 它可能会使用更少的内存 因为它不会重新绘制窗口 这需要读取图像和字体并执行大量库函数 这些对象仍然可以在内存中访问 但实际上并没有被使用 类似的工具top它们
  • Java Runtime.getRuntime().freeMemory() 问题

    我搜索并看到了一些线程 但没有一个能够解决我遇到的具体问题 我正在尝试使用以下方式监视我的内存使用情况Runtime getRuntime freeMemory Runtime getRuntime maxMemory and Runtim
  • c# 通过内存地址调用方法

    我正在尝试在 C 中的指定内存地址调用函数 以下是我在 C 中的操作方法 typedef void do int i auto doActor do 0xAAAABEEF doActor 1 如果可能的话 如何在 C 中复制这种行为 对 C
  • ConcurrentHashMap 内部是如何工作的?

    我正在阅读有关 Java 并发性的 Oracle 官方文档 我想知道Collection由返回 public static
  • 串行 I/O 与 Windows/Windows CE 重叠/不重叠

    抱歉 这不是一个大问题 但更多的是帮助那些在这些特定问题上遇到问题的人 我正在解决的问题需要使用串行 I O 但主要在 Windows CE 6 0 下运行 然而 最近有人问我该应用程序是否也可以在 Windows 下运行 所以我开始着手解

随机推荐