heap migration

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
NaFi_2915566
Level 3
Level 3
First like received First like given

I am chasing down a heap issue and I am confused about the heap structure.

In the makefile, I am setting PLATFORM_HEAP_SIZE=256*1024.  We have some large JSON structures and when we convert them to strings they can get over 100k characters.

When I print heap information using the example from command_console_mallinfo.c, I get the following

malloc_info {

                arena:                   31000;   /* total space allocated from system */

                ordblks: 4;        /* number of non-inuse chunks */

                smblks:                     0;        /* unused -- always zero */

                hblks:       0;        /* number of mmapped regions */

                hblkhd:                     0;        /* total space in mmapped regions */

                usmblks: 0;        /* unused -- always zero */

                fsmblks: 0;        /* unused -- always zero */

                uordblks:             26512;   /* total allocated space */

                fordblks:              4488;    /* total non-inuse space */

                keepcost:            2048;    /* top-most, releasable (via malloc_trim) space */

};

******Mallinfo summary******

Total heap size: 31000 bytes

Memory in use: 26512 bytes

sbrk heap start: 0x004F76E8; size:    1739024

sbrk current free: 1708024

Total free memory: 1712512

******Mallinfo END******

I do not see a 256kB stack anywhere; it looks like the "total area" is 31000 bytes. In fact I am not sure what the difference between arena, heap and sbrk heap are.  I could not find this in the SDK documentation.

I some later point, the heap info looks like this and all malloc() calls are failing:

sbrk heap size: 1739024

sbrk current free: 4088

malloc arena: 1734936

malloc allocated: 395672

malloc free: 1339264

Total free memory: 1343352

It looks like the memory has migrated from one heap to another, and malloc() is failing because there is very little memory left in the heap.

  1. Do you know what could cause this heap migration?  We are using the cJSON library very heavily during these logs.
  2. How do I ensure there is ample heap available for the large JSON strings?
0 Likes
1 Solution
Zhengbao_Zhang
Moderator
Moderator
Moderator
250 sign-ins First comment on KBA 10 questions asked

captured the heap info from 43907,  we have enough free memory with the value 1550064 .

> malloc_info

malloc_info {

arena:          37112;  /* total space allocated from system */

ordblks:            6;  /* number of non-inuse chunks */

smblks:             0;  /* unused -- always zero */

hblks:              0;  /* number of mmapped regions */

hblkhd:             0;  /* total space in mmapped regions */

usmblks:            0;  /* unused -- always zero */

fsmblks:            0;  /* unused -- always zero */

uordblks:       18944;  /* total allocated space */

fordblks:       18168;  /* total non-inuse space */

keepcost:        1840;  /* top-most, releasable (via malloc_trim) space */

};

******Mallinfo summary******

Total heap size: 37112 bytes

Memory in use: 18944 bytes

>

>

> heap_info

sbrk heap size:    1569008

sbrk current free: 1531896

malloc arena: 37112

malloc allocated: 18944

malloc free: 18168

Total free memory: 1550064

View solution in original post

2 Replies
Zhengbao_Zhang
Moderator
Moderator
Moderator
250 sign-ins First comment on KBA 10 questions asked

hello:

which chip are you using now?  I can have a try on my evb also.

0 Likes
Zhengbao_Zhang
Moderator
Moderator
Moderator
250 sign-ins First comment on KBA 10 questions asked

captured the heap info from 43907,  we have enough free memory with the value 1550064 .

> malloc_info

malloc_info {

arena:          37112;  /* total space allocated from system */

ordblks:            6;  /* number of non-inuse chunks */

smblks:             0;  /* unused -- always zero */

hblks:              0;  /* number of mmapped regions */

hblkhd:             0;  /* total space in mmapped regions */

usmblks:            0;  /* unused -- always zero */

fsmblks:            0;  /* unused -- always zero */

uordblks:       18944;  /* total allocated space */

fordblks:       18168;  /* total non-inuse space */

keepcost:        1840;  /* top-most, releasable (via malloc_trim) space */

};

******Mallinfo summary******

Total heap size: 37112 bytes

Memory in use: 18944 bytes

>

>

> heap_info

sbrk heap size:    1569008

sbrk current free: 1531896

malloc arena: 37112

malloc allocated: 18944

malloc free: 18168

Total free memory: 1550064