]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/commitdiff
Slab allocators: consolidate code for krealloc in mm/util.c
authorChristoph Lameter <clameter@sgi.com>
Tue, 17 Jul 2007 11:03:21 +0000 (04:03 -0700)
committerLinus Torvalds <torvalds@woody.linux-foundation.org>
Tue, 17 Jul 2007 17:23:01 +0000 (10:23 -0700)
The size of a kmalloc object is readily available via ksize().  ksize is
provided by all allocators and thus we can implement krealloc in a generic
way.

Implement krealloc in mm/util.c and drop slab specific implementations of
krealloc.

Signed-off-by: Christoph Lameter <clameter@sgi.com>
Acked-by: Pekka Enberg <penberg@cs.helsinki.fi>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
mm/slab.c
mm/slob.c
mm/slub.c
mm/util.c

index a453383333fc02f4c9bfc342bedb88eeb454f685..4bd8a53091b745174dd645564088411d5b002319 100644 (file)
--- a/mm/slab.c
+++ b/mm/slab.c
@@ -3725,52 +3725,6 @@ void *__kmalloc(size_t size, gfp_t flags)
 EXPORT_SYMBOL(__kmalloc);
 #endif
 
-/**
- * krealloc - reallocate memory. The contents will remain unchanged.
- * @p: object to reallocate memory for.
- * @new_size: how many bytes of memory are required.
- * @flags: the type of memory to allocate.
- *
- * The contents of the object pointed to are preserved up to the
- * lesser of the new and old sizes.  If @p is %NULL, krealloc()
- * behaves exactly like kmalloc().  If @size is 0 and @p is not a
- * %NULL pointer, the object pointed to is freed.
- */
-void *krealloc(const void *p, size_t new_size, gfp_t flags)
-{
-       struct kmem_cache *cache, *new_cache;
-       void *ret;
-
-       if (unlikely(!p))
-               return kmalloc_track_caller(new_size, flags);
-
-       if (unlikely(!new_size)) {
-               kfree(p);
-               return NULL;
-       }
-
-       cache = virt_to_cache(p);
-       new_cache = __find_general_cachep(new_size, flags);
-
-       /*
-        * If new size fits in the current cache, bail out.
-        */
-       if (likely(cache == new_cache))
-               return (void *)p;
-
-       /*
-        * We are on the slow-path here so do not use __cache_alloc
-        * because it bloats kernel text.
-        */
-       ret = kmalloc_track_caller(new_size, flags);
-       if (ret) {
-               memcpy(ret, p, min(new_size, ksize(p)));
-               kfree(p);
-       }
-       return ret;
-}
-EXPORT_SYMBOL(krealloc);
-
 /**
  * kmem_cache_free - Deallocate an object
  * @cachep: The cache the allocation was from.
index b4899079d8b00e32660f8c36437c3b558bef4823..154e7bdf3544c7ad1572c20dcafa72b47c8fadb1 100644 (file)
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -446,39 +446,6 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
 }
 EXPORT_SYMBOL(__kmalloc_node);
 
-/**
- * krealloc - reallocate memory. The contents will remain unchanged.
- *
- * @p: object to reallocate memory for.
- * @new_size: how many bytes of memory are required.
- * @flags: the type of memory to allocate.
- *
- * The contents of the object pointed to are preserved up to the
- * lesser of the new and old sizes.  If @p is %NULL, krealloc()
- * behaves exactly like kmalloc().  If @size is 0 and @p is not a
- * %NULL pointer, the object pointed to is freed.
- */
-void *krealloc(const void *p, size_t new_size, gfp_t flags)
-{
-       void *ret;
-
-       if (unlikely(!p))
-               return kmalloc_track_caller(new_size, flags);
-
-       if (unlikely(!new_size)) {
-               kfree(p);
-               return NULL;
-       }
-
-       ret = kmalloc_track_caller(new_size, flags);
-       if (ret) {
-               memcpy(ret, p, min(new_size, ksize(p)));
-               kfree(p);
-       }
-       return ret;
-}
-EXPORT_SYMBOL(krealloc);
-
 void kfree(const void *block)
 {
        struct slob_page *sp;
index a18708821c1e2264eea914a4f45c2bafec04337e..1b0a95d75dbb8f57d2187875212a11ca13e94fb9 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -2467,43 +2467,6 @@ int kmem_cache_shrink(struct kmem_cache *s)
 }
 EXPORT_SYMBOL(kmem_cache_shrink);
 
-/**
- * krealloc - reallocate memory. The contents will remain unchanged.
- * @p: object to reallocate memory for.
- * @new_size: how many bytes of memory are required.
- * @flags: the type of memory to allocate.
- *
- * The contents of the object pointed to are preserved up to the
- * lesser of the new and old sizes.  If @p is %NULL, krealloc()
- * behaves exactly like kmalloc().  If @size is 0 and @p is not a
- * %NULL pointer, the object pointed to is freed.
- */
-void *krealloc(const void *p, size_t new_size, gfp_t flags)
-{
-       void *ret;
-       size_t ks;
-
-       if (unlikely(!p || p == ZERO_SIZE_PTR))
-               return kmalloc(new_size, flags);
-
-       if (unlikely(!new_size)) {
-               kfree(p);
-               return ZERO_SIZE_PTR;
-       }
-
-       ks = ksize(p);
-       if (ks >= new_size)
-               return (void *)p;
-
-       ret = kmalloc(new_size, flags);
-       if (ret) {
-               memcpy(ret, p, min(new_size, ks));
-               kfree(p);
-       }
-       return ret;
-}
-EXPORT_SYMBOL(krealloc);
-
 /********************************************************************
  *                     Basic setup of slabs
  *******************************************************************/
index ace2aea69f1a834ca7526a1bfa4070205b82579e..18396ea63ee694aa3bcadf86ee67a5a425e6423f 100644 (file)
--- a/mm/util.c
+++ b/mm/util.c
@@ -58,6 +58,40 @@ void *kmemdup(const void *src, size_t len, gfp_t gfp)
 }
 EXPORT_SYMBOL(kmemdup);
 
+/**
+ * krealloc - reallocate memory. The contents will remain unchanged.
+ * @p: object to reallocate memory for.
+ * @new_size: how many bytes of memory are required.
+ * @flags: the type of memory to allocate.
+ *
+ * The contents of the object pointed to are preserved up to the
+ * lesser of the new and old sizes.  If @p is %NULL, krealloc()
+ * behaves exactly like kmalloc().  If @size is 0 and @p is not a
+ * %NULL pointer, the object pointed to is freed.
+ */
+void *krealloc(const void *p, size_t new_size, gfp_t flags)
+{
+       void *ret;
+       size_t ks;
+
+       if (unlikely(!new_size)) {
+               kfree(p);
+               return NULL;
+       }
+
+       ks = ksize(p);
+       if (ks >= new_size)
+               return (void *)p;
+
+       ret = kmalloc_track_caller(new_size, flags);
+       if (ret) {
+               memcpy(ret, p, min(new_size, ks));
+               kfree(p);
+       }
+       return ret;
+}
+EXPORT_SYMBOL(krealloc);
+
 /*
  * strndup_user - duplicate an existing string from user space
  *