about summary refs log tree commit diff
path: root/malloc/tst-mxfast.c
diff options
context:
space:
mode:
authorDJ Delorie <dj@redhat.com>2019-08-08 19:09:43 -0400
committerDJ Delorie <dj@redhat.com>2019-08-09 14:04:03 -0400
commitc48d92b430c480de06762f80c104922239416826 (patch)
treeefb687b05fe7b94025ad29c6fe35d1d60a336fb8 /malloc/tst-mxfast.c
parentb6d2c4475d5abc05dd009575b90556bdd3c78ad0 (diff)
downloadglibc-c48d92b430c480de06762f80c104922239416826.tar.gz
glibc-c48d92b430c480de06762f80c104922239416826.tar.xz
glibc-c48d92b430c480de06762f80c104922239416826.zip
Add glibc.malloc.mxfast tunable
* 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 <carlos@redhat.com>
Diffstat (limited to 'malloc/tst-mxfast.c')
-rw-r--r--malloc/tst-mxfast.c50
1 files changed, 50 insertions, 0 deletions
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
+   <http://www.gnu.org/licenses/>.  */
+
+/* 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 <malloc.h>
+#include <assert.h>
+
+int
+do_test(void)
+{
+  struct mallinfo m;
+  char * volatile p1;
+  char * volatile p2;
+
+  /* Arbitrary value; must be in default fastbin range.  */
+  p1 = malloc (3);
+  /* Something large so that p1 isn't a "top block" */
+  p2 = malloc (512);
+  free (p1);
+
+  m = mallinfo();
+
+  /* This will fail if there are any blocks in the fastbins.  */
+  assert (m.smblks == 0);
+
+  /* To keep gcc happy.  */
+  free (p2);
+
+  return 0;
+}
+
+#include <support/test-driver.c>