# 分布式共享内存

**分布式共享内存**（Distributed shared memory，DSM）是在物理上没有共享内存的多计算机体系结构上实现共享内存抽象的一种方式：不同机器上的进程读写一个公共地址空间，就好像该内存是本地的一样，而系统在幕后通过网络搬运数据。<sup>[1](https://scholarsbank.uoregon.edu/items/ef6e2ac5-e9b4-4244-a526-a217ea865be0)</sup> 这种方法之所以有吸引力，是因为大多数程序员觉得全局地址空间比消息传递更易用，后者需要显式地划分数据并管理通信。<sup>[2](https://www.cs.rochester.edu/u/sandhya/papers/wusenix94.pdf)</sup> DSM 主要有两种形式：建立在普通工作站虚拟内存硬件之上的软件 DSM 系统，以及硬件支持的缓存一致分布式共享内存（CC-NUMA）多处理机。<sup>[2](https://www.cs.rochester.edu/u/sandhya/papers/wusenix94.pdf)</sup><sup> • </sup><sup>[3](https://rsim.cs.illinois.edu/arch/qual_papers/arch/lenoski_dash.pdf)</sup>

| 关键事实 | 详情 |
|---|---|
| 定义 | 在物理上不共享内存的机器上实现的共享内存抽象；数据按需通过网络传输<sup>[1](https://scholarsbank.uoregon.edu/items/ef6e2ac5-e9b4-4244-a526-a217ea865be0)</sup> |
| 首个软件系统 | IVY，由李凯（Kai Li）与保罗·胡达克（Paul Hudak）在耶鲁大学研制，是运行于 Apollo 环形网络上的共享虚拟内存原型（1986年）<sup>[4](https://doi.org/10.1145/10590.10610)</sup> |
| 首个硬件 CC-NUMA | 斯坦福 Dash，首台具备可扩展缓存一致性机制的实际运行机器，最多可配 64 个 RISC 处理器<sup>[3](https://rsim.cs.illinois.edu/arch/qual_papers/arch/lenoski_dash.pdf)</sup> |
| Dash 性能 | 每秒最高 16 亿条指令，每秒 6 亿次标量浮点运算<sup>[3](https://rsim.cs.illinois.edu/arch/qual_papers/arch/lenoski_dash.pdf)</sup> |
| 关键软件技术 | 惰性释放一致性加多写者协议，TreadMarks 借此减少一致性通信与假共享<sup>[2](https://www.cs.rochester.edu/u/sandhya/papers/wusenix94.pdf)</sup> |
| 主要软件隐患 | 假共享：虚拟内存页作为一致性单元过大，同一页上不相关的变量会触发不必要的传输<sup>[5](https://www.usenix.org/conference/osdi-94/software-write-detection-distributed-shared-memory)</sup> |
| 现代后裔 | 分区全局地址空间模型，如 OpenSHMEM——一个在分布式内存上进行数据交换与同步的 C/Fortran API<sup>[6](https://onlinelibrary.wiley.com/doi/full/10.1155/2020/4176794)</sup> |

## DSM 所解决的问题

分布式内存机器，如超立方体和 Transputer 阵列，传统上以[消息传递](https://www.edgepedia.org/zh/message-passing)作为编程模型，而共享内存机器则提供管程、信号量和取加（fetch-and-add）操作。<sup>[7](https://www.sciencedirect.com/science/article/abs/pii/0167819188901135)</sup> 消息传递要求程序员划分数据集并显式管理通信；共享地址空间则让程序员得以专注于算法开发。<sup>[2](https://www.cs.rochester.edu/u/sandhya/papers/wusenix94.pdf)</sup> DSM 的目标是在不要求物理共享内存的前提下，为分布式机器提供共享内存编程模型。<sup>[1](https://scholarsbank.uoregon.edu/items/ef6e2ac5-e9b4-4244-a526-a217ea865be0)</sup>

## 软件 DSM：共享虚拟内存

**IVY。** 软件 DSM 的基本机制由耶鲁大学的[李凯](https://www.edgepedia.org/zh/kai-li)和保罗·胡达克描述，并在 IVY 系统（Integrated shared Virtual Memory at Yale，耶鲁集成共享虚拟内存）中实现，这是一个运行在 Apollo 工作站局域网上的原型。<sup>[4](https://doi.org/10.1145/10590.10610)</sup><sup> • </sup><sup>[8](https://citeseerx.ist.psu.edu/document?doi=945246cd8ef2495e7451fb1a740265a3cd5b6992&repid=rep1&type=pdf)</sup> IVY 提供一个由松散耦合分布式内存多处理机的所有处理器共享的虚拟地址空间；其实验表明，在用户态原型上运行的并行程序相对于单处理器取得了近乎线性、偶尔超线性的加速比。<sup>[4](https://doi.org/10.1145/10590.10610)</sup> 李凯和胡达克在共享虚拟内存系统内存一致性方面的工作证明了 DSM 概念是可行的。<sup>[1](https://scholarsbank.uoregon.edu/items/ef6e2ac5-e9b4-4244-a526-a217ea865be0)</sup>

**TreadMarks。** 早期的 DSM 系统模仿硬件共享内存多处理机的一致性协议，结果饱受性能问题困扰。由于软件 DSM 中自然的一致性单元是[虚拟内存](https://www.edgepedia.org/zh/virtual-memory)页，假共享——即放在同一页上的不相关变量迫使进行不必要的通信——对许多应用来说是个严重问题。<sup>[2](https://www.cs.rochester.edu/u/sandhya/papers/wusenix94.pdf)</sup> [莱斯大学](https://www.edgepedia.org/zh/rice-university)的彼得·凯莱赫（Peter Keleher）、艾伦·L·考克斯（Alan L. Cox）、桑迪亚·德瓦卡达斯（Sandhya Dwarkadas）和威利·兹瓦内普尔（Willy Zwaenepoel）研制的 TreadMarks 用两项技术解决了这些问题：释放一致性的惰性实现——一种宽松的内存模型，将处理器的更新推迟到同步操作发生时才变为可见——以及多写者协议，允许多个处理器并发修改同一页，并通过差异（diff）协调改动，从而减轻假共享的影响。<sup>[2](https://www.cs.rochester.edu/u/sandhya/papers/wusenix94.pdf)</sup>

TreadMarks 在标准 Unix 系统的用户态运行，无需修改内核，利用虚拟内存保护来检测对共享数据的访问。在一次评估中，八台 DECStation-5000/240 工作站同时通过 100 Mbps 点对点 ATM 局域网和 10 Mbps 以太网连接；Jacobi、TSP、Quicksort 和 ILINK 都取得了良好的加速比，而 SPLASH 套件中的 Water 基准测试因同步和通信频率高，只显示出中等程度的加速。<sup>[2](https://www.cs.rochester.edu/u/sandhya/papers/wusenix94.pdf)</sup> 就所测量的应用而言，对于细粒度应用，瓶颈是软件通信开销，而非线路时间。<sup>[2](https://www.cs.rochester.edu/u/sandhya/papers/wusenix94.pdf)</sup>

**写检测。** 虚拟内存页保护是标准的写检测机制，它有两项代价：对受保护页的每次首次写入都会引发缺页异常，因此一页必须被多次写入才能摊薄这一代价；而且页作为一致性单元过大，会诱发假共享。编译器和运行时系统可以在不调用操作系统的情况下检测写入，从而以低开销获得较低的平均写入延迟和细粒度共享；[卡内基梅隆大学](https://www.edgepedia.org/zh/carnegie-mellon-university)的研究人员表明，无论采用哪种策略，写检测的主要开销都来自处理细粒度共享所用的机制。<sup>[5](https://www.usenix.org/conference/osdi-94/software-write-detection-distributed-shared-memory)</sup> 后续工作进一步细化了粒度：TreadMarks 惰性释放一致性的区域捕获版本以程序员定义的区域而非页为粒度管理数据，在六项测试应用中的五项里，捕获开销低于并行执行时间的 1%。<sup>[9](https://usenix.org/legacy/publications/library/proceedings/usenix99/full_papers/brecht/brecht_html/index.html)</sup>

## 硬件 DSM：缓存一致多处理机

**Dash。** 由丹尼尔·莱诺斯基（Daniel Lenoski）、詹姆斯·劳登（James Laudon）、库罗什·加拉乔卢（Kourosh Gharachorloo）及其同事领导的斯坦福 DASH 项目（Directory Architecture for Shared Memory，共享内存目录体系结构）旨在证明缓存一致的分布式共享内存（CC-NUMA）机器确实可以建造出来。利用目录跟踪缓存信息以及分布式缓存一致性协议的基础在此设计之前就已存在，但此前并无实际的 CC-NUMA 系统。<sup>[10](https://i.stanford.edu/pub/cstr/reports/csl/tr/97/744/CSL-TR-97-744.pdf)</sup> 其核心前提是：一台具有单一地址空间和一致缓存的可扩展高性能机器是可能的——内存分布在由具有可扩展带宽的网络相连的处理节点之间，基于目录的分布式协议在不损害可扩展性的前提下提供缓存一致性。<sup>[3](https://rsim.cs.illinois.edu/arch/qual_papers/arch/lenoski_dash.pdf)</sup>

Dash 原型是首台包含可扩展缓存一致性机制的实际运行机器。它最多可配 64 个高性能 RISC 微处理器，每秒可执行多达 16 亿条指令和 6 亿次标量浮点运算，其体系结构在处理器从几个增加到几千个的过程中实现了线性或接近线性的性能增长。<sup>[3](https://rsim.cs.illinois.edu/arch/qual_papers/arch/lenoski_dash.pdf)</sup> [基于目录的一致性](https://www.edgepedia.org/zh/directory-based-coherence)使 Dash 兼具共享内存体系结构的易用性和消息传递机器的可扩展性。<sup>[3](https://rsim.cs.illinois.edu/arch/qual_papers/arch/lenoski_dash.pdf)</sup> 在原型中，每个处理器是 33 MHz 的 MIPS R3000，配 64 KB 一级缓存和 256 KB 二级缓存，基于目录的协议在各簇之间维持一致性。<sup>[11](https://suif.stanford.edu/papers/anderson95/node18.html)</sup> DASH 是斯坦福 FLASH 项目的前身，后者将整个缓存一致性协议和目录实现在一个可编程处理器中。<sup>[10](https://i.stanford.edu/pub/cstr/reports/csl/tr/97/744/CSL-TR-97-744.pdf)</sup>

**目录的可扩展性。** 目录仍然是大规模机器的首选一致性机制。2012 年的一种设计 SCD 使用可变数量的目录标签来表示共享者集合，因此共享者很少的行使用单个标签，而广泛共享的行使用更多标签；在 1024 核片上多处理机的模拟中，它的面积效率是全映射稀疏目录的 13 倍，面积效率是层次化目录的 2 倍且速度更快。<sup>[12](https://mast.stanford.edu/pubs/scd_a_scalable_coherence_directory_with_flexible_sharer_set_encoding/)</sup>

## 一致性模型

内存一致性模型规定了当来自不同处理器的内存操作只存在偏序关系时，一次读操作可以返回哪些值。<sup>[13](https://arxiv.org/abs/cs/0208027)</sup> 顺序一致内存是基于总线的监听缓存多处理机的传统模型，它要求执行过程等价于处理器操作的某个单一顺序次序，且该次序保持每个处理器的程序顺序。<sup>[2](https://www.cs.rochester.edu/u/sandhya/papers/wusenix94.pdf)</sup><sup> • </sup><sup>[16](https://xdn.cs.umass.edu/consistency-definitions/)</sup> 释放一致性放宽了这一要求：一个处理器对普通共享内存的更新，只有在写者后续的释放操作对读者可见时，才对另一处理器可见，这减少了通信量，同时提供非常相似的编程接口。<sup>[2](https://www.cs.rochester.edu/u/sandhya/papers/wusenix94.pdf)</sup> 对于同步充分的程序，释放一致性等价于顺序一致性。<sup>[2](https://www.cs.rochester.edu/u/sandhya/papers/wusenix94.pdf)</sup><sup> • </sup><sup>[17](https://web.csl.cornell.edu/courses/ece5750/gharachorloo.isca90.pdf)</sup> 更弱的模型继续发展：基于视图的一致性模型实现在 TreadMarks 之上，它只要求：在无数据竞争的程序中，一个处理器有权访问的数据对象在其访问之前已被更新；在测试的应用上，它的表现优于惰性释放一致性。<sup>[14](https://www.sciweavers.org/publications/view-based-consistency-and-its-implementation)</sup>

## 现代后裔

共享地址空间的思想在分区全局地址空间（PGAS）家族中延续下来。[OpenSHMEM](https://www.edgepedia.org/zh/openshmem) 规范提供了一个 C/Fortran API，用于在分布式共享内存中进行数据交换和进程同步，其中每个进程都可以读写一个公共变量池，并使用屏障等同步函数；相关的 PGAS 语言和库包括 Chapel、X10、Unified Parallel C 和 Coarray Fortran。<sup>[6](https://onlinelibrary.wiley.com/doi/full/10.1155/2020/4176794)</sup> OpenSHMEM 程序在风格上是 SPMD 的，处理单元通过 put 和 get 操作、远程指针、集合广播与归约、屏障以及取加（fetch-and-increment）等原子内存操作进行通信。<sup>[15](https://docs.open-mpi.org/en/v5.0.10/man-openshmem/man3/intro_shmem.3.html)</sup> 这些单边通信模型与消息传递共存：MPI 仍然是跨集群节点进程间交换消息的标准，两种方法常常结合在同一程序中使用。<sup>[6](https://onlinelibrary.wiley.com/doi/full/10.1155/2020/4176794)</sup>

## References

1. [Distributed Shared Memory: A Survey of Issues and Algorithms, University of Oregon](https://scholarsbank.uoregon.edu/items/ef6e2ac5-e9b4-4244-a526-a217ea865be0)
2. [Keleher, Cox, Dwarkadas, Zwaenepoel. TreadMarks: Distributed Shared Memory on Standard Workstations and Operating Systems, USENIX Winter 1994](https://www.cs.rochester.edu/u/sandhya/papers/wusenix94.pdf)
3. [Lenoski et al. The Stanford Dash Multiprocessor, Computer 25(3), March 1992](https://rsim.cs.illinois.edu/arch/qual_papers/arch/lenoski_dash.pdf)
4. [Li, Hudak. Memory Coherence in Shared Virtual Memory Systems, PODC 1986](https://doi.org/10.1145/10590.10610)
5. [Zekauskas, Sawdon, Bershad. Software Write Detection for Distributed Shared Memory, OSDI 1994](https://www.usenix.org/conference/osdi-94/software-write-detection-distributed-shared-memory)
6. [Czarnul et al. Survey of Methodologies, Approaches, and Challenges in Parallel Programming Using High-Performance Computing Systems, Scientific Programming 2020](https://onlinelibrary.wiley.com/doi/full/10.1155/2020/4176794)
7. [Baillie. Comparing shared and distributed memory computers, Parallel Computing 8, 1988](https://www.sciencedirect.com/science/article/abs/pii/0167819188901135)
8. [vNUMA: Virtual Shared-Memory (notes on IVY's place in DSM history)](https://citeseerx.ist.psu.edu/document?doi=945246cd8ef2495e7451fb1a740265a3cd5b6992&repid=rep1&type=pdf)
9. [Region trapping case study in TreadMarks, USENIX 1999 Annual Technical Conference](https://usenix.org/legacy/publications/library/proceedings/usenix99/full_papers/brecht/brecht_html/index.html)
10. [The FLASH Multiprocessor: Designing Tightly Coupled Multiprocessing, Stanford CSL-TR-97-744](https://i.stanford.edu/pub/cstr/reports/csl/tr/97/744/CSL-TR-97-744.pdf)
11. [Experimental setup on the DASH multiprocessor, Stanford SUIF papers](https://suif.stanford.edu/papers/anderson95/node18.html)
12. [Sanchez, Kozyrakis. SCD: A Scalable Coherence Directory with Flexible Sharer Set Encoding, HPCA 2012](https://mast.stanford.edu/pubs/scd_a_scalable_coherence_directory_with_flexible_sharer_set_encoding/)
13. [A Unified Theory of Shared Memory Consistency, arXiv](https://arxiv.org/abs/cs/0208027)
14. [Huang, Cranefield, Purvis, Sun. View-Based Consistency and Its Implementation, CCGRID 2001](https://www.sciweavers.org/publications/view-based-consistency-and-its-implementation)
15. [intro_shmem: Introduction to the OpenSHMEM programming model, Open MPI documentation](https://docs.open-mpi.org/en/v5.0.10/man-openshmem/man3/intro_shmem.3.html)
16. [Formal definitions - XDN](https://xdn.cs.umass.edu/consistency-definitions/)
17. [web.csl.cornell.edu](https://web.csl.cornell.edu/courses/ece5750/gharachorloo.isca90.pdf)

---
*Initially written Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 计算机硬件 › Servers, supercomputers & data centers › Cluster and parallel architectures

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/distributed-shared-memory

English original: https://www.edgepedia.org/distributed-shared-memory
