public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC][10/11][MANUX] Suggestion : kmalloc()
@ 2014-04-15 13:43 Emmanuel Colbus
  0 siblings, 0 replies; only message in thread
From: Emmanuel Colbus @ 2014-04-15 13:43 UTC (permalink / raw)
  To: linux-kernel

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.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-04-15 14:00 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-04-15 13:43 [RFC][10/11][MANUX] Suggestion : kmalloc() Emmanuel Colbus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox