From owner-freebsd-hackers@FreeBSD.ORG Tue Mar 2 08:27:13 2010 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7A788106564A for ; Tue, 2 Mar 2010 08:27:13 +0000 (UTC) (envelope-from simon@comsys.ntu-kpi.kiev.ua) Received: from comsys.ntu-kpi.kiev.ua (comsys.ntu-kpi.kiev.ua [77.47.192.42]) by mx1.freebsd.org (Postfix) with ESMTP id 2DDBC8FC19 for ; Tue, 2 Mar 2010 08:27:12 +0000 (UTC) Received: from pm513-1.comsys.ntu-kpi.kiev.ua ([10.18.52.101]) by comsys.ntu-kpi.kiev.ua with esmtpsa (TLSv1:AES256-SHA:256) (Exim 4.63) (envelope-from ) id 1NmNRf-0001xy-BB; Tue, 02 Mar 2010 10:27:11 +0200 Received: by pm513-1.comsys.ntu-kpi.kiev.ua (Postfix, from userid 1001) id 56C601CC0B; Tue, 2 Mar 2010 10:27:11 +0200 (EET) Date: Tue, 2 Mar 2010 10:27:11 +0200 From: Andrey Simonenko To: Dan Nelson Message-ID: <20100302082711.GA1663@pm513-1.comsys.ntu-kpi.kiev.ua> References: <178848.53651.qm@web112006.mail.gq1.yahoo.com> <20100302032440.GV70798@dan.emsphone.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20100302032440.GV70798@dan.emsphone.com> User-Agent: Mutt/1.5.20 (2009-06-14) X-Authenticated-User: simon@comsys.ntu-kpi.kiev.ua X-Authenticator: plain X-Invalid-HELO: Host impersonating [comsys.ntu-kpi.kiev.ua] X-Sender-Verify: SUCCEEDED (sender exists & accepts mail) X-Exim-Version: 4.63 (build at 06-Jan-2007 23:14:37) X-Date: 2010-03-02 10:27:11 X-Connected-IP: 10.18.52.101:58293 X-Message-Linecount: 34 X-Body-Linecount: 17 X-Message-Size: 1729 X-Body-Size: 988 Cc: freebsd-hackers@freebsd.org, shrivatsan@gmail.com, Shrivatsan Subject: Re: kernel malloc() and free() X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 02 Mar 2010 08:27:13 -0000 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).