Merge branches 'topic/slob/cleanups', 'topic/slob/fixes', 'topic/slub/core', 'topic...
[pandora-kernel.git] / mm / slub.c
index e150b5c..c65a4ed 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -1329,7 +1329,7 @@ static struct page *get_any_partial(struct kmem_cache *s, gfp_t flags)
                n = get_node(s, zone_to_nid(zone));
 
                if (n && cpuset_zone_allowed_hardwall(zone, flags) &&
-                               n->nr_partial > n->min_partial) {
+                               n->nr_partial > s->min_partial) {
                        page = get_partial_node(n);
                        if (page)
                                return page;
@@ -1381,7 +1381,7 @@ static void unfreeze_slab(struct kmem_cache *s, struct page *page, int tail)
                slab_unlock(page);
        } else {
                stat(c, DEACTIVATE_EMPTY);
-               if (n->nr_partial < n->min_partial) {
+               if (n->nr_partial < s->min_partial) {
                        /*
                         * Adding an empty slab to the partial slabs in order
                         * to avoid page allocator overhead. This slab needs
@@ -1838,6 +1838,7 @@ static inline int calculate_order(int size)
        int order;
        int min_objects;
        int fraction;
+       int max_objects;
 
        /*
         * Attempt to find best configuration for a slab. This
@@ -1850,6 +1851,9 @@ static inline int calculate_order(int size)
        min_objects = slub_min_objects;
        if (!min_objects)
                min_objects = 4 * (fls(nr_cpu_ids) + 1);
+       max_objects = (PAGE_SIZE << slub_max_order)/size;
+       min_objects = min(min_objects, max_objects);
+
        while (min_objects > 1) {
                fraction = 16;
                while (fraction >= 4) {
@@ -1859,7 +1863,7 @@ static inline int calculate_order(int size)
                                return order;
                        fraction /= 2;
                }
-               min_objects /= 2;
+               min_objects --;
        }
 
        /*
@@ -1922,17 +1926,6 @@ static void
 init_kmem_cache_node(struct kmem_cache_node *n, struct kmem_cache *s)
 {
        n->nr_partial = 0;
-
-       /*
-        * The larger the object size is, the more pages we want on the partial
-        * list to avoid pounding the page allocator excessively.
-        */
-       n->min_partial = ilog2(s->size);
-       if (n->min_partial < MIN_PARTIAL)
-               n->min_partial = MIN_PARTIAL;
-       else if (n->min_partial > MAX_PARTIAL)
-               n->min_partial = MAX_PARTIAL;
-
        spin_lock_init(&n->list_lock);
        INIT_LIST_HEAD(&n->partial);
 #ifdef CONFIG_SLUB_DEBUG
@@ -1990,7 +1983,7 @@ static struct kmem_cache_cpu *alloc_kmem_cache_cpu(struct kmem_cache *s,
 static void free_kmem_cache_cpu(struct kmem_cache_cpu *c, int cpu)
 {
        if (c < per_cpu(kmem_cache_cpu, cpu) ||
-                       c > per_cpu(kmem_cache_cpu, cpu) + NR_KMEM_CACHE_CPU) {
+                       c >= per_cpu(kmem_cache_cpu, cpu) + NR_KMEM_CACHE_CPU) {
                kfree(c);
                return;
        }
@@ -2175,6 +2168,15 @@ static int init_kmem_cache_nodes(struct kmem_cache *s, gfp_t gfpflags)
 }
 #endif
 
+static void set_min_partial(struct kmem_cache *s, unsigned long min)
+{
+       if (min < MIN_PARTIAL)
+               min = MIN_PARTIAL;
+       else if (min > MAX_PARTIAL)
+               min = MAX_PARTIAL;
+       s->min_partial = min;
+}
+
 /*
  * calculate_sizes() determines the order and the distribution of data within
  * a slab object.
@@ -2313,6 +2315,11 @@ static int kmem_cache_open(struct kmem_cache *s, gfp_t gfpflags,
        if (!calculate_sizes(s, -1))
                goto error;
 
+       /*
+        * The larger the object size is, the more pages we want on the partial
+        * list to avoid pounding the page allocator excessively.
+        */
+       set_min_partial(s, ilog2(s->size));
        s->refcount = 1;
 #ifdef CONFIG_NUMA
        s->remote_node_defrag_ratio = 1000;
@@ -2469,7 +2476,7 @@ EXPORT_SYMBOL(kmem_cache_destroy);
  *             Kmalloc subsystem
  *******************************************************************/
 
-struct kmem_cache kmalloc_caches[PAGE_SHIFT + 1] __cacheline_aligned;
+struct kmem_cache kmalloc_caches[SLUB_PAGE_SHIFT] __cacheline_aligned;
 EXPORT_SYMBOL(kmalloc_caches);
 
 static int __init setup_slub_min_order(char *str)
@@ -2531,7 +2538,7 @@ panic:
 }
 
 #ifdef CONFIG_ZONE_DMA
-static struct kmem_cache *kmalloc_caches_dma[PAGE_SHIFT + 1];
+static struct kmem_cache *kmalloc_caches_dma[SLUB_PAGE_SHIFT];
 
 static void sysfs_add_func(struct work_struct *w)
 {
@@ -2652,7 +2659,7 @@ void *__kmalloc(size_t size, gfp_t flags)
 {
        struct kmem_cache *s;
 
-       if (unlikely(size > PAGE_SIZE))
+       if (unlikely(size > SLUB_MAX_SIZE))
                return kmalloc_large(size, flags);
 
        s = get_slab(size, flags);
@@ -2680,7 +2687,7 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
 {
        struct kmem_cache *s;
 
-       if (unlikely(size > PAGE_SIZE))
+       if (unlikely(size > SLUB_MAX_SIZE))
                return kmalloc_large_node(size, flags, node);
 
        s = get_slab(size, flags);
@@ -2730,6 +2737,7 @@ size_t ksize(const void *object)
         */
        return s->size;
 }
+EXPORT_SYMBOL(ksize);
 
 void kfree(const void *x)
 {
@@ -2979,7 +2987,7 @@ void __init kmem_cache_init(void)
                caches++;
        }
 
-       for (i = KMALLOC_SHIFT_LOW; i <PAGE_SHIFT; i++) {
+       for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
                create_kmalloc_cache(&kmalloc_caches[i],
                        "kmalloc", 1 << i, GFP_KERNEL);
                caches++;
@@ -3016,7 +3024,7 @@ void __init kmem_cache_init(void)
        slab_state = UP;
 
        /* Provide the correct kmalloc names now that the caches are up */
-       for (i = KMALLOC_SHIFT_LOW; i <PAGE_SHIFT; i++)
+       for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++)
                kmalloc_caches[i]. name =
                        kasprintf(GFP_KERNEL, "kmalloc-%d", 1 << i);
 
@@ -3216,7 +3224,7 @@ void *__kmalloc_track_caller(size_t size, gfp_t gfpflags, unsigned long caller)
 {
        struct kmem_cache *s;
 
-       if (unlikely(size > PAGE_SIZE))
+       if (unlikely(size > SLUB_MAX_SIZE))
                return kmalloc_large(size, gfpflags);
 
        s = get_slab(size, gfpflags);
@@ -3232,7 +3240,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
 {
        struct kmem_cache *s;
 
-       if (unlikely(size > PAGE_SIZE))
+       if (unlikely(size > SLUB_MAX_SIZE))
                return kmalloc_large_node(size, gfpflags, node);
 
        s = get_slab(size, gfpflags);
@@ -3829,6 +3837,26 @@ static ssize_t order_show(struct kmem_cache *s, char *buf)
 }
 SLAB_ATTR(order);
 
+static ssize_t min_partial_show(struct kmem_cache *s, char *buf)
+{
+       return sprintf(buf, "%lu\n", s->min_partial);
+}
+
+static ssize_t min_partial_store(struct kmem_cache *s, const char *buf,
+                                size_t length)
+{
+       unsigned long min;
+       int err;
+
+       err = strict_strtoul(buf, 10, &min);
+       if (err)
+               return err;
+
+       set_min_partial(s, min);
+       return length;
+}
+SLAB_ATTR(min_partial);
+
 static ssize_t ctor_show(struct kmem_cache *s, char *buf)
 {
        if (s->ctor) {
@@ -4144,6 +4172,7 @@ static struct attribute *slab_attrs[] = {
        &object_size_attr.attr,
        &objs_per_slab_attr.attr,
        &order_attr.attr,
+       &min_partial_attr.attr,
        &objects_attr.attr,
        &objects_partial_attr.attr,
        &total_objects_attr.attr,