]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - mm/slub.c
slub: Use the objsize from the kmem_cache_cpu structure
[linux-2.6-omap-h63xx.git] / mm / slub.c
index 4b3895cb90ee15b23ff7588e4b3079e405d8d8e1..b49570ca08b5de961332b466a9d2cfe959a84ecf 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -149,13 +149,6 @@ static inline void ClearSlabDebug(struct page *page)
 /* Enable to test recovery from slab corruption on boot */
 #undef SLUB_RESILIENCY_TEST
 
-/*
- * Currently fastpath is not supported if preemption is enabled.
- */
-#if defined(CONFIG_FAST_CMPXCHG_LOCAL) && !defined(CONFIG_PREEMPT)
-#define SLUB_FASTPATH
-#endif
-
 #if PAGE_SHIFT <= 12
 
 /*
@@ -298,32 +291,15 @@ static inline struct kmem_cache_cpu *get_cpu_slab(struct kmem_cache *s, int cpu)
 #endif
 }
 
-/*
- * The end pointer in a slab is special. It points to the first object in the
- * slab but has bit 0 set to mark it.
- *
- * Note that SLUB relies on page_mapping returning NULL for pages with bit 0
- * in the mapping set.
- */
-static inline int is_end(void *addr)
-{
-       return (unsigned long)addr & PAGE_MAPPING_ANON;
-}
-
-static void *slab_address(struct page *page)
-{
-       return page->end - PAGE_MAPPING_ANON;
-}
-
 static inline int check_valid_pointer(struct kmem_cache *s,
                                struct page *page, const void *object)
 {
        void *base;
 
-       if (object == page->end)
+       if (!object)
                return 1;
 
-       base = slab_address(page);
+       base = page_address(page);
        if (object < base || object >= base + s->objects * s->size ||
                (object - base) % s->size) {
                return 0;
@@ -356,8 +332,7 @@ static inline void set_freepointer(struct kmem_cache *s, void *object, void *fp)
 
 /* Scan freelist */
 #define for_each_free_object(__p, __s, __free) \
-       for (__p = (__free); (__p) != page->end; __p = get_freepointer((__s),\
-               __p))
+       for (__p = (__free); __p; __p = get_freepointer((__s), __p))
 
 /* Determine object index from a given position */
 static inline int slab_index(void *p, struct kmem_cache *s, void *addr)
@@ -509,7 +484,7 @@ static void slab_fix(struct kmem_cache *s, char *fmt, ...)
 static void print_trailer(struct kmem_cache *s, struct page *page, u8 *p)
 {
        unsigned int off;       /* Offset of last byte */
-       u8 *addr = slab_address(page);
+       u8 *addr = page_address(page);
 
        print_tracking(s, p);
 
@@ -687,7 +662,7 @@ static int slab_pad_check(struct kmem_cache *s, struct page *page)
        if (!(s->flags & SLAB_POISON))
                return 1;
 
-       start = slab_address(page);
+       start = page_address(page);
        end = start + (PAGE_SIZE << s->order);
        length = s->objects * s->size;
        remainder = end - (start + length);
@@ -755,7 +730,7 @@ static int check_object(struct kmem_cache *s, struct page *page,
                 * of the free objects in this slab. May cause
                 * another error because the object count is now wrong.
                 */
-               set_freepointer(s, p, page->end);
+               set_freepointer(s, p, NULL);
                return 0;
        }
        return 1;
@@ -789,18 +764,18 @@ static int on_freelist(struct kmem_cache *s, struct page *page, void *search)
        void *fp = page->freelist;
        void *object = NULL;
 
-       while (fp != page->end && nr <= s->objects) {
+       while (fp && nr <= s->objects) {
                if (fp == search)
                        return 1;
                if (!check_valid_pointer(s, page, fp)) {
                        if (object) {
                                object_err(s, page, object,
                                        "Freechain corrupt");
-                               set_freepointer(s, object, page->end);
+                               set_freepointer(s, object, NULL);
                                break;
                        } else {
                                slab_err(s, page, "Freepointer corrupt");
-                               page->freelist = page->end;
+                               page->freelist = NULL;
                                page->inuse = s->objects;
                                slab_fix(s, "Freelist cleared");
                                return 0;
@@ -877,7 +852,7 @@ static int alloc_debug_processing(struct kmem_cache *s, struct page *page,
        if (!check_slab(s, page))
                goto bad;
 
-       if (object && !on_freelist(s, page, object)) {
+       if (!on_freelist(s, page, object)) {
                object_err(s, page, object, "Object already allocated");
                goto bad;
        }
@@ -887,7 +862,7 @@ static int alloc_debug_processing(struct kmem_cache *s, struct page *page,
                goto bad;
        }
 
-       if (object && !check_object(s, page, object, 0))
+       if (!check_object(s, page, object, 0))
                goto bad;
 
        /* Success perform special debug activities for allocs */
@@ -906,7 +881,7 @@ bad:
                 */
                slab_fix(s, "Marking all objects used");
                page->inuse = s->objects;
-               page->freelist = page->end;
+               page->freelist = NULL;
        }
        return 0;
 }
@@ -946,7 +921,7 @@ static int free_debug_processing(struct kmem_cache *s, struct page *page,
        }
 
        /* Special debug activities for freeing objects */
-       if (!SlabFrozen(page) && page->freelist == page->end)
+       if (!SlabFrozen(page) && !page->freelist)
                remove_full(s, page);
        if (s->flags & SLAB_STORE_USER)
                set_track(s, object, TRACK_FREE, addr);
@@ -1022,30 +997,11 @@ static unsigned long kmem_cache_flags(unsigned long objsize,
        void (*ctor)(struct kmem_cache *, void *))
 {
        /*
-        * The page->offset field is only 16 bit wide. This is an offset
-        * in units of words from the beginning of an object. If the slab
-        * size is bigger then we cannot move the free pointer behind the
-        * object anymore.
-        *
-        * On 32 bit platforms the limit is 256k. On 64bit platforms
-        * the limit is 512k.
-        *
-        * Debugging or ctor may create a need to move the free
-        * pointer. Fail if this happens.
+        * Enable debugging if selected on the kernel commandline.
         */
-       if (objsize >= 65535 * sizeof(void *)) {
-               BUG_ON(flags & (SLAB_RED_ZONE | SLAB_POISON |
-                               SLAB_STORE_USER | SLAB_DESTROY_BY_RCU));
-               BUG_ON(ctor);
-       } else {
-               /*
-                * Enable debugging if selected on the kernel commandline.
-                */
-               if (slub_debug && (!slub_debug_slabs ||
-                   strncmp(slub_debug_slabs, name,
-                       strlen(slub_debug_slabs)) == 0))
-                               flags |= slub_debug;
-       }
+       if (slub_debug && (!slub_debug_slabs ||
+           strncmp(slub_debug_slabs, name, strlen(slub_debug_slabs)) == 0))
+                       flags |= slub_debug;
 
        return flags;
 }
@@ -1131,7 +1087,6 @@ static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
                SetSlabDebug(page);
 
        start = page_address(page);
-       page->end = start + 1;
 
        if (unlikely(s->flags & SLAB_POISON))
                memset(start, POISON_INUSE, PAGE_SIZE << s->order);
@@ -1143,7 +1098,7 @@ static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
                last = p;
        }
        setup_object(s, page, last);
-       set_freepointer(s, last, page->end);
+       set_freepointer(s, last, NULL);
 
        page->freelist = start;
        page->inuse = 0;
@@ -1159,7 +1114,7 @@ static void __free_slab(struct kmem_cache *s, struct page *page)
                void *p;
 
                slab_pad_check(s, page);
-               for_each_object(p, s, slab_address(page))
+               for_each_object(p, s, page_address(page))
                        check_object(s, page, p, 0);
                ClearSlabDebug(page);
        }
@@ -1169,7 +1124,6 @@ static void __free_slab(struct kmem_cache *s, struct page *page)
                NR_SLAB_RECLAIMABLE : NR_SLAB_UNRECLAIMABLE,
                -pages);
 
-       page->mapping = NULL;
        __free_pages(page, s->order);
 }
 
@@ -1373,7 +1327,7 @@ static void unfreeze_slab(struct kmem_cache *s, struct page *page, int tail)
        ClearSlabFrozen(page);
        if (page->inuse) {
 
-               if (page->freelist != page->end) {
+               if (page->freelist) {
                        add_partial(n, page, tail);
                        stat(c, tail ? DEACTIVATE_TO_TAIL : DEACTIVATE_TO_HEAD);
                } else {
@@ -1417,12 +1371,8 @@ static void deactivate_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
         * Merge cpu freelist into freelist. Typically we get here
         * because both freelists are empty. So this is unlikely
         * to occur.
-        *
-        * We need to use _is_end here because deactivate slab may
-        * be called for a debug slab. Then c->freelist may contain
-        * a dummy pointer.
         */
-       while (unlikely(!is_end(c->freelist))) {
+       while (unlikely(c->freelist)) {
                void **object;
 
                tail = 0;       /* Hot objects. Put the slab first */
@@ -1514,11 +1464,7 @@ static void *__slab_alloc(struct kmem_cache *s,
 {
        void **object;
        struct page *new;
-#ifdef SLUB_FASTPATH
-       unsigned long flags;
 
-       local_irq_save(flags);
-#endif
        if (!c->page)
                goto new_slab;
 
@@ -1528,7 +1474,7 @@ static void *__slab_alloc(struct kmem_cache *s,
        stat(c, ALLOC_REFILL);
 load_freelist:
        object = c->page->freelist;
-       if (unlikely(object == c->page->end))
+       if (unlikely(!object))
                goto another_slab;
        if (unlikely(SlabDebug(c->page)))
                goto debug;
@@ -1536,14 +1482,11 @@ load_freelist:
        object = c->page->freelist;
        c->freelist = object[c->offset];
        c->page->inuse = s->objects;
-       c->page->freelist = c->page->end;
+       c->page->freelist = NULL;
        c->node = page_to_nid(c->page);
 unlock_out:
        slab_unlock(c->page);
        stat(c, ALLOC_SLOWPATH);
-#ifdef SLUB_FASTPATH
-       local_irq_restore(flags);
-#endif
        return object;
 
 another_slab:
@@ -1575,9 +1518,7 @@ new_slab:
                c->page = new;
                goto load_freelist;
        }
-#ifdef SLUB_FASTPATH
-       local_irq_restore(flags);
-#endif
+
        /*
         * No memory available.
         *
@@ -1619,39 +1560,11 @@ static __always_inline void *slab_alloc(struct kmem_cache *s,
 {
        void **object;
        struct kmem_cache_cpu *c;
-
-/*
- * The SLUB_FASTPATH path is provisional and is currently disabled if the
- * kernel is compiled with preemption or if the arch does not support
- * fast cmpxchg operations. There are a couple of coming changes that will
- * simplify matters and allow preemption. Ultimately we may end up making
- * SLUB_FASTPATH the default.
- *
- * 1. The introduction of the per cpu allocator will avoid array lookups
- *    through get_cpu_slab(). A special register can be used instead.
- *
- * 2. The introduction of per cpu atomic operations (cpu_ops) means that
- *    we can realize the logic here entirely with per cpu atomics. The
- *    per cpu atomic ops will take care of the preemption issues.
- */
-
-#ifdef SLUB_FASTPATH
-       c = get_cpu_slab(s, raw_smp_processor_id());
-       do {
-               object = c->freelist;
-               if (unlikely(is_end(object) || !node_match(c, node))) {
-                       object = __slab_alloc(s, gfpflags, node, addr, c);
-                       break;
-               }
-               stat(c, ALLOC_FASTPATH);
-       } while (cmpxchg_local(&c->freelist, object, object[c->offset])
-                                                               != object);
-#else
        unsigned long flags;
 
        local_irq_save(flags);
        c = get_cpu_slab(s, smp_processor_id());
-       if (unlikely(is_end(c->freelist) || !node_match(c, node)))
+       if (unlikely(!c->freelist || !node_match(c, node)))
 
                object = __slab_alloc(s, gfpflags, node, addr, c);
 
@@ -1661,7 +1574,6 @@ static __always_inline void *slab_alloc(struct kmem_cache *s,
                stat(c, ALLOC_FASTPATH);
        }
        local_irq_restore(flags);
-#endif
 
        if (unlikely((gfpflags & __GFP_ZERO) && object))
                memset(object, 0, c->objsize);
@@ -1698,11 +1610,6 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
        void **object = (void *)x;
        struct kmem_cache_cpu *c;
 
-#ifdef SLUB_FASTPATH
-       unsigned long flags;
-
-       local_irq_save(flags);
-#endif
        c = get_cpu_slab(s, raw_smp_processor_id());
        stat(c, FREE_SLOWPATH);
        slab_lock(page);
@@ -1727,20 +1634,17 @@ checks_ok:
         * was not on the partial list before
         * then add it.
         */
-       if (unlikely(prior == page->end)) {
+       if (unlikely(!prior)) {
                add_partial(get_node(s, page_to_nid(page)), page, 1);
                stat(c, FREE_ADD_PARTIAL);
        }
 
 out_unlock:
        slab_unlock(page);
-#ifdef SLUB_FASTPATH
-       local_irq_restore(flags);
-#endif
        return;
 
 slab_empty:
-       if (prior != page->end) {
+       if (prior) {
                /*
                 * Slab still on the partial list.
                 */
@@ -1749,9 +1653,6 @@ slab_empty:
        }
        slab_unlock(page);
        stat(c, FREE_SLAB);
-#ifdef SLUB_FASTPATH
-       local_irq_restore(flags);
-#endif
        discard_slab(s, page);
        return;
 
@@ -1777,39 +1678,11 @@ static __always_inline void slab_free(struct kmem_cache *s,
 {
        void **object = (void *)x;
        struct kmem_cache_cpu *c;
-
-#ifdef SLUB_FASTPATH
-       void **freelist;
-
-       c = get_cpu_slab(s, raw_smp_processor_id());
-       debug_check_no_locks_freed(object, s->objsize);
-       do {
-               freelist = c->freelist;
-               barrier();
-               /*
-                * If the compiler would reorder the retrieval of c->page to
-                * come before c->freelist then an interrupt could
-                * change the cpu slab before we retrieve c->freelist. We
-                * could be matching on a page no longer active and put the
-                * object onto the freelist of the wrong slab.
-                *
-                * On the other hand: If we already have the freelist pointer
-                * then any change of cpu_slab will cause the cmpxchg to fail
-                * since the freelist pointers are unique per slab.
-                */
-               if (unlikely(page != c->page || c->node < 0)) {
-                       __slab_free(s, page, x, addr, c->offset);
-                       break;
-               }
-               object[c->offset] = freelist;
-               stat(c, FREE_FASTPATH);
-       } while (cmpxchg_local(&c->freelist, freelist, object) != freelist);
-#else
        unsigned long flags;
 
        local_irq_save(flags);
-       debug_check_no_locks_freed(object, s->objsize);
        c = get_cpu_slab(s, smp_processor_id());
+       debug_check_no_locks_freed(object, c->objsize);
        if (likely(page == c->page && c->node >= 0)) {
                object[c->offset] = c->freelist;
                c->freelist = object;
@@ -1818,7 +1691,6 @@ static __always_inline void slab_free(struct kmem_cache *s,
                __slab_free(s, page, x, addr, c->offset);
 
        local_irq_restore(flags);
-#endif
 }
 
 void kmem_cache_free(struct kmem_cache *s, void *x)
@@ -1995,7 +1867,7 @@ static void init_kmem_cache_cpu(struct kmem_cache *s,
                        struct kmem_cache_cpu *c)
 {
        c->page = NULL;
-       c->freelist = (void *)PAGE_MAPPING_ANON;
+       c->freelist = NULL;
        c->node = 0;
        c->offset = s->offset / sizeof(void *);
        c->objsize = s->objsize;
@@ -3284,7 +3156,7 @@ static int validate_slab(struct kmem_cache *s, struct page *page,
                                                unsigned long *map)
 {
        void *p;
-       void *addr = slab_address(page);
+       void *addr = page_address(page);
 
        if (!check_slab(s, page) ||
                        !on_freelist(s, page, NULL))
@@ -3567,7 +3439,7 @@ static int add_location(struct loc_track *t, struct kmem_cache *s,
 static void process_slab(struct loc_track *t, struct kmem_cache *s,
                struct page *page, enum track_item alloc)
 {
-       void *addr = slab_address(page);
+       void *addr = page_address(page);
        DECLARE_BITMAP(map, s->objects);
        void *p;
 
@@ -3676,7 +3548,7 @@ enum slab_stat_type {
 #define SO_CPU         (1 << SL_CPU)
 #define SO_OBJECTS     (1 << SL_OBJECTS)
 
-static unsigned long slab_objects(struct kmem_cache *s,
+static unsigned long show_slab_objects(struct kmem_cache *s,
                        char *buf, unsigned long flags)
 {
        unsigned long total = 0;
@@ -3839,25 +3711,25 @@ SLAB_ATTR_RO(aliases);
 
 static ssize_t slabs_show(struct kmem_cache *s, char *buf)
 {
-       return slab_objects(s, buf, SO_FULL|SO_PARTIAL|SO_CPU);
+       return show_slab_objects(s, buf, SO_FULL|SO_PARTIAL|SO_CPU);
 }
 SLAB_ATTR_RO(slabs);
 
 static ssize_t partial_show(struct kmem_cache *s, char *buf)
 {
-       return slab_objects(s, buf, SO_PARTIAL);
+       return show_slab_objects(s, buf, SO_PARTIAL);
 }
 SLAB_ATTR_RO(partial);
 
 static ssize_t cpu_slabs_show(struct kmem_cache *s, char *buf)
 {
-       return slab_objects(s, buf, SO_CPU);
+       return show_slab_objects(s, buf, SO_CPU);
 }
 SLAB_ATTR_RO(cpu_slabs);
 
 static ssize_t objects_show(struct kmem_cache *s, char *buf)
 {
-       return slab_objects(s, buf, SO_FULL|SO_PARTIAL|SO_CPU|SO_OBJECTS);
+       return show_slab_objects(s, buf, SO_FULL|SO_PARTIAL|SO_CPU|SO_OBJECTS);
 }
 SLAB_ATTR_RO(objects);