Table of Contents

About

Shared memory (SHM) in Linux.

The shared memory system can also be used to set permissions on memory.

There are two different types of shared memory implementations:

Management

By default, your operating system includes an entry in /etc/fstab to mount /dev/shm.

File structure

/dev/shm

shm / shmfs is also known as tmpfs.

tmpfs means temporary file storage facility. It is intended to appear as a mounted file system, but one which uses virtual memory instead of a persistent storage device.

How to check its size ?

To check the size of the shared memory file system, enter the following command:

df –k /dev/shm

Limit

To determine current shared memory limits you can use the ipcs command.

ipcs -lm
------ Shared Memory Limits --------
max number of segments = 4096
max seg size (kbytes) = 1073741824
max total shared memory (kbytes) = 17179869184
min seg size (bytes) = 1

Parameters

shmmax

shmmax define the Maximum size (in bytes) for a shared memory segment.

We gan get the parameters limit by using the proc Filesystem such as:

cat /proc/sys/kernel/shmmax
1099511627799

shmall total shared memory avail: 2097152

cat /proc/sys/kernel/shmall
4294967296

  • shmseg - max # of shared memory segs per process: (doesn't exist in FC6)
  • shmmni - max # of shared memory segs system-wide
cat /proc/sys/kernel/shmmni
4096

segments

ipcs -m

------ Shared Memory Segments --------
key        shmid      owner      perms      bytes      nattch     status
0x45110010 1774485506 oracle    660        1048576    2
0x00000000 3112963    oracle    660        67108864   51
0x00000000 3145732    oracle    660        1543503872 51
0x910ac490 3178501    oracle    660        2097152    51
0x6611c0d9 1774518278 oracle    660        126921994088 1                 locked
0x6711c0d9 1774551047 oracle    660        33554432   1
0x1111c0df 1775206408 oracle    660        273722634328 2                 locked
0x1211c0df 1775239177 oracle    660        33554432   2

Process

ipcs -pm
------ Shared Memory Creator/Last-op --------
shmid      owner      cpid       lpid
1774485506 oracle     30581      11420
3112963    oracle     24249      11377
3145732    oracle     24249      11377
3178501    oracle     24249      11377
1774518278 oracle     30572      11420
1774551047 oracle     30572      11420

where:

  • cpid is the process ID of the job that created the shared memory segment.
  • lpid is the process ID of the last job to attach or detach from the shared memory segment or change the semaphore value.

top

SHR – Shared Mem size (kb)

        The  amount of shared memory used by a task.  It simply reflects mem-
        ory that could be potentially shared with other processes.

Documentation / Reference