radeon: Take drm struct_mutex over reclocking
[safe/jmp/linux-2.6] / mm / slub.c
index 30d2dde..7d6c8b1 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
  * Set of flags that will prevent slab merging
  */
 #define SLUB_NEVER_MERGE (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER | \
-               SLAB_TRACE | SLAB_DESTROY_BY_RCU | SLAB_NOLEAKTRACE)
+               SLAB_TRACE | SLAB_DESTROY_BY_RCU | SLAB_NOLEAKTRACE | \
+               SLAB_FAILSLAB)
 
 #define SLUB_MERGE_SAME (SLAB_DEBUG_FREE | SLAB_RECLAIM_ACCOUNT | \
                SLAB_CACHE_DMA | SLAB_NOTRACK)
@@ -217,10 +218,10 @@ static inline void sysfs_slab_remove(struct kmem_cache *s)
 
 #endif
 
-static inline void stat(struct kmem_cache_cpu *c, enum stat_item si)
+static inline void stat(struct kmem_cache *s, enum stat_item si)
 {
 #ifdef CONFIG_SLUB_STATS
-       c->stat[si]++;
+       __this_cpu_inc(s->cpu_slab->stat[si]);
 #endif
 }
 
@@ -1004,6 +1005,9 @@ static int __init setup_slub_debug(char *str)
                case 't':
                        slub_debug |= SLAB_TRACE;
                        break;
+               case 'a':
+                       slub_debug |= SLAB_FAILSLAB;
+                       break;
                default:
                        printk(KERN_ERR "slub_debug option '%c' "
                                "unknown. skipped\n", *str);
@@ -1108,7 +1112,7 @@ static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
                if (!page)
                        return NULL;
 
