Doug Lea's malloc adapted for 64bit, needs testing

Wolfram Gloger (Wolfram.Gloger@dent.med.uni-muenchen.de)
Fri, 7 Jun 1996 15:20:43 +0200


Hi,

Over the last days, I have hacked Doug Lea's latest malloc version
so that it runs on 64bit-architectures (or so I hope). Unfortunately,
I don't have access to a 64bit machine yet, so I hope someone else
can test it or, if there should be problems, let me test it on a
temporary account.

Why do this ? I don't know which malloc version you're using in
alpha-libc, but if it's GNU malloc or (worse) derived from the old BSD
code, there is a lot to gain from using Doug's version. It is by far
the most space-efficient malloc implementation that I know of. It
excels in particular at dealing with widely varying allocation size
distributions, showing little fragmentation and returning memory to
the system via sbrk(-x) or munmap(). On the latest Linux kernels, it
also supports fast realloc()ation of large chunks via the mremap()
system call. I would like to have dl-malloc put into GNU libc, but a
prerequisite is that it runs on 64bit architectures.

I hope it does so now. There is a catch though, because with
sizeof(void*)=8 and sizeof(size_t)=4 the minimum chunk size is 24bytes
(compared to 16bytes on a 32bit arch), so the worst-case overhead
becomes 20bytes rather than 12 (the normal overhead for larger chunks
remains only 4bytes). But if you're allocating lots and lots of 4byte
(or smaller) chunks, you should probably be running your own
special-purpose allocator anyway.

You can get the malloc source file from

ftp://md.dent.med.uni-muenchen.de/pub/wmglo/malloc-2.6.3f-64.c

and a simple testing program, malloc-test.c, is also there (that
is also untested under 64bit, but should work). As a quick start,
you could compile with

% cc -O -DDEBUG -c malloc-2.6.3f-64.c
^^^ to test for bugs (but executes much slower!)
% cc -O malloc-test.c malloc-2.6.3f-64.o -o malloc-test
% ./malloc-test
% ./malloc-test 1000000 33000
^^^ ^^^
^^^ maximum size of a single allocation
total number of allocations
etc.

If this works for all sorts of allocation sizes (play with the second
command line parameter to malloc-test), fine. If not, I'd like to
hear about it (please send me mail as I'm not on the linux-alpha
list). You might also want to link against a different malloc
implementation (such as the one in your libc) and compare the
`waste percentage' figures that `malloc-test' prints.

Regards,
Wolfram.