From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from beige.elm.relay.mailchannels.net (beige.elm.relay.mailchannels.net [23.83.212.16]) by sourceware.org (Postfix) with ESMTPS id 8CCB0385B190 for ; Mon, 28 Nov 2022 14:13:07 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8CCB0385B190 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=sourceware.org Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 2D19E8C0B4E; Mon, 28 Nov 2022 14:13:04 +0000 (UTC) Received: from pdx1-sub0-mail-a306.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id B52D88C0ED3; Mon, 28 Nov 2022 14:13:03 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1669644783; a=rsa-sha256; cv=none; b=OjH0blbjEJmDPU1iPeAfrNkAyqbgzVwul7e2urqnIrcd6r6oaZJ5sO/OTvEAVg0HxHgNgA cAQkC59SskWS4wXu/Nrw+mKcEQu2PeeoBAXVU2gNMYLMUeM1tAuBSZpNZGsW3Uhy1Yz1s2 B1NR+Rpntoj1E/yiYDSaC7j2C/AhKvHDMRoI+kFElaSTcWFfpvliWY1V/O9JtySRDj3xnf +grkONl3cSWLXlk/LAvUhbi1V9uxnfy+WmjuMHqyZ3A/u/3MzTJGa37HH0aE3NBKk8QqFd YJ7KF1jGATiIhm0BhVea9vo9o3Do/N4XlcCNvfHRNnAW2nPjcucTfdiSZOwtzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1669644783; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kozrOf/65UPHbM/gzSdnqy2thuMX/J2GWaoke/CkMnE=; b=JFN8iFqPqDy/bYDWhoTA+UCu+L1f7DDoAF5+Sy9HKEoCWK4vWEfYI2vm1lM38AdRmqkpqh 7a8BjdsFJDhxibv2fQaqGT5fGsjFXNm5qYPziR944vUzXmQeuUq7Kxg0UH9WCDOnAX88jL st1WpOumIHErOJlQHfafgOMoWjcwUpMeXFzvWNssJY+3c3DbpDA20/qsg+mSMCZsfm0+Dk pTOMuFaS6FboaoCz46aT6Lvm6RpNbg2Ac2ys6y6PrxvGsWxR8TahUtifRe7zll6FxILPaR xE7OQBmkusSPOgFAc7iW1hcnY/jxbz94GQhoB+9+2b6uM5jhSWP7poMkzorypw== ARC-Authentication-Results: i=1; rspamd-84789cff4b-fjwc5; auth=pass smtp.auth=dreamhost smtp.mailfrom=siddhesh@sourceware.org X-Sender-Id: dreamhost|x-authsender|siddhesh@gotplt.org X-MC-Relay: Neutral X-MailChannels-SenderId: dreamhost|x-authsender|siddhesh@gotplt.org X-MailChannels-Auth-Id: dreamhost X-Oafish-Blushing: 4925811e13d83897_1669644784003_3519852676 X-MC-Loop-Signature: 1669644784002:4058042638 X-MC-Ingress-Time: 1669644784002 Received: from pdx1-sub0-mail-a306.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.123.200.112 (trex/6.7.1); Mon, 28 Nov 2022 14:13:04 +0000 Received: from [192.168.0.182] (bras-base-toroon4834w-grc-23-76-68-24-147.dsl.bell.ca [76.68.24.147]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: siddhesh@gotplt.org) by pdx1-sub0-mail-a306.dreamhost.com (Postfix) with ESMTPSA id 4NLS9W0xz4z6t; Mon, 28 Nov 2022 06:13:03 -0800 (PST) Message-ID: <3cc4e7f1-fa60-edf7-c31b-a3ba34ae4eab@sourceware.org> Date: Mon, 28 Nov 2022 09:13:01 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH] realloc: Return unchanged if request is within usable size Content-Language: en-US To: Wilco Dijkstra , 'GNU C Library' References: From: Siddhesh Poyarekar In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1166.6 required=5.0 tests=BAYES_00,KAM_DMARC_NONE,KAM_DMARC_STATUS,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL,TXREP autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: 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