-               stat(this_cpu_ptr(s->cpu_slab), ORDER_FALLBACK);
+               stat(s, ORDER_FALLBACK);
        }
 
        if (kmemcheck_enabled
@@ -1406,23 +1410,22 @@ static struct page *get_partial(struct kmem_cache *s, gfp_t flags, int node)
 static void unfreeze_slab(struct kmem_cache *s, struct page *page, int tail)
 {
        struct kmem_cache_node *n = get_node(s, page_to_nid(page));
-       struct kmem_cache_cpu *c = this_cpu_ptr(s->cpu_slab);
 
        __ClearPageSlubFrozen(page);
        if (page->inuse) {
 
                if (page->freelist) {
                        add_partial(n, page, tail);
-                       stat(c, tail ? DEACTIVATE_TO_TAIL : DEACTIVATE_TO_HEAD);
+                       stat(s, tail ? DEACTIVATE_TO_TAIL : DEACTIVATE_TO_HEAD);
                } else {
-                       stat(c, DEACTIVATE_FULL);
+                       stat(s, DEACTIVATE_FULL);
                        if (SLABDEBUG && PageSlubDebug(page) &&
                                                (s->flags & SLAB_STORE_USER))
                                add_full(n, page);
                }
                slab_unlock(page);
        } else {
-               stat(c, DEACTIVATE_EMPTY);
+               stat(s, DEACTIVATE_EMPTY);
                if (n->nr_partial < s->min_partial) {
                        /*
                         * Adding an empty slab to the partial slabs in order
@@ -1438,7 +1441,7 @@ static void unfreeze_slab(struct kmem_cache *s, struct page *page, int tail)
                        slab_unlock(page);
                } else {
                        slab_unlock(page);
-                       stat(__this_cpu_ptr(s->cpu_slab), FREE_SLAB);
+                       stat(s, FREE_SLAB);
                        discard_slab(s, page);
                }
        }
@@ -1453,7 +1456,7 @@ static void deactivate_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
        int tail = 1;
 
        if (page->freelist)
-               stat(c, DEACTIVATE_REMOTE_FREES);
+               stat(s, DEACTIVATE_REMOTE_FREES);
        /*
         * Merge cpu freelist into slab freelist. Typically we get here
         * because both freelists are empty. So this is unlikely
@@ -1479,7 +1482,7 @@ static void deactivate_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
 
 static inline void flush_slab(struct kmem_cache *s, struct kmem_cache_cpu *c)
 {
-       stat(c, CPUSLAB_FLUSH);
+       stat(s, CPUSLAB_FLUSH);
        slab_lock(c->page);
        deactivate_slab(s, c);
 }
@@ -1619,7 +1622,7 @@ static void *__slab_alloc(struct kmem_cache *s, gfp_t gfpflags, int node,
        if (unlikely(!node_match(c, node)))
                goto another_slab;
 
-       stat(c, ALLOC_REFILL);
+       stat(s, ALLOC_REFILL);
 
 load_freelist:
        object = c->page->freelist;
@@ -1634,7 +1637,7 @@ load_freelist:
        c->node = page_to_nid(c->page);
 unlock_out:
        slab_unlock(c->page);
-       stat(c, ALLOC_SLOWPATH);
+       stat(s, ALLOC_SLOWPATH);
        return object;
 
 another_slab:
@@ -1644,7 +1647,7 @@ new_slab:
        new = get_partial(s, gfpflags, node);
        if (new) {
                c->page = new;
-               stat(c, ALLOC_FROM_PARTIAL);
+               stat(s, ALLOC_FROM_PARTIAL);
                goto load_freelist;
        }
 
@@ -1658,7 +1661,7 @@ new_slab:
 
        if (new) {
                c = __this_cpu_ptr(s->cpu_slab);
-               stat(c, ALLOC_SLAB);
+               stat(s, ALLOC_SLAB);
                if (c->page)
                        flush_slab(s, c);
                slab_lock(new);
@@ -1701,7 +1704,7 @@ static __always_inline void *slab_alloc(struct kmem_cache *s,
        lockdep_trace_alloc(gfpflags);
        might_sleep_if(gfpflags & __GFP_WAIT);
 
-       if (should_failslab(s->objsize, gfpflags))
+       if (should_failslab(s->objsize, gfpflags, s->flags))
                return NULL;
 
        local_irq_save(flags);
@@ -1713,7 +1716,7 @@ static __always_inline void *slab_alloc(struct kmem_cache *s,
 
        else {
                c->freelist = get_freepointer(s, object);
-               stat(c, ALLOC_FASTPATH);
+               stat(s, ALLOC_FASTPATH);
        }
        local_irq_restore(flags);
 
@@ -1780,10 +1783,8 @@ static void __slab_free(struct kmem_cache *s, struct page *page,
 {
        void *prior;
        void **object = (void *)x;
-       struct kmem_cache_cpu *c;
 
-       c = __this_cpu_ptr(s->cpu_slab);
-       stat(c, FREE_SLOWPATH);
+       stat(s, FREE_SLOWPATH);
        slab_lock(page);
 
        if (unlikely(SLABDEBUG && PageSlubDebug(page)))
@@ -1796,7 +1797,7 @@ checks_ok:
        page->inuse--;
 
        if (unlikely(PageSlubFrozen(page))) {
-               stat(c, FREE_FROZEN);
+               stat(s, FREE_FROZEN);
                goto out_unlock;
        }
 
@@ -1809,7 +1810,7 @@ checks_ok:
         */
        if (unlikely(!prior)) {
                add_partial(get_node(s, page_to_nid(page)), page, 1);
-               stat(c, FREE_ADD_PARTIAL);
+               stat(s, FREE_ADD_PARTIAL);
        }
 
 out_unlock:
@@ -1822,10 +1823,10 @@ slab_empty:
                 * Slab still on the partial list.
                 */
                remove_partial(s, page);
-               stat(c, FREE_REMOVE_PARTIAL);
+               stat(s, FREE_REMOVE_PARTIAL);
        }
        slab_unlock(page);
-       stat(c, FREE_SLAB);
+       stat(s, FREE_SLAB);
        discard_slab(s, page);
        return;
 
@@ -1863,7 +1864,7 @@ static __always_inline void slab_free(struct kmem_cache *s,
        if (likely(page == c->page && c->node >= 0)) {
                set_freepointer(s, object, c->freelist);
                c->freelist = object;
-               stat(c, FREE_FASTPATH);
+               stat(s, FREE_FASTPATH);
        } else
                __slab_free(s, page, x, addr);
 
@@ -2065,7 +2066,7 @@ init_kmem_cache_node(struct kmem_cache_node *n, struct kmem_cache *s)
 #endif
 }
 
-static DEFINE_PER_CPU(struct kmem_cache_cpu, kmalloc_percpu[SLUB_PAGE_SHIFT]);
+static DEFINE_PER_CPU(struct kmem_cache_cpu, kmalloc_percpu[KMALLOC_CACHES]);
 
 static inline int alloc_kmem_cache_cpus(struct kmem_cache *s, gfp_t flags)
 {
@@ -2074,7 +2075,7 @@ static inline int alloc_kmem_cache_cpus(struct kmem_cache *s, gfp_t flags)
                 * Boot time creation of the kmalloc array. Use static per cpu data
                 * since the per cpu allocator is not available yet.
                 */
-               s->cpu_slab = per_cpu_var(kmalloc_percpu) + (s - kmalloc_caches);
+               s->cpu_slab = kmalloc_percpu + (s - kmalloc_caches);
        else
                s->cpu_slab =  alloc_percpu(struct kmem_cache_cpu);
 
@@ -2151,7 +2152,8 @@ static int init_kmem_cache_nodes(struct kmem_cache *s, gfp_t gfpflags)
        int node;
        int local_node;
 
-       if (slab_state >= UP)
+       if (slab_state >= UP && (s < kmalloc_caches ||
+                       s > kmalloc_caches + KMALLOC_CACHES))
                local_node = page_to_nid(virt_to_page(s));
        else
                local_node = 0;
@@ -2384,6 +2386,9 @@ int kmem_ptr_validate(struct kmem_cache *s, const void *object)
 {
        struct page *page;
 
+       if (!kern_ptr_validate(object, s->size))
+               return 0;
+
        page = get_object_page(object);
 
        if (!page || s != page->slab)
@@ -2644,7 +2649,7 @@ static noinline struct kmem_cache *dma_kmalloc_cache(int index, gfp_t flags)
        if (slab_state >= SYSFS)
                slabflags |= __SYSFS_ADD_DEFERRED;
 
-       if (!s || !text || !kmem_cache_open(s, flags, text,
+       if (!text || !kmem_cache_open(s, flags, text,
                        realsize, ARCH_KMALLOC_MINALIGN, slabflags, NULL)) {
                s->size = 0;
                kfree(text);
@@ -2958,7 +2963,7 @@ static void slab_mem_offline_callback(void *arg)
                        /*
                         * if n->nr_slabs > 0, slabs still exist on the node
                         * that is going down. We were unable to free them,
-                        * and offline_pages() function shoudn't call this
+                        * and offline_pages() function shouldn't call this
                         * callback. So, we must fail.
                         */
                        BUG_ON(slabs_node(s, offline_node));
@@ -4019,6 +4024,23 @@ static ssize_t trace_store(struct kmem_cache *s, const char *buf,
 }
 SLAB_ATTR(trace);
 
+#ifdef CONFIG_FAILSLAB
+static ssize_t failslab_show(struct kmem_cache *s, char *buf)
+{
+       return sprintf(buf, "%d\n", !!(s->flags & SLAB_FAILSLAB));
+}
+
+static ssize_t failslab_store(struct kmem_cache *s, const char *buf,
+                                                       size_t length)
+{
+       s->flags &= ~SLAB_FAILSLAB;
+       if (buf[0] == '1')
+               s->flags |= SLAB_FAILSLAB;
+       return length;
+}
+SLAB_ATTR(failslab);
+#endif
+
 static ssize_t reclaim_account_show(struct kmem_cache *s, char *buf)
 {
        return sprintf(buf, "%d\n", !!(s->flags & SLAB_RECLAIM_ACCOUNT));
@@ -4315,6 +4337,10 @@ static struct attribute *slab_attrs[] = {
        &deactivate_remote_frees_attr.attr,
        &order_fallback_attr.attr,
 #endif
+#ifdef CONFIG_FAILSLAB
+       &failslab_attr.attr,
+#endif
+
        NULL
 };
 
@@ -4367,7 +4393,7 @@ static void kmem_cache_release(struct kobject *kobj)
        kfree(s);
 }
 
-static struct sysfs_ops slab_sysfs_ops = {
+static const struct sysfs_ops slab_sysfs_ops = {
        .show = slab_attr_show,
        .store = slab_attr_store,
 };
@@ -4386,7 +4412,7 @@ static int uevent_filter(struct kset *kset, struct kobject *kobj)
        return 0;
 }
 
-static struct kset_uevent_ops slab_uevent_ops = {
+static const struct kset_uevent_ops slab_uevent_ops = {
        .filter = uevent_filter,
 };