0

In the manpage of top,

  • Why are "program images and shared libraries" in #3 "considered private to a process", if "they will be accounted for as shared (SHR) by the kernel"?

  • In what "private" sense are "program images and shared libraries" "considered private to a process"? Are "program images and shared libraries" read only?

  • In what "shared" sense are "program images and shared libraries" "accounted for as shared (SHR) by the kernel"?

  • "the swap file only includes #1 through #3. The memory in quadrant #4, when modified, acts as its own dedicated swap file." Do "program images and shared libraries" act as their own dedicated swap files too?

Thanks.

For each such process, every memory page is restricted to a single quadrant from the table below. Both physical memory and virtual
memory can include any of the four, while the swap file only includes #1 through #3. The memory in quadrant #4, when modified, acts as its own dedicated swap file.

                             Private | Shared
                         1           |          2
    Anonymous  . stack               |
               . malloc()            |
               . brk()/sbrk()        | . POSIX shm*
               . mmap(PRIVATE, ANON) | . mmap(SHARED, ANON)
              -----------------------+----------------------
               . mmap(PRIVATE, fd)   | . mmap(SHARED, fd)
  File-backed  . pgms/shared libs    |
                         3           |          4

The following may help in interpreting process level memory values displayed as scalable columns and discussed under topic `3a.DESCRIPTIONS of Fields'.

  SHR  - subset of RES (excludes 1, includes all 2 & 4, some 3)

Note: Even though program images and shared libraries are considered private to a process, they will be accounted for as shared (SHR) by the kernel.

1

The diagram distinguishes private v. shared from the running processes’ perspective. Pages represented on the left are private to each process, even if they can be shared by the kernel (i.e. mapped to the same physical location, in memory or in a backing store). Pages represented on the right are shared by potentially multiple processes, and there is no strict expectation of privacy.

Thus program images and shared libraries are private because any change made to them, in memory, is only visible to the process making the changes. Most of the pages mapped from executables and libraries are indeed non-writable, but they don’t have to be.

They are simultaneously shared, as viewed by the kernel, because they map to shared physical areas. (Using copy-on-write so they can be unshared if necessary.) That sharing is a kernel-level detail, and is invisible to processes.

Swap is a backing store for dirty pages, i.e. memory which has been changed since it was loaded. Non-dirty pages don’t need swap: their source (typically a memory-mapped file) is their backing store, and when memory pressures dictates that they be removed from physical memory, they can simply be discarded. Dirty, non-shared pages, need a backing store of some sort if they are to be removed from physical memory. In most cases that’s swap; but file-backed shared memory has another natural backing store, the file which backs it. Pages of file-backed shared memory which need to be removed from physical memory can be written to the backing file and discarded, without involving swap.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.