mailing list of musl libc
 help / color / mirror / code / Atom feed
From: "zhangwentao (M)" <zhangwentao234@huawei.com>
To: "musl@lists.openwall.com" <musl@lists.openwall.com>
Cc: "Jianing (OS-LAB)" <ning.jia@huawei.com>,
	"Huangqiang (H)" <h.huangqiang@huawei.com>,
	leijitang <leijitang@huawei.com>,
	wanghaozhan <wanghaozhan2@huawei.com>
Subject: 答复: [musl] musl: about malloc 'expand heap' issue
Date: Wed, 31 Oct 2018 01:19:11 +0000	[thread overview]
Message-ID: <D53ADE21CD59B0478DFBD751B7B6F4711F2374A1@dggeml530-mbx.china.huawei.com> (raw)
In-Reply-To: <20181030150039.GT5150@brightrain.aerifal.cx>

Hi

 Now we are using a global lock to solve the issue. And as you said the performance maybe cost too much.
And if you have solution about this and the fix is not that expensive, that's great.
If you finish it, would you send the patch to me ?

Thanks a lot~
From Wentao


-----邮件原件-----
发件人: Rich Felker [mailto:dalias@aerifal.cx] 代表 Rich Felker
发送时间: 2018年10月30日 23:01
收件人: musl@lists.openwall.com
主题: Re: [musl] musl: about malloc 'expand heap' issue

On Tue, Oct 30, 2018 at 11:11:07AM +0000, zhangwentao (M) wrote:
> 
> Hi all,
>   I am using musl in my project and I found an issue about the malloc function in musl:
> 
> Issue Description:
> *             When in muti-threads environment, malloc/free are called in high concurrency<http://dict.cn/high%20concurrency>.
> 
> Malloc:
>   Will find 'struct bin' from bitmap(without lock), and allocate memory from the bin (with lock).
> 
> Free:
>  Will merge the chunk together if the free memory is 'connected' to the existing chunk.
> 
> ? It will remove the old chunk first then combine the chunk to a larger one..
> 
> ? After merge operation done, insert the chunk to the bin list.
> 
> ? Each of the chunk operation is locked while merging, but the whole steps aren't within a lock.
> 
> So here is the issue:
> 
> 1.      There is only one chunk in largest bin list, and Free is on process, just remove the largest bins chunk from bin, the bitmap(mal.binmap) on that bit will be zero.
> 
> 2.      A malloc comes, the bitmap is zero, and goes to expand heap. (Actually there is enough memories in process)
> 
> 3.      Free operation goes on, and put the merged big chunk to bins.
> 
> But in operation 2, the process has expand heap.
> 
> If we have a loop on step 1-3, the process will expand heap frequently.
> So it will cost more Virtual Memory  (of course, physical memory would be freed by calling '__madvise' if the chunk is big enough)
> 
> In my environment , we do not have that much virtual memory. I think stop expand heap would a better choice.
> 
> Do you have plan to fix it ??

This is a known issue, and intended to be fixed in the complete
redesign of malloc. Fixing it right in the current design seems to
impose significant performance costs that I thought were equivalent
to, or worse than, just using one global lock. However if it's causing
major problems I may be able to make a quick fix that's not too
expensive -- I'll take a look again today or tomorrow.

Rich

  reply	other threads:[~2018-10-31  1:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-30 11:11 zhangwentao (M)
2018-10-30 15:00 ` Rich Felker
2018-10-31  1:19   ` zhangwentao (M) [this message]
2018-10-31  3:44     ` 答复: [musl] " Rich Felker
2019-04-12 22:51       ` Rich Felker

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=D53ADE21CD59B0478DFBD751B7B6F4711F2374A1@dggeml530-mbx.china.huawei.com \
    --to=zhangwentao234@huawei.com \
    --cc=h.huangqiang@huawei.com \
    --cc=leijitang@huawei.com \
    --cc=musl@lists.openwall.com \
    --cc=ning.jia@huawei.com \
    --cc=wanghaozhan2@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).