This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Finding the heap low water mark when using nRFConnect/Zephyr

I need to monitor how much heap was ever left available, as a minimum, after I have run my CI test suite.  This is the true minimum heap ever remaining, so taking account of calls to malloc() as well as to Zephyr's memory management APIs, i.e. the true underlying heap low water mark.

I could do this on NRF52 as I had the implementation of _sbrk() that FreeRTOS called into (the Dave Nadler one).

What is the equivalent in the nRFConnect/Zephyr world on NRF53?

Rob

Parents Reply
  • FYI, since newlib is being used by Zephyr under the hood (at least on NRF53) it is almost possible to do this by calling the newlib mallinfo() function. The reason this is only "almost" is that mallinfo() is not the whole story: newlib calls sbrk() as required to give it heap memory from the ultimate heap, so the real number is mallinfo's fordblks plus what's left in sbrk(): without this the reported heap can end up going UP from it's original value, a "negative leak", which would cause any strict heap checking to fail.

    Unfortunately, the variable that tracks the memory left inside sbrk(), heap_sz in lib/libc/newlib/libc-hooks.c is static so one can't get at it to do the free heap calculation properly.

    I've noted this on  https://github.com/zephyrproject-rtos/zephyr/issues/23076 and suggested that the simplest change would be to remove the static from that variable, then people can solve this problem themselves.

Children
Related