Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 2 Oct 2011 16:21:09 +0400
From:      Lev Serebryakov <lev@FreeBSD.org>
To:        freebsd-hackers@freebsd.org
Subject:   Memory allocation in kernel -- what to use in which situation? What is the best for page-sized allocations?
Message-ID:  <358651269.20111002162109@serebryakov.spb.ru>

next in thread | raw e-mail | index | archive | help
Hello, Freebsd-hackers.

  Here are several memory-allocation mechanisms in the kernel. The two
I'm aware of is MALLOC_DEFINE()/malloc()/free() and uma_* (zone(9)).

  As far as I understand, malloc() is general-purpose, but it has
fixed "transaction cost" (in term of memory consumption) for each
block allocated, and is not very suitable for allocation of many small
blocks, as lots of memory will be wasted for bookkeeping.

  zone(9) allocator, on other hand, have very low cost of each
allocated block, but could allocate only pre-configured fixed-size
blocks, and ideal for allocation tons of small objects (and provide
API for reusing them, too!).

  Am I right?

   But what if I need to allocate a lot (say, 16K-32K) of page-sized
blocks? Not in one chunk, for sure, but in lifetime of my kernel
module. Which allocator should I use? It seems, the best one will be
very low-level only-page-sized allocator. Is here any in kernel?

--=20
// Black Lion AKA Lev Serebryakov <lev@FreeBSD.org>




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?358651269.20111002162109>