From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12982 Path: news.gmane.org!.POSTED!not-for-mail From: ritesh sonawane Newsgroups: gmane.linux.lib.musl.general Subject: Re: Changing MMAP_THRESHOLD in malloc() implementation. Date: Wed, 4 Jul 2018 10:54:50 +0530 Message-ID: References: <20180703144331.GL1392@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary="0000000000005dc22a057025a6de" X-Trace: blaine.gmane.org 1530681781 19858 195.159.176.226 (4 Jul 2018 05:23:01 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 4 Jul 2018 05:23:01 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-12998-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jul 04 07:22:57 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1faaFk-000550-TL for gllmg-musl@m.gmane.org; Wed, 04 Jul 2018 07:22:57 +0200 Original-Received: (qmail 27977 invoked by uid 550); 4 Jul 2018 05:25:04 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 27946 invoked from network); 4 Jul 2018 05:25:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=RYbOOaWZb72QkiIJm1LP5H+2frC6quRA4v30e4K50q8=; b=taddGG/zTzLsrgqPg8XvJJKyVKNiB/pYjyMqehf9Di7Fbb2MpWtqRqNZdLyZ0D9kdG I/PC2Ux+8bb72U9ACUnhtnC8iDHSl+PBWTdmf4Hqra7fX6SMULI6IzPifeYTPHQvVQGe jG8vqpspToo4OZCP457LI/JLOVafxdav1bDbLM6Jw1OMsg/vRo0eHwAIKKtnC3MSNzaM YWwhbZjo3kODQxahMM8KKgGrXFrGQapxxzEITPumtAsD69MOFrDxU8TR8Q/iAtp1giOV nQeDxs0uctLU0uQQE0KtcVni0e7YGMK3O3du+RlJNyaRuvu3evwiQBiIz4oBiAgOsyQT 2Glg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=RYbOOaWZb72QkiIJm1LP5H+2frC6quRA4v30e4K50q8=; b=gEgp8RXk7r3hFPCl1oaDJxdFLtH0Y8Qp3i8X7bFr3mFpn74U7CX5SDtVl4QFS8xqIy 2+bVp5dXqvlPX9bGm5FeCHoTOR+y+tY0RXv6toNrWIk3Kv+dCd4iGEja9HD71iKOuTMF nR0cjYjTX7IOCJ0Zv/rwOYf5en4NYBfSd1GoKQWwj+ALSViA9D01bb6jIICC1SGkCBfk 6mrBf//+oW6v2ukif6cd4ADkIVI2mnMy+XjqYdl9FYHlsUF/ZwlKZ0mVH4vO97lkY/Db Hcrbd5jZEhQl0uKKBOi8LmFk3GkRbGd5xRzNI4QuoiIi6NfHDX9u1rYKNAUJgCD7QTMN 6tPg== X-Gm-Message-State: AOUpUlFqYVDXQ34q8HATbdz39DQWH98RXIngNXKaoQfrtRorYnv05Yeh ro3vA0qaC4Iek5+7zNgpFE9Eb2vtoa2EIFgUhXqBTA== X-Google-Smtp-Source: AAOMgpc8qDxnnMT5Pr2IUFNJ9gGx8uKGgagNN3iOdHvnppbSrYH9EWScqbkj76zZMs2qRGcszhKan6HEA4TltUiCwOg= X-Received: by 2002:a6b:5503:: with SMTP id j3-v6mr384247iob.96.1530681890815; Tue, 03 Jul 2018 22:24:50 -0700 (PDT) In-Reply-To: <20180703144331.GL1392@brightrain.aerifal.cx> Xref: news.gmane.org gmane.linux.lib.musl.general:12982 Archived-At: --0000000000005dc22a057025a6de Content-Type: text/plain; charset="UTF-8" Thank you very much for instant reply.. Yes sir it is wasting memory for each shared library. But memory wastage even worse when program requesting memory with size more than 224KB(threshold value). ->If a program requests 1GB per request, it can use 45GB at the most. ->If a program requests 512MB per request, it can use 41.5GB at the most. ->If a program requests 225KB per request, it can use about 167MB at the most. As we ported musl-1.1.14 for our architecture, we are bounded to make change in same base code. we have increased MMAP_THRESHOLD to 1GB and also changes the calculation for bin index . after that observed improvement in memory utilization. i.e for size 225KB memory used is 47.6 GB. But now facing problem in multi threaded application. As we haven't changed the function pretrim() because there are some hard coded values like '40' and '3' used and unable to understand how these values are decided ..? static int pretrim(struct chunk *self, size_t n, int i, int j) { size_t n1; struct chunk *next, *split; /* We cannot pretrim if it would require re-binning. */ if (j < 40) return 0; if (j < i+3) { if (j != 63) return 0; n1 = CHUNK_SIZE(self); if (n1-n <= MMAP_THRESHOLD) return 0; } else { n1 = CHUNK_SIZE(self); } ..... ..... ...... } can we get any clue how these value are decided, it will be very helpful for us. Best Regard, Ritesh Sonawane On Tue, Jul 3, 2018 at 8:13 PM, Rich Felker wrote: > On Tue, Jul 03, 2018 at 12:58:04PM +0530, ritesh sonawane wrote: > > Hi All, > > > > We are using musl-1.1.14 version for our architecture. It is having page > > size of 2MB. > > Due to low threshold value there is more memory wastage. So we want to > > change the value of MMAP_THRESHOLD. > > > > can anyone please giude us, which factor need to consider to change this > > threshold value ? > > It's not a parameter that can be changed but linked to the scale of > bin sizes. There is no framework to track and reuse freed chunks which > are larger than MMAP_THRESHOLD, so you'd be replacing recoverable > waste from page granularity with unrecoverable waste from inability to > reuse these larger freed chunks except breaking them up into pieces to > satisfy smaller requests. > > I may look into handling this better when replacing musl's malloc at > some point, but if your system forces you to use ridiculously large > pages like 2MB, you've basically committed to wasting huge amounts of > memory anyway (at least 2MB for each shared library in each > process)... > > With musl git-master and future releases, you have the option to link > a malloc replacement library that might be a decent solution to your > problem. > > Rich > --0000000000005dc22a057025a6de Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thank you very much for instant reply..

