From owner-freebsd-hackers@FreeBSD.ORG Thu Feb 12 14:08:24 2009 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 9174B1065672 for ; Thu, 12 Feb 2009 14:08:24 +0000 (UTC) (envelope-from brampton@gmail.com) Received: from mail-ew0-f21.google.com (mail-ew0-f21.google.com [209.85.219.21]) by mx1.freebsd.org (Postfix) with ESMTP id F16678FC25 for ; Thu, 12 Feb 2009 14:08:23 +0000 (UTC) (envelope-from brampton@gmail.com) Received: by ewy14 with SMTP id 14so663602ewy.19 for ; Thu, 12 Feb 2009 06:08:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:sender:received:date :x-google-sender-auth:message-id:subject:from:to:content-type :content-transfer-encoding; bh=ds+Why8ppsRdR+K6zfp+LNKZRb8F+n1aq7396uHipV8=; b=CGSPjEmxyMMqepTCl+FmRP6pnlLQag3PxsOPC+aTAlMxGwDyeFx8PbN0ntVZX/e/Y9 C8RxrJf0km8MBq9DXgzuf6vQULn9a1bijBn3GT2Fmr118cLZ4RMV1+urWAd1qh2kLTeY Ddd2LJ8fCTMWBnAVF0YmAIwVmBjQUni8VJOg4= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:sender:date:x-google-sender-auth:message-id:subject :from:to:content-type:content-transfer-encoding; b=eoX7+wpv3bFQSR+zP45rCvaM/Qgzwj641wEwbcjB+KyTnXJBknUwrd7L7eVFePR0Jp U3XoEXQoRntXGMhXtgdsvp3CNJ+LIFl2SWnn7r+Il5cxLFPuXzuWIPoWjsE1BVcT5MVz Q/nZyY5fAoeooAxB9/nh0JZDftkWleaSJumEQ= MIME-Version: 1.0 Sender: brampton@gmail.com Received: by 10.210.66.13 with SMTP id o13mr203497eba.157.1234447702498; Thu, 12 Feb 2009 06:08:22 -0800 (PST) Date: Thu, 12 Feb 2009 14:08:22 +0000 X-Google-Sender-Auth: b7a73b16aebe9d38 Message-ID: From: Andrew Brampton To: freebsd-hackers@freebsd.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Subject: pahole - Finding holes in kernel structs 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: Thu, 12 Feb 2009 14:08:25 -0000 I found this useful tool called pahole[1]. It basically finds holes within structs, so for example on my 64bit machine this struct: struct test { int foo; const char *bar; int blah; } Would have a hole between foo and bar of 4 bytes because both for and bar have been aligned on a 8 byte boundary, and the struct would also have 4 bytes of padding on the end. However, if I simply moved blah between foo and bar then the struct has shrunk by 8 bytes, which could be a good thing. This could also help keep structs within single cache lines, and just generally keep memory usage to a minimum when the struct is used many times (for example in an array). So I ran the tool pahole over a 7.1 FreeBSD Kernel, and found that many of the struct had holes, and some of which could be rearranged to fill the gap. I've made the list available here[2]. So my questions are two fold: 1) Is it worth my time trying to rearrange structs? If so do you think many of my patches would be accepted? 2) Is there a way to find out the most heavily used structs? There are ~3600 structs, and ~2000 holes, it might be a waste of my time fixing the structs which are only used once. thanks Andrew [1] http://lwn.net/Articles/206805/ [2] http://bramp.net/projects/kernel.pahole.bz2 (~260kB)