Re: kmalloc() alignment

From: Philipp Rumpf (prumpf@mandrakesoft.com)
Date: Tue Mar 06 2001 - 03:59:31 EST


On Sun, Mar 04, 2001 at 10:34:31PM +0000, Alan Cox wrote:
> > Does kmalloc() make any guarantees of the alignment of allocated
> > blocks? Will the returned block always be 4-, 8- or 16-byte
> > aligned, for example?
>
> There are people who assume 16byte alignment guarantees. I dont think anyone
> has formally specified the guarantee beyond 4 bytes tho

Userspace malloc is "suitably aligned for any kind of variable", so I think
expecting 8 bytes alignment (long long on 32-bit platforms) should be okay.

>From reading the code it seems as though we actually use L1_CACHE_BYTES,
and I think it might be a good idea to document the current behaviour (as
long as there's no good reason to change it ?)

diff -ur linux/mm/slab.c linux-prumpf/mm/slab.c
--- linux/mm/slab.c Tue Mar 6 00:54:38 2001
+++ linux-prumpf/mm/slab.c Tue Mar 6 01:00:47 2001
@@ -1525,9 +1525,10 @@
  * @flags: the type of memory to allocate.
  *
  * kmalloc is the normal method of allocating memory
- * in the kernel. Note that the @size parameter must be less than or
- * equals to %KMALLOC_MAXSIZE and the caller must ensure this. The @flags
- * argument may be one of:
+ * in the kernel. It returns a pointer (aligned to a hardware cache line
+ * boundary) to the allocated memory, or %NULL in case of failure. Note that
+ * the @size parameter must be less than or equal to %KMALLOC_MAXSIZE and
+ * the caller must ensure this. The @flags argument may be one of:
  *
  * %GFP_USER - Allocate memory on behalf of user. May sleep.
  *
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/



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