Christoph Rohland; Hugh Dickins; KOSAKI Motohiro
In laptop science, shared memory is memory that may be simultaneously accessed by multiple packages with an intent to offer communication among them or keep away from redundant copies. Shared memory is an environment friendly technique of passing information between programs. Depending on context, applications might run on a single processor or on a number of separate processors. Using memory for communication inside a single program, e.g. amongst its multiple threads, can also be known as shared memory. In pc hardware, shared memory refers to a (sometimes giant) block of random entry memory (RAM) that can be accessed by several different central processing items (CPUs) in a multiprocessor laptop system. A shared memory system is comparatively straightforward to program since all processors share a single view of data and the communication between processors will be as fast as memory accesses to the identical location. Making an attempt to entry close by memory places might cause false sharing. Shared memory computers can't scale very effectively.
Such cache coherence protocols can, when they work nicely, present extraordinarily excessive-performance access to shared info between a number of processors. Then again, they can generally change into overloaded and change into a bottleneck to performance. Applied sciences like crossbar switches, Omega networks, HyperTransport or entrance-aspect bus can be utilized to dampen the bottleneck-results. In case of a Heterogeneous System Structure (processor architecture that integrates different types of processors, reminiscent of CPUs and GPUs, with shared memory), the memory management unit (MMU) of the CPU and the input-output memory administration unit (IOMMU) of the GPU have to share sure characteristics, like a typical deal with space. The alternate options to shared memory are distributed memory and distributed shared memory, each having an analogous set of issues. CPUs and the underlying structure just isn't cache coherent. IPC by shared memory is used for example to switch photos between the applying and the X server on Unix systems, or contained in the IStream object returned by CoMarshalInterThreadInterfaceInStream in the COM libraries underneath Home windows.
Dynamic libraries are usually held in memory once and mapped to multiple processes, and solely pages that needed to be custom-made for the person process (because a symbol resolved otherwise there) are duplicated, usually with a mechanism generally known as copy-on-write that transparently copies the web page when a write is tried, and then lets the write succeed on the personal copy. In comparison with multiple address space working systems, memory sharing -- particularly of sharing procedures or pointer-primarily based structures -- is simpler in single handle house working systems. POSIX offers a standardized API for using shared memory, POSIX Shared Memory. POSIX interprocess communication (a part of the POSIX:XSI Extension) contains the shared-memory capabilities shmat, shmctl, shmdt and shmget. Unix System V gives an API for shared memory as well. This makes use of shmget from sys/shm.h. BSD techniques present "nameless mapped memory" which can be used by several processes. It stays within the system until explicitly removed by a course of.
This has a disadvantage in that if the process crashes and fails to wash up shared memory it should stay till system shutdown; that limitation shouldn't be current in an Android-particular implementation dubbed ashmem. POSIX additionally provides the mmap API for mapping information into memory; a mapping will be shared, permitting the file's contents to be used as shared memory. Linux distributions based on the 2.6 kernel and later offer /dev/shm as shared memory within the form of a RAM disk, more particularly as a world-writable listing (a directory during which every person of the system can create recordsdata) that's saved in memory. Both the RedHat and Debian based mostly distributions embrace it by default. Assist for the sort of RAM disk is completely non-compulsory within the kernel configuration file. On Windows, one can use CreateFileMapping and MapViewOfFile features to map a region of a file into memory in a number of processes. Qt supplies the QSharedMemory class. Other programming languages might have their very own methods of utilizing these operating amenities for similar impact. For instance, PHP provides an API to create shared memory, just like POSIX capabilities. El-Rewini, Hesham; Abd-El-Barr, Mostafa (2005). Superior Pc Structure and Parallel Processing. Jeffrey S. Chase; Henry M. Levy; Michael J. Feeley; and Edward D. Lazowska. Robbins, Kay A.; Robbins, Steven (2003). Unix systems programming: communication, concurrency, and threads (2 ed.). Prentice Corridor PTR. p. Shared memory facility from the single Unix Specification. Christoph Rohland; Hugh Dickins; KOSAKI Motohiro. Creating Named Shared Memory from MSDN. Shared Memory Introduction, MemoryWave Guide Ch. 12 from MemoryWave Guide by Richard Stevens "UNIX Network Programming, Quantity 2, Second Edition: Interprocess Communications". SharedHashFile, An open supply, shared memory hash desk.