Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shared_dirty vs Private_dirty in shared memory

I have multi process application using shared memory. I am trying to detect memory leak in my application. I found this in /proc/$pid/smap

 2b51cd2b2000-2b53b8aa4000 rw-s 00000000 00:09 17151225                   /dev/zero (deleted)
  Size:           8052680 kB
  Rss:              31608 kB
  Shared_Clean:      1524 kB
  Shared_Dirty:     25736 kB
  Private_Clean:        0 kB
  Private_Dirty:     4348 kB
  Swap:                 0 kB
  Pss:               6945 kB

This is shared memory that I allocated.(size tells this is one which is allocated by me with mmap)

I was trying to understand the difference between Shared/Private in this context where memory is itself shared. See 's' flag.

If any one can explain the difference between Shared_Clean vs Private_Clean Shared_Dirty vs Private_Dirty in the context of shared memory.

like image 670
Vikas Avatar asked Oct 08 '15 23:10

Vikas


1 Answers

The distinction between Clean and Dirty refers to whether or not the pages have been written-out to the backing store since being written to in memory. For a mapping of /dev/zero, pages are obviously never written-out, so Clean pages have only been read whereas Dirty pages have been written to.

For a shared mapping, the distinction between Private and Shared is whether the pages have only been referenced by the process you're examining, or whether they've been referenced by multiple processes.

So in summary:

  • Shared_Clean are the pages in the mapping that have been referenced by this process and at least one other process, but not written by any process;
  • Shared_Dirty are the pages in the mapping that have been referenced by this process and at least one other process, and written by at least one of those processes;
  • Private_Clean are the pages in the mapping that have been read and not written by this process but not referenced by any other process;
  • Private_Dirty are the pages in the mapping that have been written by this process but not referenced by any other process.

Pages can move from Clean to Dirty when they're written to, and from Private to Shared when another process references them.

If you map a real disk file, then pages can also move from Dirty to Clean when they're written-out by the kernel.

like image 57
caf Avatar answered Nov 27 '22 05:11

caf