[Kamailio-Users] Understanding memory-leaks by inspecting PKG/SHM memory status at shutdown
Daniel-Constantin Mierla
miconda at gmail.com
Thu Apr 8 09:47:11 CEST 2010
Hello,
On 4/8/10 12:34 AM, Iñaki Baz Castillo wrote:
> Hi, according to the wiki page:
> http://www.kamailio.org/dokuwiki/doku.php/troubleshooting:memory
>
> 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?
>
it does not look as a dump with memory debugging on.
When memdbg is on, you should get something like:
0(17665) 1. N address=0xb5ab2440 frag=0xb5ab2428 size=4 used=1
0(17665) alloc'd from timer.c: init_timer(52)
Notice the "alloc'd ...' line which specifies the place where the memory
was allocated.
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).
Send kamailio -v to see if memory debugging is on.
Cheers,
Daniel
--
Daniel-Constantin Mierla * http://www.asipto.com/ *
http://twitter.com/miconda *
http://www.linkedin.com/in/danielconstantinmierla
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sip-router.org/pipermail/sr-users/attachments/20100408/98909a7a/attachment.htm>
More information about the sr-users
mailing list