From owner-freebsd-hackers@FreeBSD.ORG Fri Feb 13 02:41:28 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 D200E10656DD for ; Fri, 13 Feb 2009 02:41:28 +0000 (UTC) (envelope-from gad@FreeBSD.org) Received: from smtp6.server.rpi.edu (smtp6.server.rpi.edu [128.113.2.226]) by mx1.freebsd.org (Postfix) with ESMTP id 945B18FC0A for ; Fri, 13 Feb 2009 02:41:28 +0000 (UTC) (envelope-from gad@FreeBSD.org) Received: from [128.113.24.47] (gilead.netel.rpi.edu [128.113.24.47]) by smtp6.server.rpi.edu (8.13.1/8.13.1) with ESMTP id n1D2fO06016122; Thu, 12 Feb 2009 21:41:26 -0500 Mime-Version: 1.0 Message-Id: In-Reply-To: References: Date: Thu, 12 Feb 2009 21:41:24 -0500 To: Andrew Brampton , freebsd-hackers@FreeBSD.org From: Garance A Drosehn Content-Type: text/plain; charset="us-ascii" ; format="flowed" X-Bayes-Prob: 0.0001 (Score 0) X-RPI-SA-Score: 0.10 () [Hold at 20.00] COMBINED_FROM X-CanItPRO-Stream: outgoing X-Canit-Stats-ID: Bayes signature not available X-Scanned-By: CanIt (www . roaringpenguin . com) on 128.113.2.226 Cc: Subject: Re: 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: Fri, 13 Feb 2009 02:41:29 -0000 At 2:08 PM +0000 2/12/09, Andrew Brampton wrote: >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? In most cases, re-arranging things is probably not worth it. That's just my opinion, though. >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. I used a similar tool (which I wrote myself) when making some changes to 'struct kinfo_proc' some time ago. The first issue which comes up is that a hole on one hardware platform may not be a hole on other platforms. I think it is perhaps useful to shuffle around fields in a struct if you're doing some *other* change at the same time. A tool like this pahole program seems like a good idea at those times. And I do think it can be useful to document the holes which exist, especially if you take the time to figure out what is happening on different platforms which have different alignment requirements. -- Garance Alistair Drosehn = drosehn@rpi.edu Senior Systems Programmer or gad@FreeBSD.org Rensselaer Polytechnic Institute; Troy, NY; USA