[nsd-users] Mmap allocation of namedb database

Martin Svec martin.svec at zoner.cz
Fri Mar 5 20:08:26 UTC 2010


attached I send a patch that allocates database memory chunks using
anonymous mmap/munmap instead of malloc/free. Primary goal of this patch
is to reduce memory overhead of xfrd daemon. Xfrd inherits namedb
database from the main process and immediately frees it after
initialization. However, when using malloc, namedb database is allocated
on a process heap and destroying it does not release the memory occupied
by the heap. Mmap/munmap allocation guarantees that the memory is really
freed and available to the system. (Yes, I know that memory is cheap,
but I rather see it filled with filesystem cache than with unused
process heap ;-))

The patch simply changes allocator/deallocator functions for namedb
region allocator. It also increases chunk size to 128kB because I think
that 4kB is quite small. I've found no performance impacts of this patch
but more testing is necessary!

There are some numbers for our 250MB nsd.db, 65000 zones, 64bit Gentoo

xalloc/free allocation:
587MB xfrd process + 501MB shared server processes = 1088MB of RAM

mmap/munmap allocation:
118MB xfrd process + 495MB shared server processes = 613MB of RAM

That is, the patch saved more than 40% of NSD memory for us.

I provide the patch as a public domain, feel free to modify it or reject
it. I tested it only on 32/64bit Linux with 2.6.x kernels so there may
be portability problems on other systems.

(I also want to try large memory pages soon, so I can post a patch if
somebody will be interested. I guess that large pages could also improve
NSD performance because they reduce pressure on TLBs and VM descriptor

Best regards
Martin Svec

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: mmap-alloc-namedb.patch
URL: <http://lists.nlnetlabs.nl/pipermail/nsd-users/attachments/20100305/73b73cbe/attachment.ksh>

More information about the nsd-users mailing list