Date: Mon, 19 Sep 2022 22:17:02 +0200 From: Joakim Sindholt <opensource@...sha.com> To: musl@...ts.openwall.com Subject: Re: The heap memory performance (malloc/free/realloc) is significantly degraded in musl 1.2 (compared to 1.1) On Tue, 20 Sep 2022 03:45:35 +0800, baiyang <baiyang@...il.com> wrote: > > The only correct value malloc_usable_size can return is the value you passed to the allocator. > > I don't think so, see: > > Linux man page: https://man7.org/linux/man-pages/man3/malloc_usable_size.3.html - "The value returned by malloc_usable_size() may be **greater than** the requested size of the allocation". > > Mac OS X man page: https://developer.apple.com/library/archive/documentation/System/Conceptual/ManPages_iPhoneOS/man3/malloc_size.3.html - "The memory block size is always at least as large as the allocation it backs, **and may be larger**." > > FreeBSD man page: https://www.freebsd.org/cgi/man.cgi?query=malloc_usable_size&apropos=0&sektion=0&manpath=FreeBSD+7.1-RELEASE&format=html - "The return value **may be larger** than the size that was requested during allocation". > > These official man pages clearly state that the return value of malloc_usable_size is the size of the memory block allocated internally, not the size submitted by the user. > > Instead, we didn't find any documentation saying that the return value of malloc_usable_size must be the size submitted by the user to be correct. Please correct me if you have the relevant documentation. It's not that malloc_usable_size must return the size originally submitted by the user but that if it doesn't and you take that as an invitation to exceed the original size allocated you will hit UB. Simple case: https://gcc.godbolt.org/z/5E65rr95W Real world example: https://github.com/systemd/systemd/issues/22801 And the reason why is pretty simple: http://port70.net/~nsz/c/c11/n1570.html#188.8.131.52p2 > The malloc function allocates space for an object whose size is > specified by size and whose value is indeterminate.
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.