From owner-freebsd-hackers@FreeBSD.ORG Tue Feb 28 22:00:21 2006 Return-Path: X-Original-To: hackers@freebsd.org Delivered-To: freebsd-hackers@FreeBSD.ORG Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 05E6316A420 for ; Tue, 28 Feb 2006 22:00:21 +0000 (GMT) (envelope-from rwatson@FreeBSD.org) Received: from cyrus.watson.org (cyrus.watson.org [209.31.154.42]) by mx1.FreeBSD.org (Postfix) with ESMTP id 64D1D43D46 for ; Tue, 28 Feb 2006 22:00:20 +0000 (GMT) (envelope-from rwatson@FreeBSD.org) Received: from fledge.watson.org (fledge.watson.org [209.31.154.41]) by cyrus.watson.org (Postfix) with ESMTP id 4E1A746B98; Tue, 28 Feb 2006 17:00:00 -0500 (EST) Date: Tue, 28 Feb 2006 22:04:41 +0000 (GMT) From: Robert Watson X-X-Sender: robert@fledge.watson.org To: Rohit Jalan In-Reply-To: <20060227104341.GA6671@desk01.n2.purpe.com> Message-ID: <20060228215910.S2248@fledge.watson.org> References: <20060227104341.GA6671@desk01.n2.purpe.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: hackers@freebsd.org Subject: Re: UMA zone allocator memory fragmentation questions 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, 28 Feb 2006 22:00:21 -0000 On Mon, 27 Feb 2006, Rohit Jalan wrote: > Is there an upper limit on the amount of fragmentation / wastage that can > occur in a UMA zone? > > Is there a method to know the total number of pages used by a UMA zone at > some instance of time? Hey there Rohit, UMA allocates pages retrieved from VM as "slabs". It's behavior depends a bit on how large the allocated object is, as it's a question of packing objects into page-sized slabs for small objects, or packing objects into sets of pages making up a slab for larger objects. You can programmatically access information on UMA using libmemstat(3), which allows you to do things like query the current object cache size, total lifetime allocations for the zone, allocation failure count, sizes of per-cpu caches, etc. You may want to take a glance at the source code for vmstat -z and netstat -m for examples of it in use. You'll notice, for example, that netstat -m reports on both the mbufs in active use, and also the memory allocated to mbufs in the percpu + zone caches, since that memory is also (for the time being) committed to the mbuf allocator. The mbuf code is a little hard to follow because there are actually two zones that allocate mbufs, the mbuf zone and the packet secondary zone, so let me know if you have any questions. If you want to dig down a bit more, uma_int.h includes the keg and zone definitions, and you can extracting information like the page maximum, the number of items per page or pages per item, etc. If there's useful information that you need but isn't currently exposed by libmemstat, we can add it easily enough. You might also be interested in some of the tools at http://www.watson.org/~robert/freebsd/libmemstat/ Include memtop, which is basically an activity monitor for kernel memory types. As an FYI, kernel malloc is wrapped around UMA, so if you view both malloc and UMA stats at once, there is double-counting. Robert N M Watson