[RFC][10/11][MANUX] Suggestion : kmalloc()

From: Emmanuel Colbus
Date: Tue Apr 15 2014 - 10:01:40 EST


Finally, since cloning the Linux kernel gave me some ideas, I would like
to give you a couple of suggestions of my own. Feel free to do what you
want with them.

First, I'm not sure whether this has been done or not, but I would like
to suggest you to mark your kernel memory allocator with gcc's malloc
attribute (and mark kfree() as taking void*, not const void*).

Yes, I know, it apparently doesn't corresponds with what the malloc
attribute's specification covers, since there are still pointers to the
returned memory area somewhere else in the kernel. However, I would like
to point out that this isn't relevant : in *any* malloc-like
implementation, there will be such pointers somewhere in the allocator.
What's important is whether they are such pointers *in the specific
compilation units from which the allocator is called*.

And since the allocator can't call itself (well, I'm not sure for the
Linux one, of course, but this happens to be true in mine), leaving
kmalloc in a separate file allows setting this attribute, which gives a
little speed boost to the code (that's what it did to my kernel when I
did it). That's because it allows the compiler to know that two areas
allocated with such a function *cannot* alias each other, which helps it
optimize the memory accesses to them.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/