lkml.org 
[lkml]   [2006]   [Apr]   [26]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH] likely cleanup: remove unlikely for kfree(NULL)
On Wed, 26 April 2006 10:27:18 +0200, Arjan van de Ven wrote:
> > > what I would like is kfree to become an inline wrapper that does the
> > > null check inline, that way gcc can optimize it out (and it will in 4.1
> > > with the VRP pass) if gcc can prove it's not NULL.

On Wed, 2006-04-26 at 12:05 +0200, Jörn Engel wrote:
> > How well can gcc optimize this case?

On Wed, 26 Apr 2006, Arjan van de Ven wrote:
> if you deref'd the pointer it'll optimize it away (assuming a new enough
> gcc, like 4.1)

Here are the numbers for allyesconfig on my setup.

Pekka

gcc version 3.4.5 (Gentoo 3.4.5-r1, ssp-3.4.5-1.0, pie-8.7.9)

text data bss dec hex filename
24910301 6946478 2092332 33949111 20605b7 vmlinux
24934157 6946530 2092332 33973019 206631b vmlinux-inline-kfree


diff --git a/include/linux/slab.h b/include/linux/slab.h
index 3af03b1..1b4b3bb 100644
--- a/include/linux/slab.h
+++ b/include/linux/slab.h
@@ -148,7 +148,14 @@ static inline void *kcalloc(size_t n, si
return kzalloc(n * size, flags);
}

-extern void kfree(const void *);
+extern void __kfree(const void *);
+
+static inline void kfree(const void *p)
+{
+ if (unlikely(p))
+ __kfree(p);
+}
+
extern unsigned int ksize(const void *);

#ifdef CONFIG_NUMA
diff --git a/mm/slab.c b/mm/slab.c
index e6ef9bd..1f63787 100644
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3367,7 +3367,7 @@ void kmem_cache_free(struct kmem_cache *
EXPORT_SYMBOL(kmem_cache_free);

/**
- * kfree - free previously allocated memory
+ * __kfree - free previously allocated memory
* @objp: pointer returned by kmalloc.
*
* If @objp is NULL, no operation is performed.
@@ -3375,13 +3375,11 @@ EXPORT_SYMBOL(kmem_cache_free);
* Don't free memory not originally allocated by kmalloc()
* or you will run into trouble.
*/
-void kfree(const void *objp)
+void __kfree(const void *objp)
{
struct kmem_cache *c;
unsigned long flags;

- if (unlikely(!objp))
- return;
local_irq_save(flags);
kfree_debugcheck(objp);
c = virt_to_cache(objp);
@@ -3389,7 +3387,7 @@ void kfree(const void *objp)
__cache_free(c, (void *)objp);
local_irq_restore(flags);
}
-EXPORT_SYMBOL(kfree);
+EXPORT_SYMBOL(__kfree);

#ifdef CONFIG_SMP
/**
-
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/
\
 
 \ /
  Last update: 2006-04-26 12:59    [W:0.075 / U:0.656 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site