Re: kernel memory allocations alignment

Andi Kleen (ak@suse.de)
04 Feb 2001 18:00:05 +0100


"Hen, Shmulik" <shmulik.hen@intel.com> writes:

> Actually yes. We were warned that on IA64 architecture the system will halt
> when accessing any type of variable via a pointer if the pointer does not
> contain an aligned address matching that type. Until now we were using a

That will need to be fixed with a handler anyways, the network stack requires
unaligned accesses. If the IA64 port doesn't handle that it it's buggy and
trivially remotely crashable.

Of course it'll always be much faster to use aligned accesses that do not
need an exception.

> method of receiving a pointer to an array, casting it to a pointer of a
> struct (packed with #pragma pack(1) ) ,and retrieving fields directly from
> it with pointers.
> It seems we cannot do that any more and were wondering what are the
> alternatives.

get_unaligned() or a memcpy to a local variable is the standard method.
get_unaligned is normally slightly faster than relying on an unalignment
exception handler.

> One way we could think of is forget the packing and rearrange the fields in
> the struct in descending order so they all come out aligned, but we didn't
> know for sure if the first one will be aligned too.
>
> Will that work ?

Yes, it's the best solution.

-Andi
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
Please read the FAQ at http://www.tux.org/lkml/