<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:Wingdings;
        panose-1:5 0 0 0 0 0 0 0 0 0;}
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        color:black;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#0563C1;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
p
        {mso-style-priority:99;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        color:black;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";
        color:black;}
p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph
        {mso-style-priority:34;
        margin-top:0in;
        margin-right:0in;
        margin-bottom:0in;
        margin-left:.5in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        color:black;}
span.EmailStyle18
        {mso-style-type:personal;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:Consolas;
        color:black;}
span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:962612654;
        mso-list-type:hybrid;
        mso-list-template-ids:-1018915426 67698689 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;}
@list l0:level1
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:38.25pt;
        text-indent:-.25in;
        font-family:Symbol;}
@list l0:level2
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:74.25pt;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l0:level3
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:110.25pt;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l0:level4
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:146.25pt;
        text-indent:-.25in;
        font-family:Symbol;}
@list l0:level5
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:182.25pt;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l0:level6
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:218.25pt;
        text-indent:-.25in;
        font-family:Wingdings;}
@list l0:level7
        {mso-level-number-format:bullet;
        mso-level-text:\F0B7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:254.25pt;
        text-indent:-.25in;
        font-family:Symbol;}
@list l0:level8
        {mso-level-number-format:bullet;
        mso-level-text:o;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:290.25pt;
        text-indent:-.25in;
        font-family:"Courier New";}
