|
|
8a8cfb |
commit cb89ba9c72f66327f5d66034681eb1d46eedf96f
|
|
|
8a8cfb |
Author: DJ Delorie <dj@redhat.com>
|
|
|
8a8cfb |
Date: Thu Aug 8 19:09:43 2019 -0400
|
|
|
8a8cfb |
|
|
|
8a8cfb |
Add glibc.malloc.mxfast tunable
|
|
|
8a8cfb |
|
|
|
8a8cfb |
* elf/dl-tunables.list: Add glibc.malloc.mxfast.
|
|
|
8a8cfb |
* manual/tunables.texi: Document it.
|
|
|
8a8cfb |
* malloc/malloc.c (do_set_mxfast): New.
|
|
|
8a8cfb |
(__libc_mallopt): Call it.
|
|
|
8a8cfb |
* malloc/arena.c: Add mxfast tunable.
|
|
|
8a8cfb |
* malloc/tst-mxfast.c: New.
|
|
|
8a8cfb |
* malloc/Makefile: Add it.
|
|
|
8a8cfb |
|
|
|
8a8cfb |
Reviewed-by: Carlos O'Donell <carlos@redhat.com>
|
|
|
8a8cfb |
(cherry picked from commit c48d92b430c480de06762f80c104922239416826)
|
|
|
8a8cfb |
|
|
|
8a8cfb |
diff --git a/elf/dl-tunables.list b/elf/dl-tunables.list
|
|
|
8a8cfb |
index 1f8ecb8437a0460f..1ff6fcb6f24f93a8 100644
|
|
|
8a8cfb |
--- a/elf/dl-tunables.list
|
|
|
8a8cfb |
+++ b/elf/dl-tunables.list
|
|
|
8a8cfb |
@@ -85,6 +85,11 @@ glibc {
|
|
|
8a8cfb |
tcache_unsorted_limit {
|
|
|
8a8cfb |
type: SIZE_T
|
|
|
8a8cfb |
}
|
|
|
8a8cfb |
+ mxfast {
|
|
|
8a8cfb |
+ type: SIZE_T
|
|
|
8a8cfb |
+ minval: 0
|
|
|
8a8cfb |
+ security_level: SXID_IGNORE
|
|
|
8a8cfb |
+ }
|
|
|
8a8cfb |
}
|
|
|
8a8cfb |
tune {
|
|
|
8a8cfb |
hwcap_mask {
|
|
|
8a8cfb |
diff --git a/malloc/Makefile b/malloc/Makefile
|
|
|
8a8cfb |
index 228a1279a5960d8c..bf9a53cb7c5ebacb 100644
|
|
|
8a8cfb |
--- a/malloc/Makefile
|
|
|
8a8cfb |
+++ b/malloc/Makefile
|
|
|
8a8cfb |
@@ -39,6 +39,7 @@ tests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \
|
|
|
8a8cfb |
tst-malloc-too-large \
|
|
|
8a8cfb |
tst-malloc-stats-cancellation \
|
|
|
8a8cfb |
tst-tcfree1 tst-tcfree2 tst-tcfree3 \
|
|
|
8a8cfb |
+ tst-mxfast \
|
|
|
8a8cfb |
|
|
|
8a8cfb |
tests-static := \
|
|
|
8a8cfb |
tst-interpose-static-nothread \
|
|
|
8a8cfb |
@@ -196,6 +197,8 @@ tst-malloc-usable-static-ENV = $(tst-malloc-usable-ENV)
|
|
|
8a8cfb |
tst-malloc-usable-tunables-ENV = GLIBC_TUNABLES=glibc.malloc.check=3
|
|
|
8a8cfb |
tst-malloc-usable-static-tunables-ENV = $(tst-malloc-usable-tunables-ENV)
|
|
|
8a8cfb |
|
|
|
8a8cfb |
+tst-mxfast-ENV = GLIBC_TUNABLES=glibc.malloc.tcache_count=0:glibc.malloc.mxfast=0
|
|
|
8a8cfb |
+
|
|
|
8a8cfb |
ifeq ($(experimental-malloc),yes)
|
|
|
8a8cfb |
CPPFLAGS-malloc.c += -DUSE_TCACHE=1
|
|
|
8a8cfb |
else
|
|
|
8a8cfb |
diff --git a/malloc/arena.c b/malloc/arena.c
|
|
|
8a8cfb |
index ff8fd5d2a7e51ac8..f5c7ad4570ad6186 100644
|
|
|
8a8cfb |
--- a/malloc/arena.c
|
|
|
8a8cfb |
+++ b/malloc/arena.c
|
|
|
8a8cfb |
@@ -237,6 +237,7 @@ TUNABLE_CALLBACK_FNDECL (set_tcache_max, size_t)
|
|
|
8a8cfb |
TUNABLE_CALLBACK_FNDECL (set_tcache_count, size_t)
|
|
|
8a8cfb |
TUNABLE_CALLBACK_FNDECL (set_tcache_unsorted_limit, size_t)
|
|
|
8a8cfb |
#endif
|
|
|
8a8cfb |
+TUNABLE_CALLBACK_FNDECL (set_mxfast, size_t)
|
|
|
8a8cfb |
#else
|
|
|
8a8cfb |
/* Initialization routine. */
|
|
|
8a8cfb |
#include <string.h>
|
|
|
8a8cfb |
@@ -324,6 +325,7 @@ ptmalloc_init (void)
|
|
|
8a8cfb |
TUNABLE_GET (tcache_unsorted_limit, size_t,
|
|
|
8a8cfb |
TUNABLE_CALLBACK (set_tcache_unsorted_limit));
|
|
|
8a8cfb |
# endif
|
|
|
8a8cfb |
+ TUNABLE_GET (mxfast, size_t, TUNABLE_CALLBACK (set_mxfast));
|
|
|
8a8cfb |
#else
|
|
|
8a8cfb |
const char *s = NULL;
|
|
|
8a8cfb |
if (__glibc_likely (_environ != NULL))
|
|
|
8a8cfb |
diff --git a/malloc/malloc.c b/malloc/malloc.c
|
|
|
8a8cfb |
index fcf480acdaea1b86..9756ed0a0d28c5f6 100644
|
|
|
8a8cfb |
--- a/malloc/malloc.c
|
|
|
8a8cfb |
+++ b/malloc/malloc.c
|
|
|
8a8cfb |
@@ -5142,6 +5142,19 @@ do_set_tcache_unsorted_limit (size_t value)
|
|
|
8a8cfb |
}
|
|
|
8a8cfb |
#endif
|
|
|
8a8cfb |
|
|
|
8a8cfb |
+static inline int
|
|
|
8a8cfb |
+__always_inline
|
|
|
8a8cfb |
+do_set_mxfast (size_t value)
|
|
|
8a8cfb |
+{
|
|
|
8a8cfb |
+ if (value >= 0 && value <= MAX_FAST_SIZE)
|
|
|
8a8cfb |
+ {
|
|
|
8a8cfb |
+ LIBC_PROBE (memory_mallopt_mxfast, 2, value, get_max_fast ());
|
|
|
8a8cfb |
+ set_max_fast (value);
|
|
|
8a8cfb |
+ return 1;
|
|
|
8a8cfb |
+ }
|
|
|
8a8cfb |
+ return 0;
|
|
|
8a8cfb |
+}
|
|
|
8a8cfb |
+
|
|
|
8a8cfb |
int
|
|
|
8a8cfb |
__libc_mallopt (int param_number, int value)
|
|
|
8a8cfb |
{
|
|
|
8a8cfb |
@@ -5161,13 +5174,7 @@ __libc_mallopt (int param_number, int value)
|
|
|
8a8cfb |
switch (param_number)
|
|
|
8a8cfb |
{
|
|
|
8a8cfb |
case M_MXFAST:
|
|
|
8a8cfb |
- if (value >= 0 && value <= MAX_FAST_SIZE)
|
|
|
8a8cfb |
- {
|
|
|
8a8cfb |
- LIBC_PROBE (memory_mallopt_mxfast, 2, value, get_max_fast ());
|
|
|
8a8cfb |
- set_max_fast (value);
|
|
|
8a8cfb |
- }
|
|
|
8a8cfb |
- else
|
|
|
8a8cfb |
- res = 0;
|
|
|
8a8cfb |
+ do_set_mxfast (value);
|
|
|
8a8cfb |
break;
|
|
|
8a8cfb |
|
|
|
8a8cfb |
case M_TRIM_THRESHOLD:
|
|
|
8a8cfb |
diff --git a/malloc/tst-mxfast.c b/malloc/tst-mxfast.c
|
|
|
8a8cfb |
new file mode 100644
|
|
|
8a8cfb |
index 0000000000000000..7a371d2f9d2f0005
|
|
|
8a8cfb |
--- /dev/null
|
|
|
8a8cfb |
+++ b/malloc/tst-mxfast.c
|
|
|
8a8cfb |
@@ -0,0 +1,50 @@
|
|
|
8a8cfb |
+/* Test that glibc.malloc.mxfast tunable works.
|
|
|
8a8cfb |
+ Copyright (C) 2018, 2019 Free Software Foundation, Inc.
|
|
|
8a8cfb |
+ This file is part of the GNU C Library.
|
|
|
8a8cfb |
+
|
|
|
8a8cfb |
+ The GNU C Library is free software; you can redistribute it and/or
|
|
|
8a8cfb |
+ modify it under the terms of the GNU Lesser General Public
|
|
|
8a8cfb |
+ License as published by the Free Software Foundation; either
|
|
|
8a8cfb |
+ version 2.1 of the License, or (at your option) any later version.
|
|
|
8a8cfb |
+
|
|
|
8a8cfb |
+ The GNU C Library is distributed in the hope that it will be useful,
|
|
|
8a8cfb |
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
8a8cfb |
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
8a8cfb |
+ Lesser General Public License for more details.
|
|
|
8a8cfb |
+
|
|
|
8a8cfb |
+ You should have received a copy of the GNU Lesser General Public
|
|
|
8a8cfb |
+ License along with the GNU C Library; if not, see
|
|
|
8a8cfb |
+ <http://www.gnu.org/licenses/>. */
|
|
|
8a8cfb |
+
|
|
|
8a8cfb |
+/* This test verifies that setting the glibc.malloc.mxfast tunable to
|
|
|
8a8cfb |
+ zero results in free'd blocks being returned to the small bins, not
|
|
|
8a8cfb |
+ the fast bins. */
|
|
|
8a8cfb |
+
|
|
|
8a8cfb |
+#include <malloc.h>
|
|
|
8a8cfb |
+#include <assert.h>
|
|
|
8a8cfb |
+
|
|
|
8a8cfb |
+int
|
|
|
8a8cfb |
+do_test(void)
|
|
|
8a8cfb |
+{
|
|
|
8a8cfb |
+ struct mallinfo m;
|
|
|
8a8cfb |
+ char * volatile p1;
|
|
|
8a8cfb |
+ char * volatile p2;
|
|
|
8a8cfb |
+
|
|
|
8a8cfb |
+ /* Arbitrary value; must be in default fastbin range. */
|
|
|
8a8cfb |
+ p1 = malloc (3);
|
|
|
8a8cfb |
+ /* Something large so that p1 isn't a "top block" */
|
|
|
8a8cfb |
+ p2 = malloc (512);
|
|
|
8a8cfb |
+ free (p1);
|
|
|
8a8cfb |
+
|
|
|
8a8cfb |
+ m = mallinfo();
|
|
|
8a8cfb |
+
|
|
|
8a8cfb |
+ /* This will fail if there are any blocks in the fastbins. */
|
|
|
8a8cfb |
+ assert (m.smblks == 0);
|
|
|
8a8cfb |
+
|
|
|
8a8cfb |
+ /* To keep gcc happy. */
|
|
|
8a8cfb |
+ free (p2);
|
|
|
8a8cfb |
+
|
|
|
8a8cfb |
+ return 0;
|
|
|
8a8cfb |
+}
|
|
|
8a8cfb |
+
|
|
|
8a8cfb |
+#include <support/test-driver.c>
|
|
|
8a8cfb |
diff --git a/manual/tunables.texi b/manual/tunables.texi
|
|
|
8a8cfb |
index f6c49250e3889ddd..3dc6f9a44592c030 100644
|
|
|
8a8cfb |
--- a/manual/tunables.texi
|
|
|
8a8cfb |
+++ b/manual/tunables.texi
|
|
|
8a8cfb |
@@ -213,6 +213,18 @@ pre-fill the per-thread cache with. The default, or when set to zero,
|
|
|
8a8cfb |
is no limit.
|
|
|
8a8cfb |
@end deftp
|
|
|
8a8cfb |
|
|
|
8a8cfb |
+@deftp Tunable glibc.malloc.mxfast
|
|
|
8a8cfb |
+One of the optimizations malloc uses is to maintain a series of ``fast
|
|
|
8a8cfb |
+bins'' that hold chunks up to a specific size. The default and
|
|
|
8a8cfb |
+maximum size which may be held this way is 80 bytes on 32-bit systems
|
|
|
8a8cfb |
+or 160 bytes on 64-bit systems. Applications which value size over
|
|
|
8a8cfb |
+speed may choose to reduce the size of requests which are serviced
|
|
|
8a8cfb |
+from fast bins with this tunable. Note that the value specified
|
|
|
8a8cfb |
+includes malloc's internal overhead, which is normally the size of one
|
|
|
8a8cfb |
+pointer, so add 4 on 32-bit systems or 8 on 64-bit systems to the size
|
|
|
8a8cfb |
+passed to @code{malloc} for the largest bin size to enable.
|
|
|
8a8cfb |
+@end deftp
|
|
|
8a8cfb |
+
|
|
|
8a8cfb |
@node Elision Tunables
|
|
|
8a8cfb |
@section Elision Tunables
|
|
|
8a8cfb |
@cindex elision tunables
|