Clarification on the Shared Memory column in the Linux top utility

5,718

Solution 1

The SHR column simply represents the amount of shared memory used by the process. It can be used for interprocess communications, but a more common scenario is that this is memory used by shared libraries that an application has linked in.

From The Linux Kernel: Memory Management:

Shared Virtual Memory

Although virtual memory allows processes to have separate (virtual) address spaces, there are times when you need processes to share memory. For example there could be several processes in the system running the bash command shell. Rather than have several copies of bash, one in each processes virtual address space, it is better to have only one copy in physical memory and all of the processes running bash share it. Dynamic libraries are another common example of executing code shared between several processes.

Shared memory can also be used as an Inter Process Communication (IPC) mechanism, with two or more processes exchanging information via memory common to all of them. Linux supports the Unix TM System V shared memory IPC.

What the top man page says about this column:

   t: 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.

Solution 2

does it make sense for ANY process to have allocated 50 - 60 megabytes of shared memory

Yes.

For example, Oracle tuning guides have recommended shared memory sizes of gigabytes.

That said, if the process is "cat", it probably doesn't make much sense.

Share:
5,718

Related videos on Youtube

JamesH
Author by

JamesH

Updated on September 17, 2022

Comments

  • JamesH
    JamesH over 1 year

    We are having a memory allocation issues with a program running under Linux. We are using the top utility to try and determine the root cause of the problem. One thing that we have noticed is that one process has an excessively high value for shared memory (the SHR column in top).

    Reading the MAN page for top leads me to believe that the SHR column represents the amount of memory for interprocess communications via shared memory. Is this correct?

    If so, then does it make sense for ANY process to have allocated 50 - 60 megabytes of shared memory (X11 only allocates 11MB, which seems reasonable based on what it has to do).

    Thanks...

    • John T
      John T over 14 years
      What program specifically?