public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Wilco Dijkstra <Wilco.Dijkstra@arm.com>
To: 'GNU C Library' <libc-alpha@sourceware.org>
Cc: "siddhesh@sourceware.org" <siddhesh@sourceware.org>
Subject: [PATCH] realloc: Return unchanged if request is within usable size
Date: Mon, 28 Nov 2022 09:22:48 +0000	[thread overview]
Message-ID: <PAWPR08MB8982FB5595F28F88787A1B1D83139@PAWPR08MB8982.eurprd08.prod.outlook.com> (raw)

Hi Siddhesh,

I think the idea of having a fast path in realloc is good since it is a more standard
interface than malloc_usable_size, so improving performance for obvious cases
where we can return the original pointer makes sense. It will help badly written
code that does a realloc when growing an array 1 element at a time.

However the proposed patch will block realloc from ever releasing memory...
We do need to handle the case where the size is smaller than the usable size since
we'd still want to free the unused portion if it is a significant fraction of the total size.
Note the mmap code always tries to remap before checking the new size is smaller
than usable size - so will end up remapping even if you downsize by one page.

Cheers,
Wilco

             reply	other threads:[~2022-11-28  9:22 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-28  9:22 Wilco Dijkstra [this message]
2022-11-28 14:13 ` Siddhesh Poyarekar
2022-12-06 12:45   ` Wilco Dijkstra
2022-12-06 18:41     ` Siddhesh Poyarekar
2023-07-03 22:02     ` Aurelien Jarno
2023-07-04 11:17       ` Siddhesh Poyarekar
2023-07-04 16:08         ` Aurelien Jarno
  -- strict thread matches above, loose matches on Subject: below --
2022-11-25 20:09 Siddhesh Poyarekar
2022-11-25 20:40 ` Andreas Schwab
2022-11-28 14:23   ` Siddhesh Poyarekar
2022-11-28 14:29     ` Andreas Schwab

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=PAWPR08MB8982FB5595F28F88787A1B1D83139@PAWPR08MB8982.eurprd08.prod.outlook.com \
    --to=wilco.dijkstra@arm.com \
    --cc=libc-alpha@sourceware.org \
    --cc=siddhesh@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).