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