Next: , Previous: semlimits, Up: Top



1.7 Shared Memory

Shared memory is distinct from the sharing of read-only code pages or the sharing of unaltered data pages that is available due to the copy-on-write mechanism. The essential difference is that the shared pages are dirty (in the case of Shared memory) and can be made to appear at a convenient location in the process' address space.

A shared segment is described by :

     struct shmid_ds
         struct  ipc_perm shm_perm;
         int     shm_segsz;              /* size of segment (bytes) */
         time_t  shm_atime;              /* last attach time */
         time_t  shm_dtime;              /* last detach time */
         time_t  shm_ctime;              /* last change time */
         ulong   *shm_pages;             /* internal page table */
         ushort  shm_cpid;               /* pid, creator */
         ushort  shm_lpid;               /* pid, last operation */
         short   shm_nattch;             /* no. of current attaches */

A shmget allocates a shmid_ds and an internal page table. A shmat maps the segment into the process' address space with pointers into the internal page table and the actual pages are faulted in as needed. The memory associated with the segment must be explicitly destroyed by calling shmctl with IPC_RMID.