Date: Sun, 2 Oct 2011 16:06:18 +0300 From: Kostik Belousov <kostikbel@gmail.com> To: Lev Serebryakov <lev@freebsd.org> Cc: freebsd-hackers@freebsd.org Subject: Re: Memory allocation in kernel -- what to use in which situation? What is the best for page-sized allocations? Message-ID: <20111002130618.GJ1511@deviant.kiev.zoral.com.ua> In-Reply-To: <358651269.20111002162109@serebryakov.spb.ru> References: <358651269.20111002162109@serebryakov.spb.ru>
next in thread | previous in thread | raw e-mail | index | archive | help
--FaO1PrAXXyeXdeCc Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Oct 02, 2011 at 04:21:09PM +0400, Lev Serebryakov wrote: > Hello, Freebsd-hackers. >=20 > Here are several memory-allocation mechanisms in the kernel. The two > I'm aware of is MALLOC_DEFINE()/malloc()/free() and uma_* (zone(9)). >=20 > 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. >=20 > 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!). >=20 > Am I right? >=20 > 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? Very short answer is that you could use kmem_alloc() or kmem_malloc(). kmem_alloc() sleeps, while kmem_malloc() may be directed to not sleep. --FaO1PrAXXyeXdeCc Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.18 (FreeBSD) iEYEARECAAYFAk6IYckACgkQC3+MBN1Mb4h2mwCgnqjicdk2ZMFW8uYRWmrAc4zZ aY4An0nOQezMQzQvrwZBgfywonhuobWJ =hx5q -----END PGP SIGNATURE----- --FaO1PrAXXyeXdeCc--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20111002130618.GJ1511>