@list l0:level9
        {mso-level-number-format:bullet;
        mso-level-text:\F0A7;
        mso-level-tab-stop:none;
        mso-level-number-position:left;
        margin-left:326.25pt;
        text-indent:-.25in;
        font-family:Wingdings;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body bgcolor="white" lang="EN-US" link="#0563C1" vlink="#954F72">
<div class="WordSection1">
<p class="MsoNormal"><span style="color:#1F497D">Thanks for the quick and useful response.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Increasing the package memory seems like a simple and safe thing to do. Also, we are indeed planning to upgrade soon.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Regarding 'mem_join', based on the documentation, I assume we will have to compile with MEM_JOIN_FREE in order for it to work. Is that correct?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">We are still hoping to be able to reproduce this issue in our dev environment, so that we can prove our changes are helping. Can anyone think of a way we might be able to intentionally cause some memory fragmentation?
 Is there a particular type of access pattern, or a series of operations we can repeat many times to induce fragmentation?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">We’ve been running heavy SIPp load tests for many days which exercise the following:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">-Registration<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">-Subscription to large RLS contact lists<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">-Subscription to presence of many contacts<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">So far, we haven't been able to reproduce.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D">Thanks again.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="color:#1F497D"><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="color:windowtext">From:</span></b><span style="color:windowtext"> Daniel-Constantin Mierla [mailto:miconda@gmail.com]
<br>
<b>Sent:</b> Wednesday, September 18, 2019 11:32 PM<br>
<b>To:</b> Kamailio (SER) - Users Mailing List <sr-users@lists.kamailio.org>; Cody Herzog <CHerzog@IntouchHealth.com><br>
<b>Subject:</b> Re: [SR-Users] qm_find_free() Free fragment not found, called from xcap_server, no more pkg<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p>Hello,<span style="font-size:12.0pt"><o:p></o:p></span></p>
<p>first, I would recommend to upgrade to the latest version in v5.1.x series, the 5.1.0 was the first there and there were many issues fixed in the 5.1 branch that will ensure smoother run in long term.<o:p></o:p></p>
<p>The issue reported is likely related to fragmentation, try to set global parameter:<o:p></o:p></p>
<p>mem_join=1<o:p></o:p></p>
<p>As the instance needs to deal with large chunks for xcap documents, I would also suggest to increase a bit the pool of pkg memory via -M command line parameter -- I see that now is 8MB, make it 12 or 16.<o:p></o:p></p>
<p>Cheers,<br>
Daniel<o:p></o:p></p>
<div>
<p class="MsoNormal">On 19.09.19 01:07, Cody Herzog wrote:<o:p></o:p></p>
</div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">Hello.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Recently, for the first time, we experienced an apparent memory issue in our production environment. Here's an example of the relevant log messages:<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Sep 13 18:55:22 SIPCOMM /usr/local/sbin/kamailio[2302]: ERROR: <core> [core/mem/q_malloc.c:286]: qm_find_free(): qm_find_free(0x7fd8bbcfc010, 134648); Free fragment not found!<o:p></o:p></p>
<p class="MsoNormal">Sep 13 18:55:22 SIPCOMM /usr/local/sbin/kamailio[2302]: ERROR: <core> [core/mem/q_malloc.c:419]: qm_malloc(): qm_malloc(0x7fd8bbcfc010, 134648) called from xcap_server: xcap_server.c: ki_xcaps_put(549), module: xcap_server; Free fragment
 not found!<o:p></o:p></p>
<p class="MsoNormal">Sep 13 18:55:22 SIPCOMM /usr/local/sbin/kamailio[2302]: ERROR: xcap_server [xcap_server.c:552]: ki_xcaps_put(): no more pkg<o:p></o:p></p>
<p class="MsoNormal">Sep 13 18:55:22 SIPCOMM /usr/local/sbin/kamailio[2252]: ERROR: app_perl [kamailioxs.xs:487]: XS_Kamailio_log(): 500 Server error<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">The failed operation was the XCAP server module trying to generate a very large RLS contact list for a user. The issue only impacted users with very large lists, as though a large contiguous block of memory could not be found, whereas other
 smaller allocations continued to work fine. We believe the requested allocation was around 112 KB in size.<o:p></o:p></p>
<p class="MsoNormal">The server had been up for 14 days. We were able to work around the issue temporarily by just restarting the Kamailio service. It's unusual, because our production server is often up for months, and we've never seen this issue before. The
 load on production is increasing slowly due to an increased concurrent user count, so that might be related.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Before restarting the service on production, we captured the output of the following commands:<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">kamctl stats shmem<o:p></o:p></p>
<p class="MsoNormal">kamcmd mod.stats all shm<o:p></o:p></p>
<p class="MsoNormal">kamcmd pkg.stats<o:p></o:p></p>
<p class="MsoNormal">kamcmd mod.stats all pkg<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Here's the shared mem output:<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">{<o:p></o:p></p>
<p class="MsoNormal">  "jsonrpc":  "2.0",<o:p></o:p></p>
<p class="MsoNormal">  "result": [<o:p></o:p></p>
<p class="MsoNormal">    "shmem:fragments = 27240",<o:p></o:p></p>
<p class="MsoNormal">    "shmem:free_size = 447203296",<o:p></o:p></p>
<p class="MsoNormal">    "shmem:max_used_size = 116175576",<o:p></o:p></p>
<p class="MsoNormal">    "shmem:real_used_size = 89667616",<o:p></o:p></p>
<p class="MsoNormal">    "shmem:total_size = 536870912",<o:p></o:p></p>
<p class="MsoNormal">    "shmem:used_size = 68824240"<o:p></o:p></p>
<p class="MsoNormal">  ],<o:p></o:p></p>
<p class="MsoNormal">  "id": 6934<o:p></o:p></p>
<p class="MsoNormal">}<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Here's the pkg output for the particular PID which was throwing the errors:<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">{<o:p></o:p></p>
<p class="MsoNormal">                entry: 34<o:p></o:p></p>
<p class="MsoNormal">                pid: 2302<o:p></o:p></p>
<p class="MsoNormal">                rank: 14<o:p></o:p></p>
<p class="MsoNormal">                used: 2415864<o:p></o:p></p>
<p class="MsoNormal">                free: 4949688<o:p></o:p></p>
<p class="MsoNormal">                real_used: 3438920<o:p></o:p></p>
<p class="MsoNormal">                total_size: 8388608<o:p></o:p></p>
<p class="MsoNormal">                total_frags: 1951<o:p></o:p></p>
<p class="MsoNormal">}<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">We didn't see anything obvious in the stats output which explains the issue.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">We've been trying to reproduce the issue in a dev environment using simulated higher than production load running for many days, but so far we've had no luck. We've been monitoring memory stats over time, but we don't see any obvious leaks
 or issues.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">We've searched various past threads, but didn't find any obvious answers. Here are some of the documents and the threads we've been reading:<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal"><a href="https://www.kamailio.org/wiki/tutorials/troubleshooting/memory">https://www.kamailio.org/wiki/tutorials/troubleshooting/memory</a><o:p></o:p></p>
