[lkml]   [2014]   [Apr]   [15]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
Messages in this thread
Subject[RFC][10/11][MANUX] Suggestion : kmalloc()
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.

 \ /
  Last update: 2014-04-16 07:01    [W:0.039 / U:2.516 seconds]
©2003-2018 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site