From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 81695 invoked by alias); 18 Nov 2019 18:03:52 -0000 Mailing-List: contact libc-stable-help@sourceware.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Subscribe: List-Archive: Sender: libc-stable-owner@sourceware.org Received: (qmail 81685 invoked by uid 89); 18 Nov 2019 18:03:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Checked: by ClamAV 0.100.3 on sourceware.org X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,SPF_PASS autolearn=ham version=3.3.1 spammy=1978, elision X-Spam-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,KAM_SHORT,SPF_PASS autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on sourceware.org X-Spam-Level: X-HELO: aloka.lostca.se Received: from aloka.lostca.se (HELO aloka.lostca.se) (178.63.46.202) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 18 Nov 2019 18:03:50 +0000 Received: from aloka.lostca.se (aloka [127.0.0.1]) by aloka.lostca.se (Postfix) with ESMTP id 8050515E7B for ; Mon, 18 Nov 2019 18:03:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=lostca.se; h=date:from:to :subject:message-id:mime-version:content-type :content-transfer-encoding; s=howrah; bh=0lP0SCp0ZV9knBlqAbcJ2mx du/Y=; b=MhIk98EgPOodoUVTMJ4E4Ax1cgvZYofKC/BTyeZCG7Uoj3SCFBIDQ9r nou49Pm8unsC02ynNE1MofgJ4tR96J5suFsMot8V7HhUmXpn05zKhF4HVpz1w4SW MGKLwT7V0mx8C7ER00XRcAVtOqIVl9LeWpCOj8SNrA0sKdjNgleA= Received: from localhost (unknown [IPv6:2a01:4f8:120:624c::25]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aloka.lostca.se (Postfix) with ESMTPSA id 48B9415E7A for ; Mon, 18 Nov 2019 18:03:48 +0000 (UTC) Date: Tue, 01 Jan 2019 00:00:00 -0000 From: Arjun Shankar To: libc-stable@sourceware.org Subject: [2.29 COMMITTED] Add glibc.malloc.mxfast tunable Message-ID: <20191118180347.GC73440@aloka.lostca.se> MIME-Version: 1.0 Content-Type: text/plain; charset=unknown-8bit Content-Disposition: inline User-Agent: Mutt/1.10.1 (2018-07-13) Content-Transfer-Encoding: quoted-printable X-IsSubscribed: yes X-SW-Source: 2019-11/txt/msg00014.txt.bz2 * elf/dl-tunables.list: Add glibc.malloc.mxfast. * manual/tunables.texi: Document it. * malloc/malloc.c (do_set_mxfast): New. (__libc_mallopt): Call it. * malloc/arena.c: Add mxfast tunable. * malloc/tst-mxfast.c: New. * malloc/Makefile: Add it. Reviewed-by: Carlos O'Donell (cherry picked from commit c48d92b430c480de06762f80c104922239416826) --- ChangeLog | 10 +++++++++ elf/dl-tunables.list | 5 +++++ malloc/Makefile | 3 +++ malloc/arena.c | 2 ++ malloc/malloc.c | 21 ++++++++++++------- malloc/tst-mxfast.c | 50 ++++++++++++++++++++++++++++++++++++++++++++ manual/tunables.texi | 12 +++++++++++ 7 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 malloc/tst-mxfast.c diff --git a/ChangeLog b/ChangeLog index 8bfc29a02f..cbdc566fa1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2019-08-09 DJ Delorie + + * elf/dl-tunables.list: Add glibc.malloc.mxfast. + * manual/tunables.texi: Document it. + * malloc/malloc.c (do_set_mxfast): New. + (__libc_mallopt): Call it. + * malloc/arena.c: Add mxfast tunable. + * malloc/tst-mxfast.c: New. + * malloc/Makefile: Add it. + 2019-08-08 Niklas Hamb=C3=BCchen Carlos O'Donell =20 diff --git a/elf/dl-tunables.list b/elf/dl-tunables.list index 1fc2d8886b..525c3767b5 100644 --- a/elf/dl-tunables.list +++ b/elf/dl-tunables.list @@ -85,6 +85,11 @@ glibc { tcache_unsorted_limit { type: SIZE_T } + mxfast { + type: SIZE_T + minval: 0 + security_level: SXID_IGNORE + } } cpu { hwcap_mask { diff --git a/malloc/Makefile b/malloc/Makefile index ab2eed09c6..26947feccf 100644 --- a/malloc/Makefile +++ b/malloc/Makefile @@ -39,6 +39,7 @@ tests :=3D mallocbug tst-malloc tst-valloc tst-calloc tst= -obstack \ tst-malloc-too-large \ tst-malloc-stats-cancellation \ tst-tcfree1 tst-tcfree2 tst-tcfree3 \ + tst-mxfast \ =20 tests-static :=3D \ tst-interpose-static-nothread \ @@ -196,6 +197,8 @@ tst-malloc-usable-static-ENV =3D $(tst-malloc-usable-EN= V) tst-malloc-usable-tunables-ENV =3D GLIBC_TUNABLES=3Dglibc.malloc.check=3D3 tst-malloc-usable-static-tunables-ENV =3D $(tst-malloc-usable-tunables-ENV) =20 +tst-mxfast-ENV =3D GLIBC_TUNABLES=3Dglibc.malloc.tcache_count=3D0:glibc.ma= lloc.mxfast=3D0 + ifeq ($(experimental-malloc),yes) CPPFLAGS-malloc.c +=3D -DUSE_TCACHE=3D1 else diff --git a/malloc/arena.c b/malloc/arena.c index efca2bcf68..d19a28710f 100644 --- a/malloc/arena.c +++ b/malloc/arena.c @@ -237,6 +237,7 @@ TUNABLE_CALLBACK_FNDECL (set_tcache_max, size_t) TUNABLE_CALLBACK_FNDECL (set_tcache_count, size_t) TUNABLE_CALLBACK_FNDECL (set_tcache_unsorted_limit, size_t) #endif +TUNABLE_CALLBACK_FNDECL (set_mxfast, size_t) #else /* Initialization routine. */ #include @@ -324,6 +325,7 @@ ptmalloc_init (void) TUNABLE_GET (tcache_unsorted_limit, size_t, TUNABLE_CALLBACK (set_tcache_unsorted_limit)); # endif + TUNABLE_GET (mxfast, size_t, TUNABLE_CALLBACK (set_mxfast)); #else const char *s =3D NULL; if (__glibc_likely (_environ !=3D NULL)) diff --git a/malloc/malloc.c b/malloc/malloc.c index 5c44dcdb66..ecdb2a0f36 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -5142,6 +5142,19 @@ do_set_tcache_unsorted_limit (size_t value) } #endif =20 +static inline int +__always_inline +do_set_mxfast (size_t value) +{ + if (value >=3D 0 && value <=3D MAX_FAST_SIZE) + { + LIBC_PROBE (memory_mallopt_mxfast, 2, value, get_max_fast ()); + set_max_fast (value); + return 1; + } + return 0; +} + int __libc_mallopt (int param_number, int value) { @@ -5161,13 +5174,7 @@ __libc_mallopt (int param_number, int value) switch (param_number) { case M_MXFAST: - if (value >=3D 0 && value <=3D MAX_FAST_SIZE) - { - LIBC_PROBE (memory_mallopt_mxfast, 2, value, get_max_fast ()); - set_max_fast (value); - } - else - res =3D 0; + do_set_mxfast (value); break; =20 case M_TRIM_THRESHOLD: diff --git a/malloc/tst-mxfast.c b/malloc/tst-mxfast.c new file mode 100644 index 0000000000..7a371d2f9d --- /dev/null +++ b/malloc/tst-mxfast.c @@ -0,0 +1,50 @@ +/* Test that glibc.malloc.mxfast tunable works. + Copyright (C) 2018, 2019 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* This test verifies that setting the glibc.malloc.mxfast tunable to + zero results in free'd blocks being returned to the small bins, not + the fast bins. */ + +#include +#include + +int +do_test(void) +{ + struct mallinfo m; + char * volatile p1; + char * volatile p2; + + /* Arbitrary value; must be in default fastbin range. */ + p1 =3D malloc (3); + /* Something large so that p1 isn't a "top block" */ + p2 =3D malloc (512); + free (p1); + + m =3D mallinfo(); + + /* This will fail if there are any blocks in the fastbins. */ + assert (m.smblks =3D=3D 0); + + /* To keep gcc happy. */ + free (p2); + + return 0; +} + +#include diff --git a/manual/tunables.texi b/manual/tunables.texi index 17de5bcc6b..d4c23cb0dd 100644 --- a/manual/tunables.texi +++ b/manual/tunables.texi @@ -214,6 +214,18 @@ pre-fill the per-thread cache with. The default, or w= hen set to zero, is no limit. @end deftp =20 +@deftp Tunable glibc.malloc.mxfast +One of the optimizations malloc uses is to maintain a series of ``fast +bins'' that hold chunks up to a specific size. The default and +maximum size which may be held this way is 80 bytes on 32-bit systems +or 160 bytes on 64-bit systems. Applications which value size over +speed may choose to reduce the size of requests which are serviced +from fast bins with this tunable. Note that the value specified +includes malloc's internal overhead, which is normally the size of one +pointer, so add 4 on 32-bit systems or 8 on 64-bit systems to the size +passed to @code{malloc} for the largest bin size to enable. +@end deftp + @node Elision Tunables @section Elision Tunables @cindex elision tunables --=20 2.21.0