多核架构中的 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 和内存访问 的相关文章

  • 使用 Nginx 或 Apache 来提供动态内容? [关闭]

    就目前情况而言 这个问题不太适合我们的问答形式 我们希望答案得到事实 参考资料或专业知识的支持 但这个问题可能会引发辩论 争论 民意调查或扩展讨论 如果您觉得这个问题可以改进并可能重新开放 访问帮助中心 help reopen questi
  • CPU是如何做减法的?

    我有一些基本的疑问 但每次我坐下来尝试面试问题时 这些问题和我的疑问就会出现 假设 A 5 B 2 假设A和B都是4字节 那么CPU是怎么做的呢 A B添加 我知道 A 的符号位 MSB 为 0 表示正值 B 的符号位为 1 表示负整数 现
  • Python:数百万个小文件的读写速度缓慢

    结论 看来 HDF5 是适合我的目的的方法 基本上 HDF5 是一种用于存储和管理数据的数据模型 库和文件格式 并且旨在处理令人难以置信的大量数据 它有一个名为 python tables 的 Python 模块 链接在下面的答案中 HDF
  • 如何查找或计算Linux进程的页表大小和其他内核占用?

    我怎样才能知道 Linux 进程页表有多大 以及任何其他可变大小的进程统计 如果您真的对页表感兴趣 请执行以下操作 cat proc meminfo grep PageTables PageTables 24496 kB
  • java IO将一个文件复制到另一个文件

    我有两个 Java io File 对象 file1 和 file2 我想将 file1 的内容复制到 file2 有没有一种标准方法可以做到这一点 而无需我创建一个读取 file1 并写入 file2 的方法 不 没有内置方法可以做到这一
  • C语言中变量名是如何存储在内存中的?

    在 C 中 假设你有一个名为variable name 假设它位于0xaaaaaaaa 在该内存地址处 您有整数 123 换句话说 variable name包含 123 个 我正在寻找有关措辞的澄清 variable name位于0xaa
  • List.Clear() 在 C# 中是如何实现的?

    我假设它使用数组来实现 List 怎么List Clear 实施的 它实际上清理了数组还是只是为此列表创建了一个新数组 public class List private Array array public void Clear1 arr
  • C 中的菱形数组排序

    我有以下 C 语言作业 我基本上需要一种方法而不是解决方案 我们有一个 13 x 13 的数组 在数组中 我们有一个需要考虑的菱形形状 该菱形之外的所有内容都初始化为 1 不重要 下面的 5 x 5 数组示例 x x 1 x x x 2 2
  • 内存不一致与线程交错有何不同?

    我正在编写一个多线程程序 正在研究是否应该使用volatile对于我的布尔标志 关于并发性的文档 oracle Trail 没有解释任何关于memory consistency errors以外 当不同的线程有内存一致性错误时 就会发生内存
  • 在运行的 Swing 应用程序中替换 AWT EventQueue 的安全方法

    我维护的 Swing 应用程序中的各种零星问题似乎是由它使用自己的自定义版本替换默认 AWT 事件队列的方式引起的Toolkit getDefaultToolkit getSystemEventQueue push new AEventQu
  • 为什么 .NET 异步等待文件复制比同步 File.Copy() 调用消耗更多 CPU?

    为什么下面的代码会产生 public static class Program public static void Main params string args var sourceFileName C Users ehoua Desk
  • 无法删除临时文件夹(有时)

    当我启动应用程序时 我创建一个临时文件夹 public static File createTempDir String name throws IOException File tempDir File createTempFile na
  • 如何组合 3 个或更多 CompletionStages?

    如果有 2 个 CompletionStages 我可以将它们与thenCombine method CompletionStage a aCompletionStage getA CompletionStage b bCompletion
  • 是否有其他方法可以释放 C 中动态分配的内存 - 不使用 free() 函数?

    我正在为测试而学习 我想知道这些是否等同于 free ptr malloc NULL calloc ptr realloc NULL ptr calloc ptr 0 realloc ptr 0 据我了解 这些都不起作用 因为 free 函
  • 在 python 中将变量设置为“None”是否更节省内存?

    这是一个简单的问题 但由于我没有找到任何答案 我认为答案是否定的 但是 为了确保这一点 我要问 将变量设置为是否会使Python代码更有效None当我们在函数中使用完它们之后 举个例子 def foo fname temp 1 temp 2
  • 为什么在 10 个 Java 线程中递增一个数字不会得到 10 的值?

    我不明白 a 的值为0 为什么 a 不是10 那段代码的运行过程是怎样的 是否需要从Java内存模型来分析 这是我的测试代码 package com study concurrent demo import lombok extern sl
  • Guzzle 中的“并发”到底是什么?

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

    您可以在here https en wikipedia org wiki Race condition Software关于什么是竞争条件的一个很好的解释 我最近看到很多人对竞争条件和线程做出了令人困惑的陈述 我了解到竞争条件只能发生在线程
  • sizeof(某个指针)总是等于四吗?

    例如 sizeof char 返回 4 也是如此int long long 我尝试过的一切 这有什么例外吗 您得到的保证是sizeof char 1 没有其他保证 包括不保证sizeof int sizeof double 实际上 在 16
  • 在 Java 中如何找出哪个对象打开了文件?

    我需要找出答案哪个对象在我的 Java 应用程序中打开了一个文件 这是为了调试 因此欢迎使用工具或实用程序 如果发现哪个对象太具体了 这class也会很有帮助 这可能很棘手 您可以从使用分析器开始 例如VisualVM http visua

随机推荐