Add dlmalloc 2.7.0, a very efficient malloc/free/realloc implementation.

According to my tests it is *amazingly* efficient - it gave me about 10%
memory saving (SIZE in the top(1)) for the large processes like X and jre
without any measureable performance saturation.

Moreover, due to not very clear for me reasons Python benchmark (pybench)
is about 60% (!!!) faster with this allocator comparing to the libc one.
Obviously we should investigate this further and if there is no error
then tune either Python or our own malloc.

Alternatively we may evaluate a possibility to make it (or part of it) our
default malloc(), because it is friendly licensed and actively maintained.
This commit is contained in:
Maxim Sobolev 2001-04-05 15:17:33 +00:00
parent 5207f70b22
commit 7a663db0e0
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=40891
9 changed files with 144 additions and 0 deletions

View file

@ -80,6 +80,7 @@
SUBDIR += ddd
SUBDIR += dia2code
SUBDIR += diffconvert
SUBDIR += dlmalloc
SUBDIR += dmake
SUBDIR += dmalloc
SUBDIR += doc++

48
devel/dlmalloc/Makefile Normal file
View file

@ -0,0 +1,48 @@
# New ports collection makefile for: dlmalloc
# Date created: 4 April 2001
# Whom: Maxim Sobolax <sobomax@FreeBSD.org>
#
# $FreeBSD$
#
PORTNAME= dlmalloc
PORTVERSION= 2.7.0
CATEGORIES= devel
MASTER_SITES= ftp://gee.cs.oswego.edu/pub/misc/
DISTFILES= malloc-${PORTVERSION}.c malloc-${PORTVERSION}.h
EXTRACT_ONLY=
MAINTAINER= sobomax@FreeBSD.org
DIST_SUBDIR= ${PORTNAME}
WRKSRC= ${WRKDIR}
MAKEFILE= ${FILESDIR}/Makefile
MAKE_ENV= PTHREAD_CFLAGS="${PTHREAD_CFLAGS}" \
PTHREAD_LIBS="${PTHREAD_LIBS}"
PKGMESSAGE= ${WRKDIR}/pkg-message
do-extract:
@${MKDIR} ${WRKDIR}
.for file in ${DISTFILES}
@${CP} ${DISTDIR}/${DIST_SUBDIR}/${file} \
${WRKSRC}/${file:S/-${PORTVERSION}//}
.endfor
do-install:
${MKDIR} ${PREFIX}/include/${PORTNAME}
${MKDIR} ${PREFIX}/share/doc/dlmalloc
${INSTALL_DATA} ${WRKSRC}/malloc.h ${PREFIX}/include/${PORTNAME}
.for suffix in "" # "_r" <- thread-safe version doesn't work yet
${INSTALL_DATA} ${WRKSRC}/libdlmalloc${suffix}.a ${PREFIX}/lib
${INSTALL_PROGRAM} ${WRKSRC}/dlmalloc_module${suffix}.so ${PREFIX}/lib
.endfor
${SED} 's|%%PREFIX%%|${PREFIX}|g' ${FILESDIR}/README.FreeBSD | \
/usr/bin/fmt > ${WRKDIR}/README.FreeBSD
${INSTALL_MAN} ${WRKDIR}/README.FreeBSD ${PREFIX}/share/doc/dlmalloc
@${SED} 's|%%PREFIX%%|${PREFIX}|g' ${PKGDIR}/pkg-message | \
/usr/bin/fmt > ${PKGMESSAGE}
post-install:
@${CAT} ${PKGMESSAGE}
.include <bsd.port.mk>

2
devel/dlmalloc/distinfo Normal file
View file

@ -0,0 +1,2 @@
MD5 (dlmalloc/malloc-2.7.0.c) = b65e649a6c8e5c9354c7322c1b0d3608
MD5 (dlmalloc/malloc-2.7.0.h) = 9de8397b53f5d2b485ac419e1458a33f

View file

@ -0,0 +1,35 @@
# $FreeBSD$
SRCS= malloc.c malloc.h
STATIC_LIB= libdlmalloc.a
STATIC_LIB_R= libdlmalloc_r.a
SHARED_OBJ= dlmalloc_module.so
SHARED_OBJ_R= dlmalloc_module_r.so
THR_SAFE_FLAG= -DUSE_MALLOC_LOCK ${PTHREAD_CFLAGS}
CFLAGS+= -I${.CURDIR}
all: ${STATIC_LIB} ${STATIC_LIB_R} ${SHARED_OBJ} ${SHARED_OBJ_R}
malloc.o: ${SRCS}
${CC} -c ${CFLAGS} -o ${.TARGET} malloc.c
malloc_r.o: ${SRCS}
${CC} -c ${CFLAGS} ${THR_SAFE_FLAG} -o ${.TARGET} malloc.c
malloc.so: ${SRCS}
${CC} -c ${CFLAGS} -fPIC -DPIC -o ${.TARGET} malloc.c
malloc_r.so: ${SRCS}
${CC} -c ${CFLAGS} ${THR_SAFE_FLAG} -fPIC -DPIC -o ${.TARGET} malloc.c
${STATIC_LIB}: malloc.o
${AR} cq ${.TARGET} malloc.o
${STATIC_LIB_R}: malloc_r.o
${AR} cq ${.TARGET} malloc_r.o
${SHARED_OBJ}: malloc.so
${CC} -shared -o ${.TARGET} malloc.so
${SHARED_OBJ_R}: malloc_r.so
${CC} -shared -o ${.TARGET} malloc_r.so ${PTHREAD_LIBS}

View file

@ -0,0 +1,30 @@
This is drop-in replacement for the standard libc malloc/realloc/free routines.
In many cases it makes a sense to use it with your program instead of the
standard ones, as sometimes it is significantly more efficient and fast,
especially for the memory intensive apps such as virtual machines, GUIs etc.
There are two methods of linking it with your program:
1) Run-time linking using LD_PRELOAD.
This method doesn't requre to recompile a program, but doesn't work for
statically linked binaries. Just set the following environment variable and
run your program - dynamic linker will automatically do the rest:
LD_PRELOAD=%%PREFIX%%/lib/dlmalloc_module.so
2) Compile-time linking.
Compile your applications that use the dlmalloc port with the following
command line options:
-I%%PREFIX%%/include/dlmalloc -L%%PREFIX%%/lib -ldlmalloc
Note that the include (-I<path>) directive shown here should appear before
any other include directive that would cause the compiler to find the FreeBSD
file malloc.h. Using the FreeBSD malloc.h instead of the dlmalloc malloc.h
will result in an app that fails in many odd and maybe spectacular ways.
It makes a sense to use the first method to benchmark effect of using this
version of memory management routines and if positive effect is confirmed then
recompile the application using the second method.

