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=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 30760 invoked from network); 19 Sep 2022 13:47:14 -0000 Received: from second.openwall.net (193.110.157.125) by inbox.vuxu.org with ESMTPUTF8; 19 Sep 2022 13:47:14 -0000 Received: (qmail 13727 invoked by uid 550); 19 Sep 2022 13:47:12 -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 13707 invoked from network); 19 Sep 2022 13:47:11 -0000 Date: Mon, 19 Sep 2022 09:46:59 -0400 From: Rich Felker To: Florian Weimer Cc: baiyang , musl Message-ID: <20220919134659.GO9709@brightrain.aerifal.cx> References: <2022091915532777412615@gmail.com> <20220919110829.GA2158779@port70.net> <874jx3h76u.fsf@oldenburg.str.redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <874jx3h76u.fsf@oldenburg.str.redhat.com> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [musl] The heap memory performance (malloc/free/realloc) is significantly degraded in musl 1.2 (compared to 1.1) On Mon, Sep 19, 2022 at 02:36:41PM +0200, Florian Weimer wrote: > * Szabolcs Nagy: > > > unlike musl those implementations don't return exact size nor have the > > same security and memory fragmentation guarantees, so bad comparision. > > > > tcmalloc: > > // Returns the actual number N of bytes reserved by tcmalloc for the pointer > > // p. This number may be equal to or greater than the number of bytes > > // requested when p was allocated. > > // > > // This function is just useful for statistics collection. The client must > > // *not* read or write from the extra bytes that are indicated by this call. > > > > jemalloc: > > The malloc_usable_size() function > > returns the usable size of the allocation pointed to by > > ptr. The return value may be larger than the size > > that was requested during allocation. The > > malloc_usable_size() function is not a > > mechanism for in-place realloc(); rather > > it is provided solely as a tool for introspection purposes. Any > > discrepancy between the requested allocation size and the size reported > > by malloc_usable_size() should not be > > depended on, since such behavior is entirely implementation-dependent. > > These implementations are buggy or at least mis-documented. The > interface contract is clearly that for that particular object, the extra > bytes in the allocation are available for reading and writing. It is > not guaranteed that the allocator will always provide the same number of > extra bytes for the same requested size, but they must be there for the > allocation being examined. It's even in the name of the function! I'm not sure I understand what you're saying, but the core problem that really can't be solved is potential discrepancy between the malloc implementation's idea of usable and the compiler's. For example: char *p = malloc(1); if (malloc_usable_size(p)>1) p[1] = 42; will cause a compiler that's actively detecting UB to abort the program when malloc_usable_size returns a value larger than 1. Rich