From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/8487 Path: news.gmane.org!not-for-mail From: Yuxin Ren Newsgroups: gmane.linux.lib.musl.general Subject: confusion about brk and mmap in expand_heap in malloc implementation Date: Thu, 10 Sep 2015 14:58:33 -0400 Message-ID: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a11c3d2bc8ff61b051f692f13 X-Trace: ger.gmane.org 1441911553 2850 80.91.229.3 (10 Sep 2015 18:59:13 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 10 Sep 2015 18:59:13 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-8499-gllmg-musl=m.gmane.org@lists.openwall.com Thu Sep 10 20:59:13 2015 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1Za73i-0005Lr-72 for gllmg-musl@m.gmane.org; Thu, 10 Sep 2015 20:58:58 +0200 Original-Received: (qmail 16331 invoked by uid 550); 10 Sep 2015 18:58:50 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Original-Received: (qmail 16187 invoked from network); 10 Sep 2015 18:58:44 -0000 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:date:message-id:subject:from:to :content-type; bh=2v+nUub5Bb9I+mdgbg40kTebu5rAWZyhfqSZrh3cw2I=; b=ZDzE3U2RbOy979K43dZzMVjKvHMRYaaVNKagWnwrdPhK1iQ8nyRNQ8V1HPouBePl1g 4p6FM28R9JKReJzu9hCJdDax9jpLcqihn1KYVPe5wwHlkLI94eXQC2pJwf1cEFDmyqlN Z/e2krsp/+MbEBdKf3StNJWomXWE3OBuEwCNgW3kqOs7wQcC0pEU6Ulmo8tvbpCf4XxD poOE9uvtZjKpY/qnewEXUlHLKOKCsWU53/cbqnyFcEYWxs2H0F1pPFcmwehB4EvTiyXf dFnSkq5STJqDu7HREoxW4nO5LzszLoA1rsnlFkehPXcHa8/tX1HqXVxQnzI73KfGIXxq N5Ig== X-Gm-Message-State: ALoCoQkC+/XVaRduak7sJlJKWe5nxAIO+dAsNNtC/eymhdAsvpPu7t/NtBuFPDB1gQ81ebLC8snq X-Received: by 10.112.234.165 with SMTP id uf5mr36982315lbc.91.1441911513537; Thu, 10 Sep 2015 11:58:33 -0700 (PDT) Xref: news.gmane.org gmane.linux.lib.musl.general:8487 Archived-At: --001a11c3d2bc8ff61b051f692f13 Content-Type: text/plain; charset=UTF-8 Hi, I found in the __expand_heap function used by malloc, if brk fails, it will use mmap to get a memory area. I think in this case, this area should be returned back to system via munmap. But in my test, when I free such area, I found it is still passed to madvise, not munmap. How do we track if an area is expanded by brk or mmap? And when we free an area, how do we decide to use munmap or madvise? Thanks a lot. Yuxin --001a11c3d2bc8ff61b051f692f13 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi,
I found in the=C2=A0__expand_heap function used by malloc, if brk fa= ils, it will use mmap to get a memory area.
I think in this case, this area should be returned back to syst= em via munmap.
But in my test, w= hen I free such area, I found it is still passed to madvise, not munmap.

How do we track if an area is expanded by brk or mmap?=
And when we free an area, how do we de= cide to use munmap or madvise?
<= br>
Thanks a lot.
Yuxin --001a11c3d2bc8ff61b051f692f13--