View file

@ -0,0 +1 @@
A very efficient malloc/free/realloc implementation

12
devel/dlmalloc/pkg-descr Normal file
View file

@ -0,0 +1,12 @@
This is a version (aka dlmalloc) of malloc/free/realloc written by Doug Lea
and released to the public domain. Use, modify, and redistribute this code
without permission or acknowledgement in any way you wish. Send questions,
comments, complaints, performance data, etc to dl@cs.oswego.edu
This is not the fastest, most space-conserving, most portable, or most
tunable malloc ever written. However it is among the fastest while also being
among the most space-conserving, portable and tunable. Consistent balance
across these factors results in a good general-purpose allocator for
malloc-intensive programs.
WWW: http://gee.cs.oswego.edu/dl/html/malloc.html

View file

@ -0,0 +1,7 @@
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Please see %%PREFIX%%/share/doc/dlmalloc/README.FreeBSD
for instructions on how to link with dlmalloc, and for
other issues and problems.
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

8
devel/dlmalloc/pkg-plist Normal file
View file

@ -0,0 +1,8 @@
include/dlmalloc/malloc.h
lib/dlmalloc_module.so
@comment lib/dlmalloc_module_r.so
lib/libdlmalloc.a
share/doc/dlmalloc/README.FreeBSD
@comment lib/libdlmalloc_r.a
@dirrm share/doc/dlmalloc
@dirrm include/dlmalloc