Best Regards BaiYang baiyang@gmail.com http://i.baiy.cn |
From: Rich FelkerDate: 2022-09-20 02:15To: baiyangCC: muslSubject: Re: Re: [musl] The heap memory performance (malloc/free/realloc) is significantly degraded in musl 1.2 (compared to 1.1)On Tue, Sep 20, 2022 at 01:32:31AM +0800, baiyang wrote:> Hi Rich,>> Thanks for your reply.>> > Unless you have an application that's explicitly using> > malloc_usable_size all over the place, it's highly unlikely that this> > is the cause of your real-world performance problems.>> 1. Yes, we have a real scenario where `malloc_usable_size` is called> frequently: we need to optimize the realloc experience. We add an> extra parameter to realloc - minimalCopyBytes: it represents the> actual size of data that needs to be copied after fallback to> malloc-copy-free mode. We will judge whether to call realloc or> complete malloc-memcpy-free by ourself based on factors such as the> size of the data that realloc needs to copy (obtained through> `malloc_usable_size`), the size that we actually need to copy when> we doing malloc-memcpy-free ourself (minimalCopyBytes) and the> chance of merging chunks (small blocks) or mremap (large blocks) in> the underlayer realloc. So, this is a real scenario, we need to call> `malloc_usable_size` frequently.Is there a reason you're relying on an unreliable and nonstandardfunction (malloc_usable_size) to do this rather than your programkeeping track of its own knowledge of the allocated size? This is whatthe C language expects you to do. For example if you have a structurethat contains a pointer to a dynamically sized buffer, normally youstore the size in a size_t member right next to that pointer, allowingyou to make these kind of decisions without having to probe anything.> 2. As I mentioned before, this isn't just a problem with> `malloc_usable_size`, since we actually include a full> `malloc_usable_size` procedure in both `realloc` and `free`, it> actually slows down The speed of other calls such as `free` and> `realloc`. So this problem actually slows down not only the> `malloc_usable_size` call itself, but also the realloc and free> calls.If this is affecting you too, that's a separate issue. But I can'ttell from what you've reported so far whether you're just claimingthis on a theoretical basis or whether you're actually experiencingunacceptable performance.