Re: kernel memory allocations alignment

From: Andi Kleen (
Date: Sun Feb 04 2001 - 12:00:05 EST

"Hen, Shmulik" <> 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.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
Please read the FAQ at

This archive was generated by hypermail 2b29 : Wed Feb 07 2001 - 21:00:19 EST