mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-21 12:30:06 +00:00
* malloc/tst-trim1.c: New file.
* malloc/Makefile (tests): Add tst-trim1.
This commit is contained in:
parent
68631c8eb9
commit
be8c1500c7
@ -5,6 +5,8 @@
|
|||||||
(mTRIm): Additionally iterate over all free blocks and use madvise
|
(mTRIm): Additionally iterate over all free blocks and use madvise
|
||||||
to free memory for all those blocks which contain at least one
|
to free memory for all those blocks which contain at least one
|
||||||
memory page.
|
memory page.
|
||||||
|
* malloc/tst-trim1.c: New file.
|
||||||
|
* malloc/Makefile (tests): Add tst-trim1.
|
||||||
|
|
||||||
* malloc/malloc.c (do_check_malloc_state): Minimal cleanups.
|
* malloc/malloc.c (do_check_malloc_state): Minimal cleanups.
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
# Copyright (C) 1991-1999, 2000, 2001, 2002, 2003, 2005, 2006
|
# Copyright (C) 1991-1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007
|
||||||
# Free Software Foundation, Inc.
|
# Free Software Foundation, Inc.
|
||||||
# This file is part of the GNU C Library.
|
# This file is part of the GNU C Library.
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ all:
|
|||||||
dist-headers := malloc.h
|
dist-headers := malloc.h
|
||||||
headers := $(dist-headers) obstack.h mcheck.h
|
headers := $(dist-headers) obstack.h mcheck.h
|
||||||
tests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \
|
tests := mallocbug tst-malloc tst-valloc tst-calloc tst-obstack \
|
||||||
tst-mallocstate tst-mcheck tst-mallocfork
|
tst-mallocstate tst-mcheck tst-mallocfork tst-trim1
|
||||||
test-srcs = tst-mtrace
|
test-srcs = tst-mtrace
|
||||||
|
|
||||||
distribute = thread-m.h mtrace.pl mcheck-init.c stackinfo.h memusage.h \
|
distribute = thread-m.h mtrace.pl mcheck-init.c stackinfo.h memusage.h \
|
||||||
|
56
malloc/tst-trim1.c
Normal file
56
malloc/tst-trim1.c
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
#include <malloc.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#define N 10000
|
||||||
|
|
||||||
|
static void *arr[N];
|
||||||
|
|
||||||
|
static int
|
||||||
|
do_test (void)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < N; ++i)
|
||||||
|
{
|
||||||
|
size_t size = random () % 16384;
|
||||||
|
|
||||||
|
if ((arr[i] = malloc (size)) == NULL)
|
||||||
|
{
|
||||||
|
nomem:
|
||||||
|
puts ("not enough memory");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
memset (arr[i], size, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
void *p = malloc (256);
|
||||||
|
if (p == NULL)
|
||||||
|
goto nomem;
|
||||||
|
memset (p, 1, 256);
|
||||||
|
|
||||||
|
puts ("==================================================================");
|
||||||
|
|
||||||
|
for (int i = 0; i < N; ++i)
|
||||||
|
if (i % 13 != 0)
|
||||||
|
free (arr[i]);
|
||||||
|
|
||||||
|
puts ("==================================================================");
|
||||||
|
|
||||||
|
malloc_trim (0);
|
||||||
|
|
||||||
|
puts ("==================================================================");
|
||||||
|
|
||||||
|
p = malloc (30000);
|
||||||
|
if (p == NULL)
|
||||||
|
goto nomem;
|
||||||
|
|
||||||
|
memset (p, 2, 30000);
|
||||||
|
|
||||||
|
malloc_trim (0);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#define TEST_FUNCTION do_test ()
|
||||||
|
#include "../test-skeleton.c"
|
Loading…
Reference in New Issue
Block a user