Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 12 Feb 2009 12:21:24 -0800
From:      Marcel Moolenaar <xcllnt@mac.com>
To:        Jille Timmermans <jille@quis.cx>
Cc:        freebsd-hackers@freebsd.org, Julian Stacey <jhs@berklix.org>, Andrew Brampton <brampton+freebsd-hackers@gmail.com>
Subject:   Re: pahole - Finding holes in kernel structs
Message-ID:  <B9DCCF52-36A3-4331-B439-6CBF88158C44@mac.com>
In-Reply-To: <49944F8F.5080104@quis.cx>
References:  <200902121549.n1CFnLdt002361@fire.js.berklix.net> <49944F8F.5080104@quis.cx>

next in thread | previous in thread | raw e-mail | index | archive | help

On Feb 12, 2009, at 8:34 AM, Jille Timmermans wrote:

> Julian Stacey schreef:
>>> 1) Is it worth my time trying to rearrange structs?
>> I wondered whether as a sensitivity test, some version of gcc (or
>> its competitor ?) might have capability to automatically re-order
>> variables ?  but found nothing in man gcc "Optimization Options".
> There is a __packed attribute, I don't know what it exactly does and  
> whether it is an improvement.
>

__packed is always a gross pessimization. The side-effect of
packing a structure is that the alignment of the structure
drops to 1. That means that any field will be read 1 byte at
a time and reconstructed by logical operations.

For best results, __packed should be used with __aligned(X),
in case __packed is needed of course to address the side-
effect. Of course multi-byte fields that are unaligned in
the structure as the result of packing, will still be read
in parts.

In other words: don't use __packed when you don't have to.

-- 
Marcel Moolenaar
xcllnt@mac.com






Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?B9DCCF52-36A3-4331-B439-6CBF88158C44>