<p></p>
<h3>Description</h3>
<p>TLSF mem manager accounting for wrong values</p>
<p>was trying to debug a crash and this popped up.</p>
<p>using a lot of small allocs until pkg_alloc returns NULL (when exhausted)<br>
when NULL is returned the memory <strong>used+overhead</strong> exceeds the heap allocated.</p>

<h3>Troubleshooting</h3>
<h4>Reproduction</h4>
<p>use frequent small memory allocs until pool is exausted (returns NULL) , check tlsf status.</p>
<p>static void do_test_mem()<br>
{<br>
void* chunk;<br>
tlsf_t pool = NULL;<br>
size_t total = 16 * 1024 * 1024;<br>
size_t half = 8 * 1024 * 1024;<br>
size_t sz = 6;<br>
int x;<br>
void* mem = malloc(total);<br>
char* mem2 = tlsf_cast(char*, tlsf_cast(ptrdiff_t, mem) + half);<br>
memset(mem2, 'X', half);<br>
assert(*mem2 == 'X');<br>
pool = tlsf_create_with_pool(mem, half);<br>
do { chunk = tlsf_malloc(pool, sz); } while(chunk != NULL);<br>
tlsf_status(pool);<br>
for(x=0; x < half; x++) {<br>
assert(*mem2 == 'X');<br>
mem2++;<br>
}<br>
free(mem);<br>
}</p>


<pre><code>heap size= **8388592**
used= **6285144**, used+overhead=**12578696**, free=**18446744073705361512**, fragments=0
max used (+overhead)=12578696, max fragments=1
Free blocks matrix ('.': none, 'X': between 2^X and (2^(X+1)-1) free blocks, X=A..Z, A=0, B=1, ...)
> first-level: 32 block list arrays between 2^fl and 2^(fl+1) bytes (fl=8..39)
v second-level: 32 block lists between 2^fl+sl*2^(fl-5) and 2^fl+(sl+1)*2^(fl-5)-1 bytes (sl=0..31)
 0|................................|
 1|................................|
 2|................................|
 3|................................|
 4|................................|
 5|................................|
 6|................................|
 7|................................|
 8|................................|
 9|................................|
10|................................|
11|................................|
12|................................|
13|................................|
14|................................|
15|................................|
16|................................|
17|................................|
18|................................|
19|................................|
20|................................|
21|................................|
22|................................|
23|................................|
24|................................|
25|................................|
26|................................|
27|................................|
28|................................|
29|................................|
30|................................|
31|................................|
</code></pre>
<h4>Log Messages</h4>

<pre><code>identical to reproduce step when calling mem debug on a running instance
</code></pre>
<h3>Possible Solutions</h3>

<h3>Additional Information</h3>
<pre><code>  * **Kamailio Version** - built from master
</code></pre>
<ul>
<li><strong>Operating System</strong>:</li>
</ul>

<pre><code>CentOS7 and alpine
</code></pre>
<h2>comments</h2>
<p>heap size= <strong>8388592</strong> shouldn't it be <strong>8388608</strong> ?<br>
used+overhead=<strong>12578696</strong> misleading<br>
free=<strong>18446744073705361512</strong> misleading, looks like it has a negative value<br>
the map doesn't look ok (or i'm not understanding what it should show), its the same output before the alloc and after.</p>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/kamailio/kamailio/issues/2628">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABO7UZLSX3FFN2MXLVZRQVLS5Z7ENANCNFSM4XHMFXHQ">unsubscribe</a>.<img src="https://github.com/notifications/beacon/ABO7UZO2EUGLJHTCUFNYSRDS5Z7ENA5CNFSM4XHMFXH2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4L633LCA.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/kamailio/kamailio/issues/2628",
"url": "https://github.com/kamailio/kamailio/issues/2628",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>