From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 4641 invoked from network); 20 Sep 2022 18:13:10 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 20 Sep 2022 18:13:10 -0000 Received: (qmail 21983 invoked by uid 550); 20 Sep 2022 18:13:07 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 21960 invoked from network); 20 Sep 2022 18:13:06 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fifth.space; s=20190812; t=1663697570; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=mAN+hyNrlBfQLpgHU/xaqtlx8uFWBLbVc21JOJIJMm8=; b=FGMSllN4G8Z7F3X5uXOttE3SJyCVSaF7kCWOmdg2d6tN4Gu0TfjC7+2fkI8DJG5JOkDxYa Ux/YNC9ojEJBcfH9M60WYZ0fdHS51WvW1pG+syG6yo/h5tqLtF6NWqFZLzsueU5i/ZXDC+ vi09JUms3NlGEZYKiUJ3gpKRdFyh3Qv7cLhMbf3EbSRY/9i5nZR9HkOuuEuQ4GN0JRUSMN OdodWm3W2FxL9ac1j6pDSZKo1CFAcPyohqF9ETMsEeUk18wiT8eYg4yOCJrjm40U7+2DEr nkTLtve61RiSmFrNJ4RPsc3rgKhKLu9Z7G42ltO+YHzdTNTbxemjnl5JvJMguQ== Date: Tue, 20 Sep 2022 20:12:44 +0200 From: Quentin Rameau To: musl@lists.openwall.com Cc: "Florian Weimer" , "Rich Felker" Message-ID: <20220920201244.4f40362e.quinq@fifth.space> In-Reply-To: <2022092101393822582117@gmail.com> References: <2022091915532777412615@gmail.com> <20220919110829.GA2158779@port70.net> <874jx3h76u.fsf@oldenburg.str.redhat.com> <20220919134659.GO9709@brightrain.aerifal.cx> <874jx2phqm.fsf@oldenburg.str.redhat.com> <2022092101393822582117@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [musl] The heap memory performance (malloc/free/realloc) is significantly degraded in musl 1.2 (compared to 1.1) > This is a good thing, we noticed it before. But we actually need a reallo= c that **can specify the copy range**. >=20 > As in our previous example, suppose we "void* p malloc(200KB)" and "mallo= c_usable_size(p)" returns 256KB. For allocators such as tcmalloc, if we do = "realloc(p, 300KB)", it will actually execute "malloc(300KB)+memcpy(**256KB= **)+free(256KB)". But at this time, the actual business of the application = layer often only needs to copy a small amount of content, such as the first= 2KB of data. So what you're actually trying to do is more clear now. And this is something that you should do on the =E2=80=9Capplication layer= =E2=80=9D, not expect the libc to magically taking care of this. If your application already knows it only needs to keep back only a few amo= unt of data, do this in a wrapper, malloc(300KB), memcpy(2KB), free old mem= ory. If on the other hand it know it actually wants to reuse the same data but i= n a more vast contiguous memory, use realloc. > Therefore, it would be great if there were additional parameters to infor= m realloc to just execute malloc(300KB)+memcpy(**2KB**)+free(256KB) when de= generating back to malloc+memcpy+free. That's what your wrapper would be.