Shared memory - Wikipedia, the free encyclopedia

来源:百度文库 编辑:神马文学网 时间:2024/10/03 02:38:46

Shared memory

From Wikipedia, the free encyclopedia

Jump to: navigation,searchNot to be confused with Shared Memory Architecture, where the graphics chip uses main system RAM.

In computing, shared memory is memorythat may be simultaneously accessed by multiple programs with an intentto provide communication among them or avoid redundant copies.Depending on context, programs may run on a single processor or onmultiple separate processors. Using memory for communication inside asingle program, for example among its multiple threads, is generally not referred to as shared memory.

Contents

[hide]
  • 1 In hardware
  • 2 In software
  • 3 See also
  • 4 External links

[edit] In hardware

In computer hardware, shared memory refers to a (typically) large block of random access memory that can be accessed by several different central processing units (CPUs) in a multiple-processor computer system.

A shared memory system is relatively easy to program since allprocessors share a single view of data and the communication betweenprocessors can be as fast as memory accesses to a same location.

The issue with shared memory systems is that many CPUs need fast access to memory and will likely cache memory, which has two complications:

  • CPU-to-memory connection becomes a bottleneck. Shared memory computers cannot scale very well. Most of them have ten or fewer processors.
  • Cache coherence: Whenever one cache is updated with information that may be used by other processors, the change needs to be reflected to the other processors, otherwise the different processors will be working with incoherent data (see cache coherence and memory coherence). Such coherence protocols can, when they work well, provide extremely high-performance access to shared information between multiple processors. On the other hand they can sometimes become overloaded and become a bottleneck to performance.

The alternatives to shared memory are distributed memory and distributed shared memory, each having a similar set of issues. See also Non-Uniform Memory Access.

[edit] In software

In computer software, shared memory is either

  • a method of inter-process communication (IPC), i.e. a way of exchanging data between programs running at the same time. One process will create an area in RAM which other processes can access, or
  • a method of conserving memory space by directing accesses to what would ordinarily be copies of a piece of data to a single instance instead, by using virtual memory mappings or with explicit support of the program in question. This is most often used for shared libraries and for XIP.

Since both processes can access the shared memory area like regularworking memory, this is a very fast way of communication (as opposed toother mechanisms of IPC such as named pipes, Unix domain sockets or CORBA).On the other hand, it is less powerful, as for example thecommunicating processes must be running on the same machine (whereasother IPC methods can use a computer network),and care must be taken to avoid issues if processes sharing memory arerunning on separate CPUs and the underlying architecture is not cache coherent.

IPC by shared memory is used for example to transfer images between the application and the X server on Unix systems, or inside the IStream object returned by CoMarshalInterThreadInterfaceInStream in the COM libraries under Windows.

Dynamic librariesare generally held in memory once and mapped to multiple processes, andonly pages that had to be customized for the individual process(because a symbol resolved differently there) are duplicated, usuallywith a mechanism that transparently copies the page when a write isattempted, and then lets the write succeed on the private copy.

POSIX provides a standardized API for using shared memory, POSIX Shared Memory. This uses the function shm_open from sys/mman.h.

Unix System 5 provides an API for shared memory as well. This uses shmget from sys/shm.h.

BSD systems provide "anonymous mapped memory" which can be used by several processes.

Recent 2.6 Linux kernel builds have started to offer /dev/shm as shared memory in the form of a RAM disk, more specifically as a world-writable[clarification needed]directory that is stored in memory with a defined limit in/etc/default/tmpfs. /dev/shm support is completely optional within thekernel configuration file. It is included by default in both Fedora and Ubuntu distributions.

[edit] See also

  • Shared Memory Architecture, where the graphics chip uses main system RAM
  • Global variable
  • Distributed shared memory

[edit] External links

This article's use of external links may not follow Wikipedia's policies or guidelines. Please improve this article by removing excessive and inappropriate external links or by converting links into footnote references. (June 2010)
  • Shared Memory Interface
  • Shared Memory Library FAQ by Márcio Serolli Pinho
  • Article "IPC:Shared Memory" by Dave Marshall
  • shared memory facility from the Single UNIX Specification
  • shm_open - POSIX
  • shmop - documentation from SunOS 5.9
  • CreateSharedMemory function from Win32-SDK
  • Functions in PHP-API
  • Paper "A C++ Pooled, Shared Memory Allocator For The Standard Template Library" by Marc Ronell
  • Citations from CiteSeer
  • Linux Shared Memory Allocation with example
  • Boost.Interprocess C++ Library
  • Linux and Solaris IPC examples IPC SystemV shared memory. IPC message queues - posix ans system V.