<p class="MsoNormal"><a href="https://www.kamailio.org/wiki/cookbooks/3.3.x/core#mem_join">https://www.kamailio.org/wiki/cookbooks/3.3.x/core#mem_join</a><o:p></o:p></p>
<p class="MsoNormal"><a href="https://sr-users.sip-router.narkive.com/3TEDs3ga/tcp-free-fragment-not-found">https://sr-users.sip-router.narkive.com/3TEDs3ga/tcp-free-fragment-not-found</a><o:p></o:p></p>
<p class="MsoNormal"><a href="https://lists.kamailio.org/pipermail/sr-users/2012-June/073552.html">https://lists.kamailio.org/pipermail/sr-users/2012-June/073552.html</a><o:p></o:p></p>
<p class="MsoNormal"><a href="https://lists.kamailio.org/pipermail/sr-users/2017-February/096132.html">https://lists.kamailio.org/pipermail/sr-users/2017-February/096132.html</a><o:p></o:p></p>
<p class="MsoNormal"><a href="https://lists.kamailio.org/pipermail/sr-users/2017-September/098607.html">https://lists.kamailio.org/pipermail/sr-users/2017-September/098607.html</a><o:p></o:p></p>
<p class="MsoNormal"><a href="https://github.com/kamailio/kamailio/issues/1001">https://github.com/kamailio/kamailio/issues/1001</a><o:p></o:p></p>
<p class="MsoNormal"><a href="https://lists.kamailio.org/pipermail/sr-users/2016-April/092592.html">https://lists.kamailio.org/pipermail/sr-users/2016-April/092592.html</a><o:p></o:p></p>
<p class="MsoNormal"><a href="https://lists.kamailio.org/pipermail/sr-users/2010-July/064832.html">https://lists.kamailio.org/pipermail/sr-users/2010-July/064832.html</a><o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Regarding our Kamailio version and build options, here's the output of 'kamailio -v':<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">----<o:p></o:p></p>
<p class="MsoNormal">version: kamailio 5.1.0 (x86_64/linux)<o:p></o:p></p>
<p class="MsoNormal">flags: STATS: Off, USE_TCP, USE_TLS, USE_SCTP, TLS_HOOKS, DISABLE_NAGLE, USE_MCAST, DNS_IP_HACK, SHM_MEM, SHM_MMAP, PKG_MALLOC, Q_MALLOC, F_MALLOC, TLSF_MALLOC, DBG_SR_MEMORY, USE_FUTEX, FAST_LOCK-ADAPTIVE_WAIT, USE_DNS_CACHE, USE_DNS_FAILOVER,
 USE_NAPTR, USE_DST_BLACKLIST, HAVE_RESOLV_RES<o:p></o:p></p>
<p class="MsoNormal">ADAPTIVE_WAIT_LOOPS=1024, MAX_RECV_BUFFER_SIZE 262144, MAX_LISTEN 16, MAX_URI_SIZE 1024, BUF_SIZE 65535, DEFAULT PKG_SIZE 8MB<o:p></o:p></p>
<p class="MsoNormal">poll method support: poll, epoll_lt, epoll_et, sigio_rt, select.<o:p></o:p></p>
<p class="MsoNormal">id: unknown<o:p></o:p></p>
<p class="MsoNormal">compiled on 20:07:31 Jan  4 2018 with gcc 5.4.0<o:p></o:p></p>
<p class="MsoNormal">----<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">We are running on a 64-bit Ubuntu Server virtual machine.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Any help would be greatly appreciated.<o:p></o:p></p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal">Thanks very much.<o:p></o:p></p>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman",serif"><br>
<br>
<o:p></o:p></span></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>Kamailio (SER) - Users Mailing List<o:p></o:p></pre>
<pre><a href="mailto:sr-users@lists.kamailio.org">sr-users@lists.kamailio.org</a><o:p></o:p></pre>
<pre><a href="https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users">https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-users</a><o:p></o:p></pre>
</blockquote>
<pre>-- <o:p></o:p></pre>
<pre>Daniel-Constantin Mierla -- <a href="http://www.asipto.com">www.asipto.com</a><o:p></o:p></pre>
<pre><a href="http://www.twitter.com/miconda">www.twitter.com/miconda</a> -- <a href="http://www.linkedin.com/in/miconda">www.linkedin.com/in/miconda</a><o:p></o:p></pre>
<pre>Kamailio Advanced Training, Oct 21-23, 2019, Berlin, Germany -- <a href="https://asipto.com/u/kat">https://asipto.com/u/kat</a><o:p></o:p></pre>
</div>
</body>
</html>