Description

TLSF mem manager accounting for wrong values

was trying to debug a crash and this popped up.

using a lot of small allocs until pkg_alloc returns NULL (when exhausted)
when NULL is returned the memory used+overhead exceeds the heap allocated.

Troubleshooting

Reproduction

use frequent small memory allocs until pool is exausted (returns NULL) , check tlsf status.

static void do_test_mem()
{
void* chunk;
tlsf_t pool = NULL;
size_t total = 16 * 1024 * 1024;
size_t half = 8 * 1024 * 1024;
size_t sz = 6;
int x;
void* mem = malloc(total);
char* mem2 = tlsf_cast(char*, tlsf_cast(ptrdiff_t, mem) + half);
memset(mem2, 'X', half);
assert(*mem2 == 'X');
pool = tlsf_create_with_pool(mem, half);
do { chunk = tlsf_malloc(pool, sz); } while(chunk != NULL);
tlsf_status(pool);
for(x=0; x < half; x++) {
assert(*mem2 == 'X');
mem2++;
}
free(mem);
}

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|................................|

Log Messages

identical to reproduce step when calling mem debug on a running instance

Possible Solutions

Additional Information

  * **Kamailio Version** - built from master
CentOS7 and alpine

comments

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


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or unsubscribe.