From: "Keith Packard" <keithp@keithp.com>
To: Maarten van der Schrieck | Things Connected
<maarten@thingsconnected.nl>,
newlib@sourceware.org
Subject: Re: [PATCH] nano malloc allocator algorithm improvement
Date: Sat, 22 Aug 2020 17:12:00 -0700 [thread overview]
Message-ID: <87pn7igqzz.fsf@keithp.com> (raw)
In-Reply-To: <87tuwugufh.fsf@keithp.com>
[-- Attachment #1: Type: text/plain, Size: 1203 bytes --]
Keith Packard via Newlib <newlib@sourceware.org> writes:
> Maarten van der Schrieck | Things Connected <maarten@thingsconnected.nl>
> 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.
I've gone ahead and added this. Because this code is shared with
realloc, the overall impact on the code size is pretty modest. I think
it's easily worth the increase in code size because it will use ram more
efficiently now.
I can back-port this code to newlib if people are interested; certainly
having people on this list review the could would be great.
https://github.com/picolibc/picolibc/blob/main/newlib/libc/stdlib/nano-mallocr.c
--
-keith
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 832 bytes --]
next prev parent reply other threads:[~2020-08-23 0:12 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-22 19:40 Maarten van der Schrieck | Things Connected
2020-08-22 22:57 ` Keith Packard
2020-08-23 0:12 ` Keith Packard [this message]
2020-08-24 10:03 ` Corinna Vinschen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87pn7igqzz.fsf@keithp.com \
--to=keithp@keithp.com \
--cc=maarten@thingsconnected.nl \
--cc=newlib@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).