* RE: kernel memory allocations alignment
@ 2001-02-04 16:15 Hen, Shmulik
2001-02-04 17:00 ` Andi Kleen
0 siblings, 1 reply; 5+ messages in thread
From: Hen, Shmulik @ 2001-02-04 16:15 UTC (permalink / raw)
To: 'Manfred', Hen, Shmulik; +Cc: 'LKML'
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
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.
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 ?
Thanks,
Shmulik Hen
Software Engineer
Linux Advanced Networking Services
Intel Network Communications Group
Jerusalem, Israel
-----Original Message-----
From: Manfred [mailto:manfred@colorfullife.com]
Sent: Sunday, February 04, 2001 5:56 PM
To: Hen, Shmulik
Cc: 'LKML'
Subject: Re: kernel memory allocations alignment
"Hen, Shmulik" wrote:
>
> When using kmalloc(size_t size), do I get a guaranty that the memory
region
> allocated is aligned according to the size specified ?
> More to the point, if I call kmalloc for type int on an IA64 architecture
is
> the pointer going to be 8 bytes aligned ?
>
Yes, kmalloc results are always 'sizeof(void*)' aligned.
Do you have stricter alignment requirements?
--
Manfred
-
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/
^ permalink raw reply [flat|nested] 5+ messages in thread* Re: kernel memory allocations alignment
2001-02-04 16:15 kernel memory allocations alignment Hen, Shmulik
@ 2001-02-04 17:00 ` Andi Kleen
2001-02-04 18:17 ` Johannes Erdfelt
0 siblings, 1 reply; 5+ messages in thread
From: Andi Kleen @ 2001-02-04 17:00 UTC (permalink / raw)
To: Hen, Shmulik; +Cc: linux-kernel
"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/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: kernel memory allocations alignment
2001-02-04 17:00 ` Andi Kleen
@ 2001-02-04 18:17 ` Johannes Erdfelt
0 siblings, 0 replies; 5+ messages in thread
From: Johannes Erdfelt @ 2001-02-04 18:17 UTC (permalink / raw)
To: Andi Kleen; +Cc: Hen, Shmulik, linux-kernel
On Sun, Feb 04, 2001, Andi Kleen <ak@suse.de> wrote:
> "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.
That ia64 port now supports unaligned accesses in kernel mode. (via the
latest patch)
It was more a debugging aid in the beginning than inability to do.
> Of course it'll always be much faster to use aligned accesses that do not
> need an exception.
Absolutely.
JE
-
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/
^ permalink raw reply [flat|nested] 5+ messages in thread
* kernel memory allocations alignment
@ 2001-02-04 14:19 Hen, Shmulik
2001-02-04 15:56 ` Manfred
0 siblings, 1 reply; 5+ messages in thread
From: Hen, Shmulik @ 2001-02-04 14:19 UTC (permalink / raw)
To: 'LKML'
Hello,
When using kmalloc(size_t size), do I get a guaranty that the memory region
allocated is aligned according to the size specified ?
More to the point, if I call kmalloc for type int on an IA64 architecture is
the pointer going to be 8 bytes aligned ?
Shmulik Hen
Software Engineer
Linux Advanced Networking Services
Network Communications Group, Israel (NCGj)
Intel Corporation Ltd.
-
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/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: kernel memory allocations alignment
2001-02-04 14:19 Hen, Shmulik
@ 2001-02-04 15:56 ` Manfred
0 siblings, 0 replies; 5+ messages in thread
From: Manfred @ 2001-02-04 15:56 UTC (permalink / raw)
To: Hen, Shmulik; +Cc: 'LKML'
"Hen, Shmulik" wrote:
>
> When using kmalloc(size_t size), do I get a guaranty that the memory region
> allocated is aligned according to the size specified ?
> More to the point, if I call kmalloc for type int on an IA64 architecture is
> the pointer going to be 8 bytes aligned ?
>
Yes, kmalloc results are always 'sizeof(void*)' aligned.
Do you have stricter alignment requirements?
--
Manfred
-
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/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2001-02-04 18:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-02-04 16:15 kernel memory allocations alignment Hen, Shmulik
2001-02-04 17:00 ` Andi Kleen
2001-02-04 18:17 ` Johannes Erdfelt
-- strict thread matches above, loose matches on Subject: below --
2001-02-04 14:19 Hen, Shmulik
2001-02-04 15:56 ` Manfred
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox