From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from black.elm.relay.mailchannels.net (black.elm.relay.mailchannels.net [23.83.212.19]) by sourceware.org (Postfix) with ESMTPS id D10DF3875B59 for ; Tue, 6 Dec 2022 18:41:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org D10DF3875B59 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 43A41641C6D; Tue, 6 Dec 2022 18:41:36 +0000 (UTC) Received: from pdx1-sub0-mail-a307.dreamhost.com (unknown [127.0.0.6]) (Authenticated sender: dreamhost) by relay.mailchannels.net (Postfix) with ESMTPA id B856E640A8A; Tue, 6 Dec 2022 18:41:35 +0000 (UTC) ARC-Seal: i=1; s=arc-2022; d=mailchannels.net; t=1670352095; a=rsa-sha256; cv=none; b=q6+z0GKXYHhtgPdOHSbp4dtQ08UbIbbWpRnJ8mVOdgwfZq2FVIlBqpxCE7eyir20zKI/fp 6J66jpqnaMHOG89RLFgbFITOQfN4qLEYV8lGWd8DM81CWSVcB4Wvd6dvrL2N8KhIjhP2eM 5JW2OZMK7yscozu9gd+HRuIlVC03cbu48ykCMA2s80bLimy8DZKA9Q3WynntUox9tsUa1d 4eLmewVjVCd6RudM1K3iMF87yNYI5NDPiFIFk+7Sbvh2kNcFX2SlmBsjQLeEgqBnFoyTVJ zTb0V9HaT3Czm91CJku8vp0FreKWWG2iJu39quuoG442ot9l+AzQihS6VbHyHg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=mailchannels.net; s=arc-2022; t=1670352095; 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=+yPdDwGMUvvy/FUk3XLNJGLtFQ9C9jPh1nCgxMpwoXA=; b=T6QPRXzEAhafs9t6Aug/IaXGzh+koxL5nPbACXjT9bcpPgvz36R4yDbnya7GAN3sd81nBC Aki3UpEcr3KS0eRJkQecav+2qto2soRIlgwIr6QhC0txaIAJ28n+SZdOWaFECFd17TSb/F cKfUmtNwP8yx2bLmdvJeHdmp+p8kmXILn7lZYLcbNMvx+dQ4xnt7YhDwHrxzS1H+6Lst73 5S6ObZqt5JslA/ld7UL3iFeIQqlvATU5H0H94vGeWiAYgueILGAbGkwa7Yv9fcMN0mlLRX QBNb0aDUZIACiG9QT1w1XgEHosX2JySj5e/YbotO4gyL9MBUbM0+UCIyx2DscA== ARC-Authentication-Results: i=1; rspamd-d48c5ddb-rjvf7; 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-Interest-Duck: 4a5443ea2c80683b_1670352096019_3568835286 X-MC-Loop-Signature: 1670352096019:195032738 X-MC-Ingress-Time: 1670352096019 Received: from pdx1-sub0-mail-a307.dreamhost.com (pop.dreamhost.com [64.90.62.162]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384) by 100.120.227.146 (trex/6.7.1); Tue, 06 Dec 2022 18:41:36 +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-a307.dreamhost.com (Postfix) with ESMTPSA id 4NRTlf5DV6zK4; Tue, 6 Dec 2022 10:41:34 -0800 (PST) Message-ID: <71b9d4d0-f8cc-b40a-ca15-6f933ffa8b08@sourceware.org> Date: Tue, 6 Dec 2022 13:41:33 -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: <3cc4e7f1-fa60-edf7-c31b-a3ba34ae4eab@sourceware.org> From: Siddhesh Poyarekar In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1165.8 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-12-06 07:45, Wilco Dijkstra wrote: > Hi Siddhesh, > >>> 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. > > That's better, but that really only helps the mmap case, and all other reallocs will > never release memory due to the 128KB default value of trim_threshold. What I'm trying to ensure here is that holes are always less than the trim threshold. > That's something we should explicitly decide/document and remove any redundant > code from realloc as a result. OK, I see the MINSIZE split is no longer relevant. >>> 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? > > I'm talking about the committed version, basically if there is any change in number of > pages it will do a system call. With your change there must be at least 128KB worth of > pages to be freed. We should do something similar for growing mmaps - large blocks > should never grow/shrink a single page at a time. Hmm, let me think about this. I reckon this is going to need more sophisticated heuristics. Thanks, Sid