Re: [PATCH] nano malloc allocator algorithm improvement

Keith Packard via Newlib <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
Maarten van der Schrieck | Things Connected <[email protected]>
writes:

> The current nano malloc implementation has two issues reducing the amount of memory available and increasing fragmentation.
>
> The first issue is that sbrk() will be called to allocate a space with
> the size of the entire requested alloc_size, even if the last free
> chunk borders the edge of currently allocated memory. This means that
> in a system with 20 kb of RAM, you will get ENOMEM when performing
> this:

Oh, that's a great idea. I did the same for realloc when the block was
at the end of the heap; doing the same for malloc is a nice
addition.

> The second issue is that a free chunk that is oversized will be cut up
> in two pieces, where the *second* piece is used for allocation and the
> first one is kept as a free chunk. Although this is easier/shorter in
> code (because the free list remains unaffected apart from the size of
> the free chunk) it leads to an inefficient pattern of memory
> allocation, and ultimately in fragmentation and slower malloc/free
> calls.

I re-worked the list management to use a different pattern that makes
this change much less invasive.

https://github.com/picolibc/picolibc/commit/fd2d18bb5ab442f16789c243648d07b4ec8e2b29

-- 
-keith
signature.asc (application/pgp-signature, 832 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCAAdFiEEw4O3eCVWE9/bQJ2R2yIaaQAAABEFAl9BovIACgkQ2yIaaQAA
ABFQwxAAqeHQyDUw73A7H7oijfaJqdl+nNsyLieYGblqaCvTb06MbGs3kWJcvkdS
UKKsGnlwkWdhx0skriD+VUPFZWwBliJLkuXrvnvSLw8jJisgfyU2j+Kcv/eISCZm
/H61bY8x4SzXKb0tyvlbOwfbbfpAsb+ScHn0BLhCDRRUAXL2Z1D0jqOreIHlOGY1
WpK3AgzyZjY8FeOW/YPFkpff+egOhcShc7qgvP45WX8V9ok0ULZxdql6l4PML1ok
Wq/ARB4/TGkjxVb12TbQj10ED9mUQ1Us9EduaGaiugx42AEmxfLmjWxIjJt0wF3m
N4FMX1gpBQPdJ9qhZcd8QHs21PYZVuOOhuJmnBffFLGSz0+b/abXYWN8QUmGf9SW
Vx8DXFlmlZezB5ha/bjrokjlZnzcr/3jzVqjhAjg2RxhJ3UvsDDaYrKTUSPZ8jDF
n80tl1T8xfAhBzTOGKMJFf/80IQGdYOV97Jvv4sEAaQiAjjtm8HWrXdPbYIC58OZ
DiTmcSoVNSXXRDdVmkrnzLXBgNRRwKQ7Pp6M6DIVUJPn1+QjVFnmjXPn7Zw7WLP4
JCKg3fzlFabdb0tsR652B6bNO/J4+V+DEqcVYG3adcgYeY8fgP7K3MPdog8Gg3vY
1Lj50HgDP6cahhcWdPrB3SMYkAEDX8zzoc/Ran7IdASt996GFI0=
=XPKd
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.