<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hello,<br>
<br>
On 4/8/10 12:34 AM, IƱaki Baz Castillo wrote:
<blockquote
 cite="mid:i2pcc1f582e1004071534t955d00s7bf8ce3c46cd9d6b@mail.gmail.com"
 type="cite">
  <pre wrap="">Hi, according to the wiki page:
  <a class="moz-txt-link-freetext" href="http://www.kamailio.org/dokuwiki/doku.php/troubleshooting:memory">http://www.kamailio.org/dokuwiki/doku.php/troubleshooting:memory</a>

In order to detect a possible memory leak (in PGK or SHM) a good way
is enabling memory debugging and shuting down the server, so:

"the memory manager will dump the memory status. Normally most of the
memory is cleaned during shutdown. If there is memory leak, it should
be visible as not-freed memory."


But I would like to know how exactly to detect if there is a memoty
leak by inspecting the SHM/PKG status, something like this:


-----------------------------------------------------------------------------------------------------------------------------
[32715]: Memory status (pkg):
[32715]: fm_status (0x701a40):
[32715]:  heap size= 16777216
[32715]:  used= 189696, used+overhead=247392, free=16529824
[32715]:  max used (+overhead)= 247392
[32715]: dumping free list:
[32715]: hash =   1 fragments no.:     1, unused:     0#012#011#011
bucket size:         8 -         8 (first         8)
[32715]: hash = 2058 fragments no.:     1, unused:     0#012#011#011
bucket size:   8388608 -  16777216 (first  16530136)
[32715]: TOTAL:      2 free fragments = 16530144 free bytes

[32678]: Memory status (shm):
[32678]: fm_status (0x7fa57921c000):
[32678]:  heap size= 67108864
[32678]:  used= 16, used+overhead=35872, free=67072992
[32678]:  max used (+overhead)= 2821064
[32678]: dumping free list:
[32678]: hash =   1 fragments no.:    45, unused:     0#012#011#011
bucket size:         8 -         8 (first         8)
[32678]: hash =   2 fragments no.:     4, unused:     0#012#011#011
bucket size:        16 -        16 (first        16)
[32678]: hash =   3 fragments no.:    16, unused:     0#012#011#011
bucket size:        24 -        24 (first        24)
[32678]: hash =   4 fragments no.:     2, unused:     0#012#011#011
bucket size:        32 -        32 (first        32)
[32678]: hash =   5 fragments no.:     1, unused:     0#012#011#011
bucket size:        40 -        40 (first        40)
[32678]: hash =   6 fragments no.:     1, unused:     0#012#011#011
bucket size:        48 -        48 (first        48)
[32678]: hash =   7 fragments no.:    39, unused:     0#012#011#011
bucket size:        56 -        56 (first        56)
[32678]: hash =   8 fragments no.:     1, unused:     0#012#011#011
bucket size:        64 -        64 (first        64)
[32678]: hash =   9 fragments no.:     1, unused:     0#012#011#011
bucket size:        72 -        72 (first        72)
[32678]: hash =  10 fragments no.:     2, unused:     0#012#011#011
bucket size:        80 -        80 (first        80)
[32678]: hash =  15 fragments no.:     1, unused:     0#012#011#011
bucket size:       120 -       120 (first       120)
[32678]: hash =  25 fragments no.:     1, unused:     0#012#011#011
bucket size:       200 -       200 (first       200)
[32678]: hash =  40 fragments no.:     5, unused:     0#012#011#011
bucket size:       320 -       320 (first       320)
[32678]: hash = 112 fragments no.:     1, unused:     0#012#011#011
bucket size:       896 -       896 (first       896)
[32678]: hash = 128 fragments no.:     4, unused:     0#012#011#011
bucket size:      1024 -      1024 (first      1024)
[32678]: hash = 129 fragments no.:     2, unused:     0#012#011#011
bucket size:      1032 -      1032 (first      1032)
[32678]: hash = 224 fragments no.:     1, unused:     0#012#011#011
bucket size:      1792 -      1792 (first      1792)
[32678]: hash = 258 fragments no.:     3, unused:     0#012#011#011
bucket size:      2064 -      2064 (first      2064)
[32678]: hash = 473 fragments no.:     1, unused:     0#012#011#011
bucket size:      3784 -      3784 (first      3784)
[32678]: hash = 1026 fragments no.:     1, unused:     0#012#011#011
bucket size:      8208 -      8208 (first      8208)
[32678]: hash = 2049 fragments no.:     2, unused:     0#012#011#011
bucket size:     16384 -     32768 (first     16512)
[32678]: hash = 2051 fragments no.:     1, unused:     0#012#011#011
bucket size:     65536 -    131072 (first     98336)
[32678]: hash = 2056 fragments no.:     1, unused:     0#012#011#011
bucket size:   2097152 -   4194304 (first   2621440)
[32678]: hash = 2060 fragments no.:     1, unused:     0#012#011#011
bucket size:  33554432 -  67108864 (first  64287800)
[32678]: TOTAL:    137 free fragments = 67072992 free bytes
-----------------------------------------------------------------------------------------------------------------------------


This is, how should look this SHM/PKG status example (after shutdown)
in case there is a memory leak? how to detect not-freed memory?
  </pre>
</blockquote>
it does not look as a dump with memory debugging on.<br>
<br>
When memdbg is on, you should get something like:<br>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<pre class="code">   0(17665)       1. N  address=0xb5ab2440 frag=0xb5ab2428 size=4 used=1 
   0(17665)             alloc'd from timer.c: init_timer(52)
</pre>
<br>
Notice the "alloc'd ...' line which specifies the place where the
memory was allocated.<br>
<br>
A leak is signaled by many occurrences of allocation from same place
(skipping the part of allocation done for config parsing and module
initialization which happen only one, at startup).<br>
<br>
Send kamailio -v to see if memory debugging is on.<br>
<br>
Cheers,<br>
Daniel<br>
<br>
<div class="moz-signature">-- <br>
Daniel-Constantin Mierla
* <a class="moz-txt-link-freetext" href="http://www.asipto.com/">http://www.asipto.com/</a> * <a class="moz-txt-link-freetext" href="http://twitter.com/miconda">http://twitter.com/miconda</a>
* <a class="moz-txt-link-freetext" href="http://www.linkedin.com/in/danielconstantinmierla">http://www.linkedin.com/in/danielconstantinmierla</a>
</div>
</body>
</html>