Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 2 Mar 2010 10:27:11 +0200
From:      Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua>
To:        Dan Nelson <dnelson@allantgroup.com>
Cc:        freebsd-hackers@freebsd.org, shrivatsan@gmail.com, Shrivatsan <shrivatsan_v@yahoo.com>
Subject:   Re: kernel malloc() and free()
Message-ID:  <20100302082711.GA1663@pm513-1.comsys.ntu-kpi.kiev.ua>
In-Reply-To: <20100302032440.GV70798@dan.emsphone.com>
References:  <178848.53651.qm@web112006.mail.gq1.yahoo.com> <20100302032440.GV70798@dan.emsphone.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, Mar 01, 2010 at 09:24:40PM -0600, Dan Nelson wrote:

> Hm.  Even after some reading, I'm not sure how the slabs keep track of which
> elements are allocated or free.  I expected to find a bitmap somewhere that
> malloc() sets and free() clears, but I don't see it.  Maybe some kernel
> hacker can explain it better :) Regardless, the size of the allocation at
> this point isn't important, since you know all the items in the page are the
> same size.

When uma_zalloc() is called it uses per CPU cache for items.  Pointers
to items are taken from uc_allocbucket, that contains array of pointers
to items.  When an item is freed its pointer goes to uc_freebucket if
it has space to save this pointer.  From time to time uc_allocbucket and
uc_freebucket are switched (see conditions for switching in uma_zalloc()
and uma_zfree()).  Initially when uma_bucket structure is allocated it is
filled with pointers to items from slab (note that uma_bucket is a variable
sized structure).



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