系统与基础设施lwn.net编辑精选
每个程序员都应该了解的内存知识
What every programmer should know about memory
2010 — 2021,它一次次回到首页
黑点是上首页(≥ 50 分)的那次投稿,空心点是没冲上去的投稿,点越大分数越高。
导读
这是 Ulrich Drepper 于 2007 年撰写的长篇内存技术文章(LWN 上的 HTML 连载版本),系统介绍程序员应当了解的内存子系统:缓存层级、RAM、虚拟内存、NUMA,以及这些机制对程序性能的影响。文章偏重底层原理与实测数据,篇幅很长,常被视作内存性能方面的经典参考资料。
为什么经久不衰:尽管文中不少具体总线与北桥设计已经过时,但内存层级、访问延迟和局部性等核心原理至今仍是性能优化的重要基础,所以它反复被推荐。
HN 评论精选
主张程序员只需掌握内存层级的延迟与容量,而非底层物理细节。
每个程序员真的都需要了解动态 RAM 背后的物理原理吗?每个程序员应该知道的是各种内存类型(缓存、RAM、虚拟内存)的延迟和各自容量。这里有一张不错的图:http://duartes.org/gustavo/blog/post/what-your-computer-does-while-you-wait
klochner查看英文原文
Does every programmer really need to know the physics behind dynamic ram? What every programmer should know is the latency of the various memory types (cache, RAM, virtual) and their respective sizes. Here's a nice graphic: http://duartes.org/gustavo/blog/post/what-your-computer-does-while-you-wait
反对把底层硬件细节当作所有程序员的必备知识,强调抽象和高层工具的价值。
胡说。抽象去哪了?把这篇推荐给所有程序员当必备知识让我很生气。我受的是计算机与电气工程教育,主要用高层语言做 Web 软件。出于好奇,我把抽象层上下都走了一遍,也很享受,但程序员几乎没有任何理由知道那页里的东西。你可以完全不知道晶体管长什么样就做出极好的软件;这正是进步的意义。我们应该鼓励更高层思维,以及更有表现力的语言和工具。
pacemkr查看英文原文
Nonsense. What happened to abstraction? To suggest this as recommended knowledge to all programmers is actually making me angry. My education is in Computer and Electrical Engineering, while I mostly work with high level languages building software for the web. I've traveled up and down the abstraction ladder out of curiosity -- that explains the dual in EE. I've enjoyed it all, but there is zero reason for a programmer to know almost anything from that page. You can make phenomenal software without ever knowing what a transistor looks like on paper; and that's the whole point of progress. If anything, we should encourage higher level thinking and discovery of more expressive languages and tools.
指出文中总线/北桥架构已过时,并补充 DDR5 等现代变化。
关于此文写成后发生的变化,有几点观察:图 2.1 中传统共享前端总线连接 CPU 与北桥的布局早已消亡,AMD 约 2003 年、Intel 约 2008 年就在主流产品中淘汰了它。此后北桥和内存控制器几乎都位于 CPU 芯片上。AMD Zen 2 及之后的桌面/服务器 CPU 又把北桥拆成独立芯片(IO die)。我近期能想到的 x86 处理器,其 PCIe 端口都由北桥提供(通常就是 CPU 芯片的一部分)。南桥通过 PCIe(通常四通道)连接北桥/CPU,部分功能是充当 PCIe 扇出交换机。北桥、南桥这些术语已不常用,因为北桥在 CPU 芯片上已成标准做法十多年。DDR5 即将到来,重要变化是把一个 DIMM 拆成两个独立的 32 位内存通道,而非一个 64 位通道;这样可再次翻倍带宽,而不让突发长度超过标准 64 字节缓存行。
wtallis查看英文原文
A few observations about what's changed since this was written: The layout shown in Figure 2.1 with a traditional shared Front Side Bus linking CPUs to the northbridge is a long-dead design, having been retired from mainstream products by AMD around 2003 and by Intel around 2008. Since then, the northbridge and memory controllers have been on the CPU die(s) for almost all products. AMD's Zen 2 and later desktop/server CPUs split the northbridge back out to a separate die ("IO die"). All recent x86 processors that I can think of off the top of my head have the PCIe ports provided by the northbridge (which means it's usually part of the CPU die itself). The southbridge is connected to the northbridge/CPU by PCIe (usually four lanes), and part of the southbridge functionality is to act as a PCIe fanout switch. And the terms "northbridge" and "southbridge" have fallen out of common use, largely because the northbridge being on the CPU die was standard practice for both Intel and AMD for over a decade. DDR5 is coming, with the significant change of splitting a DIMM into two separate 32-bit memory channels rather than one 64-bit channel. That allows doubling bandwidth again without the burst length becoming longer than the standard 64-byte cache line size.
指出文章年代,并给出完整 PDF 链接和循序阅读的建议。
标题里或许该加个(2007),供参考。“What every programmer should know about memory”是现代经典,我一开始还以为这是关于该论文的当代文章。因为这是引言,有些读者可能需要读全文:https://people.freebsd.org/~lstewart/articles/cpumemory.pdf。当然那是 114 页 PDF,所以先读前 20 页 HTML 可能更容易真正读完。但这是极好的资源,我真需要花时间读完(我自己也从未读超过前 20 页……)。
ojnabieoot查看英文原文
This should probably have a (2007) in the title, FYI. “What every programmer should know about memory” is a modern classic and at first I thought this was a contemporary article about the paper. As this is the introduction, it might be helpful for some readers to read the rest of the document: https://people.freebsd.org/~lstewart/articles/cpumemory.pdf Of course, it’s a 114 page PDF so the first ~20 pages in HTML might be easier to actually finish reading. But this is a fantastic resource and something I really need to take the time to finish (I myself never get past the first 20 pages.....)
历次讨论
同类还值得读
TTY 揭秘(2008)
The TTY demystified (2008)
经典文章深入剖析了 Unix/Linux 中 TTY 子系统的工作原理,包括线路规程、终端驱动、信号与控制字符等机制。
系统与基础设施上首页 11 次 · 2009–2025linusakesson.net编辑精选为什么 GNU grep 这么快
Why GNU grep is Fast
FreeBSD 邮件列表上一篇广为流传的帖子,解释 GNU grep 为什么快:核心在于 Boyer-Moore 字符串搜索算法配合精心优化的内部循环和 I/O,让程序在搜索时“…
系统与基础设施上首页 9 次 · 2010–2022lists.freebsd.orgXplain:为普通人讲解 X11
Xplain – Explaining X11 for the rest of us
《Xplain》是作者(HN 用户 Jasper_)写的一系列 X11 长文,用他在浏览器中重建的 X11 绘图模型做交互演示,讲解 X11 的绘图模型与窗口系统设计。
系统与基础设施上首页 6 次 · 2013–2020magcius.github.io编辑精选旋风教程:为 Linux 创建极小 ELF 可执行文件(1999)
A Whirlwind Tutorial on Creating Really Teensy ELF Executables for Linux (1999)
breadbox 写于 1999 年的经典教程,主题是如何为 Linux 手工构造并裁剪出体积极小的 ELF 可执行文件。
系统与基础设施上首页 6 次 · 2007–2025muppetlabs.comPostgreSQL 内部原理
The internals of PostgreSQL
《The Internals of PostgreSQL》是一本免费在线书籍,系统讲解 PostgreSQL 的内部实现,包括查询处理、并发控制、WAL、缓冲区管理等核心机制。
系统与基础设施上首页 5 次 · 2017–2025interdb.jp编辑精选