]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - mm/slob.c
ARM: OMAP: clk_disable_unused: init section mismatch
[linux-2.6-omap-h63xx.git] / mm / slob.c
index c89ef116d7aaf99e48d564031c57a7a85dc45081..5bc2ceb692ec94925340e0b65ce4cb8695e2cee1 100644 (file)
--- a/mm/slob.c
+++ b/mm/slob.c
@@ -293,6 +293,7 @@ static void *slob_page_alloc(struct slob_page *sp, size_t size, int align)
 static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
 {
        struct slob_page *sp;
+       struct list_head *prev;
        slob_t *b = NULL;
        unsigned long flags;
 
@@ -307,12 +308,22 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
                if (node != -1 && page_to_nid(&sp->page) != node)
                        continue;
 #endif
+               /* Enough room on this page? */
+               if (sp->units < SLOB_UNITS(size))
+                       continue;
 
-               if (sp->units >= SLOB_UNITS(size)) {
-                       b = slob_page_alloc(sp, size, align);
-                       if (b)
-                               break;
-               }
+               /* Attempt to alloc */
+               prev = sp->list.prev;
+               b = slob_page_alloc(sp, size, align);
+               if (!b)
+                       continue;
+
+               /* Improve fragment distribution and reduce our average
+                * search time by starting our next search here. (see
+                * Knuth vol 1, sec 2.5, pg 449) */
+               if (free_slob_pages.next != prev->next)
+                       list_move_tail(&free_slob_pages, prev->next);
+               break;
        }
        spin_unlock_irqrestore(&slob_lock, flags);
 
@@ -349,7 +360,7 @@ static void slob_free(void *block, int size)
        slobidx_t units;
        unsigned long flags;
 
-       if (ZERO_OR_NULL_PTR(block))
+       if (unlikely(ZERO_OR_NULL_PTR(block)))
                return;
        BUG_ON(!size);
 
@@ -455,7 +466,7 @@ void kfree(const void *block)
 {
        struct slob_page *sp;
 
-       if (ZERO_OR_NULL_PTR(block))
+       if (unlikely(ZERO_OR_NULL_PTR(block)))
                return;
 
        sp = (struct slob_page *)virt_to_page(block);
@@ -473,7 +484,8 @@ size_t ksize(const void *block)
 {
        struct slob_page *sp;
 
-       if (ZERO_OR_NULL_PTR(block))
+       BUG_ON(!block);
+       if (unlikely(block == ZERO_SIZE_PTR))
                return 0;
 
        sp = (struct slob_page *)virt_to_page(block);
@@ -487,13 +499,12 @@ struct kmem_cache {
        unsigned int size, align;
        unsigned long flags;
        const char *name;
-       void (*ctor)(void *, struct kmem_cache *, unsigned long);
+       void (*ctor)(struct kmem_cache *, void *);
 };
 
 struct kmem_cache *kmem_cache_create(const char *name, size_t size,
        size_t align, unsigned long flags,
-       void (*ctor)(void*, struct kmem_cache *, unsigned long),
-       void (*dtor)(void*, struct kmem_cache *, unsigned long))
+       void (*ctor)(struct kmem_cache *, void *))
 {
        struct kmem_cache *c;
 
@@ -537,7 +548,7 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
                b = slob_new_page(flags, get_order(c->size), node);
 
        if (c->ctor)
-               c->ctor(b, c, 0);
+               c->ctor(c, b);
 
        return b;
 }