|
From: <sv...@va...> - 2006-07-08 08:29:26
|
Author: njn
Date: 2006-07-08 09:29:20 +0100 (Sat, 08 Jul 2006)
New Revision: 5983
Log:
Trivial implementation for malloc_trim, thanks to Eero Tamminen.
Modified:
trunk/coregrind/m_replacemalloc/vg_replace_malloc.c
Modified: trunk/coregrind/m_replacemalloc/vg_replace_malloc.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_replacemalloc/vg_replace_malloc.c 2006-07-06 01:54:=
34 UTC (rev 5982)
+++ trunk/coregrind/m_replacemalloc/vg_replace_malloc.c 2006-07-08 08:29:=
20 UTC (rev 5983)
@@ -358,6 +358,41 @@
MALLOPT(m_libc_dot_so_star, mallopt);
=20
=20
+// Documentation says:
+// malloc_trim(size_t pad);
+//=20
+// If possible, gives memory back to the system (via negative argument=
s to
+// sbrk) if there is unused memory at the `high' end of the malloc poo=
l.
+// You can call this after freeing large blocks of memory to potential=
ly
+// reduce the system-level memory requirements of a program. However, =
it
+// cannot guarantee to reduce memory. Under some allocation patterns,
+// some large free blocks of memory will be locked between two used
+// chunks, so they cannot be given back to the system.
+//=20
+// The `pad' argument to malloc_trim represents the amount of free
+// trailing space to leave untrimmed. If this argument is zero, only t=
he
+// minimum amount of memory to maintain internal data structures will =
be
+// left (one page or less). Non-zero arguments can be supplied to main=
tain
+// enough trailing space to service future expected allocations withou=
t
+// having to re-obtain memory from the system.
+//=20
+// Malloc_trim returns 1 if it actually released any memory, else 0. O=
n
+// systems that do not support "negative sbrks", it will always return=
0.=20
+//
+// For simplicity, we always return 0.
+#define MALLOC_TRIM(soname, fnname) \
+ \
+ int VG_REPLACE_FUNCTION_ZU(soname, fnname) ( SizeT pad ); \
+ int VG_REPLACE_FUNCTION_ZU(soname, fnname) ( SizeT pad ) \
+ { \
+ /* 0 denotes that malloc_trim() either wasn't able \
+ to do anything, or was not implemented */ \
+ return 0; \
+ }
+
+MALLOC_TRIM(m_libc_dot_so_star, malloc_trim);
+
+
#define POSIX_MEMALIGN(soname, fnname) \
\
int VG_REPLACE_FUNCTION_ZU(soname, fnname) ( void **memptr, \
@@ -427,7 +462,6 @@
=20
PANIC(m_libc_dot_so_star, pvalloc);
PANIC(m_libc_dot_so_star, malloc_stats);
-PANIC(m_libc_dot_so_star, malloc_trim);
PANIC(m_libc_dot_so_star, malloc_get_state);
PANIC(m_libc_dot_so_star, malloc_set_state);
=20
|