Hi,
I'm trying to evaluate jemalloc using the 2.2-jemalloc branch
on a 64 bits Linux platform.
My first tests were far below my expectations, so I have
investigated a bit more.
I believe the Makefile is broken regarding tcmalloc
and jemalloc (especially jemalloc), and that the glibc
malloc is actually used even when compiling with
USE_JEMALLOC=yes
This is due to the fact -ljemalloc must be used to override
the glibc symbols instead of inlining the whole library,
and this option must be placed at the end of the link
command line.
Patch can be found here:
https://gist.github.com/967358
After fixing the Makefile, the results are much better.
CPU consumption is mostly similar to glibc malloc, with
a slight overhead in system CPU which can be partially
offset by tweaking MALLOC_CONF.
Memory footprint is much better especially when plenty
of very small objects are created. Here is a dummy
example:
redis-cli -r 1000000 RPUSH dummy x >/dev/null
With jemalloc:
used_memory:64725984
used_memory_human:61.73M
used_memory_rss:66998272
mem_fragmentation_ratio:1.04
mem_allocator:jemalloc
With glibc malloc:
used_memory:80798832
used_memory_human:77.06M
used_memory_rss:113664000
mem_fragmentation_ratio:1.41
mem_allocator:libc
Gains come from the fact the HAVE_MALLOC_SIZE workaround
is no longer necessary, and from the better granularity
in the allocation classes of jemalloc for small objects.
Another interesting consequence of using jemalloc is it
tends to give some deallocated memory back to the system
(more than glibc malloc). For instance after a flushall,
a lot a memory is given back.
Memory footprint could be even better if the tiny class
was extended until 32 bytes. Unfortunately, it stops at 8.
For small objects, the classes are:
Tiny: 8
Quantum-spaced: 16 32 48 ...
So 24 bytes is not an allocation class with jemalloc
(and I think there is no way to enforce it using
parameters). It is a pity because 24 bytes is precisely
the size of some critical Redis structures (dictionary
entries, list entries, etc ...). This is one point where
tcmalloc is better (all classes are 8 bytes spaced).
Long term memory fragmentation is difficult to evaluate
with my workload (it is low even with glibc malloc), but
this is supposed to be a strong point of jemalloc, so
I am confident it will improve the behavior of Redis
for most situations.
Finally, I think jemalloc support is a useful addition
to Redis. If you want to play with it, please consider
applying the Makefile patch, otherwise your results
will be meaningless.
Regards,
Didier.