The only reason why it is tough for us to use nano malloc is because of the small shortcoming where nano_malloc() splits a bigger chunk from the free list into two pieces while handing back the second one (the tail) to the user. This is error prone and especially bad for smaller heaps, where nano malloc is supposed to be superior. The normal malloc doesn't have this issue and we need to use it even though it costs us ~2k bytes compared to nano-malloc. The problem arise especially after giving back _every_ malloced memory to the heap and then starting to exercise the heap again by allocating something small. This small item might split the whole heap in two equally big parts depending on how the heap has been exercised before. I have uploaded the smallest possible application (only tested on ST and Nordic devices) to show the issue while the real customer applications are far more complicated: https://drive.google.com/file/d/1kfSC2KOm3Os3mI7EBd-U0j63qVs8xMbt/view?usp=sharing The application works like the following pseudo code, where we assume a heap of 100 bytes (I haven't taken padding and other nitty and gritty details into account. Everything to simplify understanding): void *ptr = malloc(52); // We get 52 bytes and we have // 48 bytes to use. free(ptr); // Hand back the 52 bytes to nano_malloc // This is the magic line that shows the issue of // nano_malloc ptr = malloc(1); // Nano malloc will split the 52 bytes // in the free list and hand you a pointer // somewhere in the // middle of the heap. ptr2 = malloc(52); // Out of memory... I have done a fix which hands back the first part of the splitted chunk. Once this is fixed we obviously have the 1 byte placed in position 0 of the heap instead of somewhere in the middle. However, this won't let us malloc 52 new bytes even though we potentially have 99 bytes left to use in the heap. The reason is that when we try to do the allocation, nano-malloc looks into the free list and sees a 51 byte chunk to be used. This is not big enough so nano-malloc decides to call sbrk for _another_ 52 bytes which is not possible since there is only 48 bytes left to ask for. The solution for this problem is to check if the last item in the free list is adjacent to sbrk(0). If it is, as it is in this case, we can just ask sbrk for the remainder of what is needed. In this case 1 byte. NB! I have only tested the solution on our ST device. |
||
---|---|---|
.github/workflows | ||
config | ||
etc | ||
include | ||
libgloss | ||
newlib | ||
texinfo | ||
winsup | ||
.appveyor.yml | ||
.gitattributes | ||
.gitignore | ||
COPYING | ||
COPYING.LIB | ||
COPYING.LIBGLOSS | ||
COPYING.NEWLIB | ||
COPYING3 | ||
COPYING3.LIB | ||
ChangeLog | ||
MAINTAINERS | ||
Makefile.def | ||
Makefile.in | ||
Makefile.tpl | ||
README | ||
README-maintainer-mode | ||
compile | ||
config-ml.in | ||
config.guess | ||
config.rpath | ||
config.sub | ||
configure | ||
configure.ac | ||
depcomp | ||
djunpack.bat | ||
install-sh | ||
libtool.m4 | ||
ltgcc.m4 | ||
ltmain.sh | ||
ltoptions.m4 | ||
ltsugar.m4 | ||
ltversion.m4 | ||
lt~obsolete.m4 | ||
makefile.vms | ||
missing | ||
mkdep | ||
mkinstalldirs | ||
move-if-change | ||
setup.com | ||
src-release | ||
symlink-tree | ||
ylwrap |
README
README for GNU development tools This directory contains various GNU compilers, assemblers, linkers, debuggers, etc., plus their support routines, definitions, and documentation. If you are receiving this as part of a GDB release, see the file gdb/README. If with a binutils release, see binutils/README; if with a libg++ release, see libg++/README, etc. That'll give you info about this package -- supported targets, how to use it, how to report bugs, etc. It is now possible to automatically configure and build a variety of tools with one command. To build all of the tools contained herein, run the ``configure'' script here, e.g.: ./configure make To install them (by default in /usr/local/bin, /usr/local/lib, etc), then do: make install (If the configure script can't determine your type of computer, give it the name as an argument, for instance ``./configure sun4''. You can use the script ``config.sub'' to test whether a name is recognized; if it is, config.sub translates it to a triplet specifying CPU, vendor, and OS.) If you have more than one compiler on your system, it is often best to explicitly set CC in the environment before running configure, and to also set CC when running make. For example (assuming sh/bash/ksh): CC=gcc ./configure make A similar example using csh: setenv CC gcc ./configure make Much of the code and documentation enclosed is copyright by the Free Software Foundation, Inc. See the file COPYING or COPYING.LIB in the various directories, for a description of the GNU General Public License terms under which you can copy the files. REPORTING BUGS: Again, see gdb/README, binutils/README, etc., for info on where and how to report problems.