Yes sir it is wasting memory for each shared library. But memory wastage e= ven worse when program=C2=A0
requesting memory with size more tha= n 224KB(threshold value).

->If a program reques= ts 1GB per request, it can use 45GB at the most.
->If a pr= ogram requests 512MB per request, it can use 41.5GB at the most.
= ->If a program requests 225KB per request, it can use about 167MB at the= most.

As we ported=C2=A0=C2=A0musl-1.1.14 for our= architecture, we are bounded to make change in same base code.
w= e have increased=C2=A0 MMAP_THRESHOLD to 1GB and also changes the calculation for bin index .
after that observed improv= ement in memory utilization. i.e for size 225KB memory used is 47.6 GB.

But now facing problem in multi threaded app= lication. As we haven't changed the function=C2=A0pretrim()=C2=A0
because=C2=A0there are some hard coded values like '40' a= nd '3' used and unable to understand how=C2=A0
these values are decided ..?

static int pretrim(struct chunk *self, size_t n, int i, int j= )
{
=C2=A0 =C2=A0 =C2=A0 =C2=A0 size_t n1;<= /div>
=C2=A0 =C2=A0 =C2=A0 =C2=A0 stru= ct chunk *next, *split;
<= br>
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 /* We cannot pretrim if it would require re-binning. */
=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if (j <= ; 40) return 0;
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 if (j < i+3) {
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (j= !=3D 63) return 0;
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 n1 =3D CHUNK_SIZE(self= );
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 if (n1-n <=3D MMAP_THRESHOLD) return = 0;
=C2=A0 =C2=A0 =C2=A0 = =C2=A0 } else {
=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 n1 =3D CHUNK_SIZE(self);
=C2=A0 =C2=A0 =C2=A0 =C2= =A0 }
=C2=A0.....<= /div>
=C2=A0.....
......
}

can we get any clue how these value are decided, it will be very helpfu= l=C2=A0for us.
=C2=A0
Best Regard,
Ritesh Sonawane

On Tue, Jul 3, 2018 at 8= :13 PM, Rich Felker <dalias@libc.org> wrote:
On Tue, Jul 03, 2018 at 12:58:04PM +0530,= ritesh sonawane wrote:
> Hi All,
>
> We are using musl-1.1.14 version for our architecture. It is having pa= ge
> size of 2MB.
> Due to low threshold value there is more memory wastage. So we want to=
> change the value of=C2=A0 MMAP_THRESHOLD.
>
> can anyone please giude us, which factor need to consider to change th= is
> threshold value ?

It's not a parameter that can be changed but linked to the scale= of
bin sizes. There is no framework to track and reuse freed chunks which
are larger than MMAP_THRESHOLD, so you'd be replacing recoverable
waste from page granularity with unrecoverable waste from inability to
reuse these larger freed chunks except breaking them up into pieces to
satisfy smaller requests.

I may look into handling this better when replacing musl's malloc at some point, but if your system forces you to use ridiculously large
pages like 2MB, you've basically committed to wasting huge amounts of memory anyway (at least 2MB for each shared library in each
process)...

With musl git-master and future releases, you have the option to link
a malloc replacement library that might be a decent solution to your
problem.

Rich

--0000000000005dc22a057025a6de--