public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Siddhesh Poyarekar <siddhesh@sourceware.org>
To: Wilco Dijkstra <Wilco.Dijkstra@arm.com>,
	'GNU C Library' <libc-alpha@sourceware.org>
Subject: Re: [PATCH] realloc: Return unchanged if request is within usable size
Date: Mon, 28 Nov 2022 09:13:01 -0500	[thread overview]
Message-ID: <3cc4e7f1-fa60-edf7-c31b-a3ba34ae4eab@sourceware.org> (raw)
In-Reply-To: <PAWPR08MB8982FB5595F28F88787A1B1D83139@PAWPR08MB8982.eurprd08.prod.outlook.com>

On 2022-11-28 04:22, Wilco Dijkstra wrote:
> 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...

Thanks for pointing that out, I missed it.

> 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.

I'll make this a function of trim_threshold so that the reuse happens 
only if the difference between the request and usable size is less than 
the trim_threshold.

> 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.

I don't see that; I've put the musable check before the 
chunk_is_mmapped() check.  What am I missing?

Thanks,
Sid

  reply	other threads:[~2022-11-28 14:13 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-28  9:22 Wilco Dijkstra
2022-11-28 14:13 ` Siddhesh Poyarekar [this message]
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=3cc4e7f1-fa60-edf7-c31b-a3ba34ae4eab@sourceware.org \
    --to=siddhesh@sourceware.org \
    --cc=Wilco.Dijkstra@arm.com \
    --cc=libc-alpha@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).