]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - mm/slub.c
slub: Calculate min_objects based on number of processors.
[linux-2.6-omap-h63xx.git] / mm / slub.c
index 6641025c597f30c2a01286918b01a038e192869d..e2e6ba7a5172ea93c588089f14b59db14ab8a890 100644 (file)
--- a/mm/slub.c
+++ b/mm/slub.c
@@ -149,25 +149,6 @@ static inline void ClearSlabDebug(struct page *page)
 /* Enable to test recovery from slab corruption on boot */
 #undef SLUB_RESILIENCY_TEST
 
-#if PAGE_SHIFT <= 12
-
-/*
- * Small page size. Make sure that we do not fragment memory
- */
-#define DEFAULT_MAX_ORDER 1
-#define DEFAULT_MIN_OBJECTS 4
-
-#else
-
-/*
- * Large page machines are customarily able to handle larger
- * page orders.
- */
-#define DEFAULT_MAX_ORDER 2
-#define DEFAULT_MIN_OBJECTS 8
-
-#endif
-
 /*
  * Mininum number of partial slabs. These will be left on the partial
  * lists even if they are empty. kmem_cache_shrink may reclaim them.
@@ -204,8 +185,6 @@ static inline void ClearSlabDebug(struct page *page)
 /* Internal SLUB flags */
 #define __OBJECT_POISON                0x80000000 /* Poison object */
 #define __SYSFS_ADD_DEFERRED   0x40000000 /* Not yet visible via sysfs */
-#define __KMALLOC_CACHE                0x20000000 /* objects freed using kfree */
-#define __PAGE_ALLOC_FALLBACK  0x10000000 /* Allow fallback to page alloc */
 
 /* Not all arches define cache_line_size */
 #ifndef cache_line_size
@@ -327,8 +306,8 @@ static inline void set_freepointer(struct kmem_cache *s, void *object, void *fp)
 }
 
 /* Loop over all objects in a slab */
-#define for_each_object(__p, __s, __addr) \
-       for (__p = (__addr); __p < (__addr) + (__s)->objects * (__s)->size;\
+#define for_each_object(__p, __s, __addr, __objects) \
+       for (__p = (__addr); __p < (__addr) + (__objects) * (__s)->size;\
                        __p += (__s)->size)
 
 /* Scan freelist */
@@ -341,6 +320,26 @@ static inline int slab_index(void *p, struct kmem_cache *s, void *addr)
        return (p - addr) / s->size;
 }
 
+static inline struct kmem_cache_order_objects oo_make(int order,
+                                               unsigned long size)
+{
+       struct kmem_cache_order_objects x = {
+               (order << 16) + (PAGE_SIZE << order) / size
+       };
+
+       return x;
+}
+
+static inline int oo_order(struct kmem_cache_order_objects x)
+{
+       return x.x >> 16;
+}
+
+static inline int oo_objects(struct kmem_cache_order_objects x)
+{
+       return x.x & ((1 << 16) - 1);
+}
+
 #ifdef CONFIG_SLUB_DEBUG
 /*
  * Debug settings:
@@ -665,7 +664,7 @@ static int slab_pad_check(struct kmem_cache *s, struct page *page)
                return 1;
 
        start = page_address(page);
-       length = (PAGE_SIZE << s->order);
+       length = (PAGE_SIZE << compound_order(page));
        end = start + length;
        remainder = length % s->size;
        if (!remainder)
@@ -774,6 +773,7 @@ static int on_freelist(struct kmem_cache *s, struct page *page, void *search)
        int nr = 0;
        void *fp = page->freelist;
        void *object = NULL;
+       unsigned long max_objects;
 
        while (fp && nr <= page->objects) {
                if (fp == search)
@@ -798,6 +798,16 @@ static int on_freelist(struct kmem_cache *s, struct page *page, void *search)
                nr++;
        }
 
+       max_objects = (PAGE_SIZE << compound_order(page)) / s->size;
+       if (max_objects > 65535)
+               max_objects = 65535;
+
+       if (page->objects != max_objects) {
+               slab_err(s, page, "Wrong number of objects. Found %d but "
+                       "should be %d", page->objects, max_objects);
+               page->objects = max_objects;
+               slab_fix(s, "Number of objects adjusted.");
+       }
        if (page->inuse != page->objects - nr) {
                slab_err(s, page, "Wrong object count. Counter is %d but "
                        "counted were %d", page->inuse, page->objects - nr);
@@ -855,7 +865,7 @@ static inline unsigned long slabs_node(struct kmem_cache *s, int node)
        return atomic_long_read(&n->nr_slabs);
 }
 
-static inline void inc_slabs_node(struct kmem_cache *s, int node)
+static inline void inc_slabs_node(struct kmem_cache *s, int node, int objects)
 {
        struct kmem_cache_node *n = get_node(s, node);
 
@@ -865,14 +875,17 @@ static inline void inc_slabs_node(struct kmem_cache *s, int node)
         * dilemma by deferring the increment of the count during
         * bootstrap (see early_kmem_cache_node_alloc).
         */
-       if (!NUMA_BUILD || n)
+       if (!NUMA_BUILD || n) {
                atomic_long_inc(&n->nr_slabs);
+               atomic_long_add(objects, &n->total_objects);
+       }
 }
-static inline void dec_slabs_node(struct kmem_cache *s, int node)
+static inline void dec_slabs_node(struct kmem_cache *s, int node, int objects)
 {
        struct kmem_cache_node *n = get_node(s, node);
 
        atomic_long_dec(&n->nr_slabs);
+       atomic_long_sub(objects, &n->total_objects);
 }
 
 /* Object debug checks for alloc/free paths */
@@ -1070,32 +1083,52 @@ static inline unsigned long kmem_cache_flags(unsigned long objsize,
 
 static inline unsigned long slabs_node(struct kmem_cache *s, int node)
                                                        { return 0; }
-static inline void inc_slabs_node(struct kmem_cache *s, int node) {}
-static inline void dec_slabs_node(struct kmem_cache *s, int node) {}
+static inline void inc_slabs_node(struct kmem_cache *s, int node,
+                                                       int objects) {}
+static inline void dec_slabs_node(struct kmem_cache *s, int node,
+                                                       int objects) {}
 #endif
+
 /*
  * Slab allocation and freeing
  */
+static inline struct page *alloc_slab_page(gfp_t flags, int node,
+                                       struct kmem_cache_order_objects oo)
+{
+       int order = oo_order(oo);
+
+       if (node == -1)
+               return alloc_pages(flags, order);
+       else
+               return alloc_pages_node(node, flags, order);
+}
+
 static struct page *allocate_slab(struct kmem_cache *s, gfp_t flags, int node)
 {
        struct page *page;
-       int pages = 1 << s->order;
+       struct kmem_cache_order_objects oo = s->oo;
 
        flags |= s->allocflags;
 
-       if (node == -1)
-               page = alloc_pages(flags, s->order);
-       else
-               page = alloc_pages_node(node, flags, s->order);
-
-       if (!page)
-               return NULL;
+       page = alloc_slab_page(flags | __GFP_NOWARN | __GFP_NORETRY, node,
+                                                                       oo);
+       if (unlikely(!page)) {
+               oo = s->min;
+               /*
+                * Allocation may have failed due to fragmentation.
+                * Try a lower order alloc if possible
+                */
+               page = alloc_slab_page(flags, node, oo);
+               if (!page)
+                       return NULL;
 
-       page->objects = s->objects;
+               stat(get_cpu_slab(s, raw_smp_processor_id()), ORDER_FALLBACK);
+       }
+       page->objects = oo_objects(oo);
        mod_zone_page_state(page_zone(page),
                (s->flags & SLAB_RECLAIM_ACCOUNT) ?
                NR_SLAB_RECLAIMABLE : NR_SLAB_UNRECLAIMABLE,
-               pages);
+               1 << oo_order(oo));
 
        return page;
 }
@@ -1122,7 +1155,7 @@ static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
        if (!page)
                goto out;
 
-       inc_slabs_node(s, page_to_nid(page));
+       inc_slabs_node(s, page_to_nid(page), page->objects);
        page->slab = s;
        page->flags |= 1 << PG_slab;
        if (s->flags & (SLAB_DEBUG_FREE | SLAB_RED_ZONE | SLAB_POISON |
@@ -1132,10 +1165,10 @@ static struct page *new_slab(struct kmem_cache *s, gfp_t flags, int node)
        start = page_address(page);
 
        if (unlikely(s->flags & SLAB_POISON))
-               memset(start, POISON_INUSE, PAGE_SIZE << s->order);
+               memset(start, POISON_INUSE, PAGE_SIZE << compound_order(page));
 
        last = start;
-       for_each_object(p, s, start) {
+       for_each_object(p, s, start, page->objects) {
                setup_object(s, page, last);
                set_freepointer(s, last, p);
                last = p;
@@ -1151,13 +1184,15 @@ out:
 
 static void __free_slab(struct kmem_cache *s, struct page *page)
 {
-       int pages = 1 << s->order;
+       int order = compound_order(page);
+       int pages = 1 << order;
 
        if (unlikely(SlabDebug(page))) {
                void *p;
 
                slab_pad_check(s, page);
-               for_each_object(p, s, page_address(page))
+               for_each_object(p, s, page_address(page),
+                                               page->objects)
                        check_object(s, page, p, 0);
                ClearSlabDebug(page);
        }
@@ -1169,7 +1204,7 @@ static void __free_slab(struct kmem_cache *s, struct page *page)
 
        __ClearPageSlab(page);
        reset_page_mapcount(page);
-       __free_pages(page, s->order);
+       __free_pages(page, order);
 }
 
 static void rcu_free_slab(struct rcu_head *h)
@@ -1195,7 +1230,7 @@ static void free_slab(struct kmem_cache *s, struct page *page)
 
 static void discard_slab(struct kmem_cache *s, struct page *page)
 {
-       dec_slabs_node(s, page_to_nid(page));
+       dec_slabs_node(s, page_to_nid(page), page->objects);
        free_slab(s, page);
 }
 
@@ -1567,27 +1602,6 @@ new_slab:
                c->page = new;
                goto load_freelist;
        }
-
-       /*
-        * No memory available.
-        *
-        * If the slab uses higher order allocs but the object is
-        * smaller than a page size then we can fallback in emergencies
-        * to the page allocator via kmalloc_large. The page allocator may
-        * have failed to obtain a higher order page and we can try to
-        * allocate a single page if the object fits into a single page.
-        * That is only possible if certain conditions are met that are being
-        * checked when a slab is created.
-        */
-       if (!(gfpflags & __GFP_NORETRY) &&
-                               (s->flags & __PAGE_ALLOC_FALLBACK)) {
-               if (gfpflags & __GFP_WAIT)
-                       local_irq_enable();
-               object = kmalloc_large(s->objsize, gfpflags);
-               if (gfpflags & __GFP_WAIT)
-                       local_irq_disable();
-               return object;
-       }
        return NULL;
 debug:
        if (!alloc_debug_processing(s, c->page, object, addr))
@@ -1788,8 +1802,8 @@ static struct page *get_object_page(const void *x)
  * take the list_lock.
  */
 static int slub_min_order;
-static int slub_max_order = DEFAULT_MAX_ORDER;
-static int slub_min_objects = DEFAULT_MIN_OBJECTS;
+static int slub_max_order = PAGE_ALLOC_COSTLY_ORDER;
+static int slub_min_objects;
 
 /*
  * Merge control. If this is set then no merging of slab caches will occur.
@@ -1866,6 +1880,8 @@ static inline int calculate_order(int size)
         * we reduce the minimum objects required in a slab.
         */
        min_objects = slub_min_objects;
+       if (!min_objects)
+               min_objects = 4 * (fls(nr_cpu_ids) + 1);
        while (min_objects > 1) {
                fraction = 8;
                while (fraction >= 4) {
@@ -2109,7 +2125,7 @@ static struct kmem_cache_node *early_kmem_cache_node_alloc(gfp_t gfpflags,
        init_tracking(kmalloc_caches, n);
 #endif
        init_kmem_cache_node(n);
-       inc_slabs_node(kmalloc_caches, node);
+       inc_slabs_node(kmalloc_caches, node, page->objects);
 
        /*
         * lockdep requires consistent irq usage for each lock
@@ -2185,11 +2201,12 @@ static int init_kmem_cache_nodes(struct kmem_cache *s, gfp_t gfpflags)
  * calculate_sizes() determines the order and the distribution of data within
  * a slab object.
  */
-static int calculate_sizes(struct kmem_cache *s)
+static int calculate_sizes(struct kmem_cache *s, int forced_order)
 {
        unsigned long flags = s->flags;
        unsigned long size = s->objsize;
        unsigned long align = s->align;
+       int order;
 
        /*
         * Round up object size to the next word boundary. We can only
@@ -2273,26 +2290,16 @@ static int calculate_sizes(struct kmem_cache *s)
         */
        size = ALIGN(size, align);
        s->size = size;
+       if (forced_order >= 0)
+               order = forced_order;
+       else
+               order = calculate_order(size);
 
-       if ((flags & __KMALLOC_CACHE) &&
-                       PAGE_SIZE / size < slub_min_objects) {
-               /*
-                * Kmalloc cache that would not have enough objects in
-                * an order 0 page. Kmalloc slabs can fallback to
-                * page allocator order 0 allocs so take a reasonably large
-                * order that will allows us a good number of objects.
-                */
-               s->order = max(slub_max_order, PAGE_ALLOC_COSTLY_ORDER);
-               s->flags |= __PAGE_ALLOC_FALLBACK;
-               s->allocflags |= __GFP_NOWARN;
-       } else
-               s->order = calculate_order(size);
-
-       if (s->order < 0)
+       if (order < 0)
                return 0;
 
        s->allocflags = 0;
-       if (s->order)
+       if (order)
                s->allocflags |= __GFP_COMP;
 
        if (s->flags & SLAB_CACHE_DMA)
@@ -2304,9 +2311,12 @@ static int calculate_sizes(struct kmem_cache *s)
        /*
         * Determine the number of objects per slab
         */
-       s->objects = (PAGE_SIZE << s->order) / size;
+       s->oo = oo_make(order, size);
+       s->min = oo_make(get_order(size), size);
+       if (oo_objects(s->oo) > oo_objects(s->max))
+               s->max = s->oo;
 
-       return !!s->objects;
+       return !!oo_objects(s->oo);
 
 }
 
@@ -2322,7 +2332,7 @@ static int kmem_cache_open(struct kmem_cache *s, gfp_t gfpflags,
        s->align = align;
        s->flags = kmem_cache_flags(size, flags, name, ctor);
 
-       if (!calculate_sizes(s))
+       if (!calculate_sizes(s, -1))
                goto error;
 
        s->refcount = 1;
@@ -2339,7 +2349,7 @@ error:
        if (flags & SLAB_PANIC)
                panic("Cannot create slab %s size=%lu realsize=%u "
                        "order=%u offset=%u flags=%lx\n",
-                       s->name, (unsigned long)size, s->size, s->order,
+                       s->name, (unsigned long)size, s->size, oo_order(s->oo),
                        s->offset, flags);
        return 0;
 }
@@ -2529,7 +2539,7 @@ static struct kmem_cache *create_kmalloc_cache(struct kmem_cache *s,
 
        down_write(&slub_lock);
        if (!kmem_cache_open(s, gfp_flags, name, size, ARCH_KMALLOC_MINALIGN,
-                       flags | __KMALLOC_CACHE, NULL))
+                                                               flags, NULL))
                goto panic;
 
        list_add(&s->list, &slab_caches);
@@ -2777,8 +2787,9 @@ int kmem_cache_shrink(struct kmem_cache *s)
        struct kmem_cache_node *n;
        struct page *page;
        struct page *t;
+       int objects = oo_objects(s->max);
        struct list_head *slabs_by_inuse =
-               kmalloc(sizeof(struct list_head) * s->objects, GFP_KERNEL);
+               kmalloc(sizeof(struct list_head) * objects, GFP_KERNEL);
        unsigned long flags;
 
        if (!slabs_by_inuse)
@@ -2791,7 +2802,7 @@ int kmem_cache_shrink(struct kmem_cache *s)
                if (!n->nr_partial)
                        continue;
 
-               for (i = 0; i < s->objects; i++)
+               for (i = 0; i < objects; i++)
                        INIT_LIST_HEAD(slabs_by_inuse + i);
 
                spin_lock_irqsave(&n->list_lock, flags);
@@ -2823,7 +2834,7 @@ int kmem_cache_shrink(struct kmem_cache *s)
                 * Rebuild the partial list with the slabs filled up most
                 * first and the least used slabs at the end.
                 */
-               for (i = s->objects - 1; i >= 0; i--)
+               for (i = objects - 1; i >= 0; i--)
                        list_splice(slabs_by_inuse + i, n->partial.prev);
 
                spin_unlock_irqrestore(&n->list_lock, flags);
@@ -3044,9 +3055,6 @@ static int slab_unmergeable(struct kmem_cache *s)
        if (slub_nomerge || (s->flags & SLUB_NEVER_MERGE))
                return 1;
 
-       if ((s->flags & __PAGE_ALLOC_FALLBACK))
-               return 1;
-
        if (s->ctor)
                return 1;
 
@@ -3239,7 +3247,8 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
 }
 
 #if (defined(CONFIG_SYSFS) && defined(CONFIG_SLUB_DEBUG)) || defined(CONFIG_SLABINFO)
-static unsigned long count_partial(struct kmem_cache_node *n)
+static unsigned long count_partial(struct kmem_cache_node *n,
+                                       int (*get_count)(struct page *))
 {
        unsigned long flags;
        unsigned long x = 0;
@@ -3247,10 +3256,25 @@ static unsigned long count_partial(struct kmem_cache_node *n)
 
        spin_lock_irqsave(&n->list_lock, flags);
        list_for_each_entry(page, &n->partial, lru)
-               x += page->inuse;
+               x += get_count(page);
        spin_unlock_irqrestore(&n->list_lock, flags);
        return x;
 }
+
+static int count_inuse(struct page *page)
+{
+       return page->inuse;
+}
+
+static int count_total(struct page *page)
+{
+       return page->objects;
+}
+
+static int count_free(struct page *page)
+{
+       return page->objects - page->inuse;
+}
 #endif
 
 #if defined(CONFIG_SYSFS) && defined(CONFIG_SLUB_DEBUG)
@@ -3273,7 +3297,7 @@ static int validate_slab(struct kmem_cache *s, struct page *page,
                        return 0;
        }
 
-       for_each_object(p, s, addr)
+       for_each_object(p, s, addr, page->objects)
                if (!test_bit(slab_index(p, s, addr), map))
                        if (!check_object(s, page, p, 1))
                                return 0;
@@ -3339,7 +3363,7 @@ static long validate_slab_cache(struct kmem_cache *s)
 {
        int node;
        unsigned long count = 0;
-       unsigned long *map = kmalloc(BITS_TO_LONGS(s->objects) *
+       unsigned long *map = kmalloc(BITS_TO_LONGS(oo_objects(s->max)) *
                                sizeof(unsigned long), GFP_KERNEL);
 
        if (!map)
@@ -3549,7 +3573,7 @@ static void process_slab(struct loc_track *t, struct kmem_cache *s,
        for_each_free_object(p, s, page->freelist)
                set_bit(slab_index(p, s, addr), map);
 
-       for_each_object(p, s, addr)
+       for_each_object(p, s, addr, page->objects)
                if (!test_bit(slab_index(p, s, addr), map))
                        add_location(t, s, get_track(s, p, alloc));
 }
@@ -3639,22 +3663,23 @@ static int list_locations(struct kmem_cache *s, char *buf,
 }
 
 enum slab_stat_type {
-       SL_FULL,
-       SL_PARTIAL,
-       SL_CPU,
-       SL_OBJECTS
+       SL_ALL,                 /* All slabs */
+       SL_PARTIAL,             /* Only partially allocated slabs */
+       SL_CPU,                 /* Only slabs used for cpu caches */
+       SL_OBJECTS,             /* Determine allocated objects not slabs */
+       SL_TOTAL                /* Determine object capacity not slabs */
 };
 
-#define SO_FULL                (1 << SL_FULL)
+#define SO_ALL         (1 << SL_ALL)
 #define SO_PARTIAL     (1 << SL_PARTIAL)
 #define SO_CPU         (1 << SL_CPU)
 #define SO_OBJECTS     (1 << SL_OBJECTS)
+#define SO_TOTAL       (1 << SL_TOTAL)
 
 static ssize_t show_slab_objects(struct kmem_cache *s,
                            char *buf, unsigned long flags)
 {
        unsigned long total = 0;
-       int cpu;
        int node;
        int x;
        unsigned long *nodes;
@@ -3665,56 +3690,60 @@ static ssize_t show_slab_objects(struct kmem_cache *s,
                return -ENOMEM;
        per_cpu = nodes + nr_node_ids;
 
-       for_each_possible_cpu(cpu) {
-               struct page *page;
-               struct kmem_cache_cpu *c = get_cpu_slab(s, cpu);
+       if (flags & SO_CPU) {
+               int cpu;
 
-               if (!c)
-                       continue;
+               for_each_possible_cpu(cpu) {
+                       struct kmem_cache_cpu *c = get_cpu_slab(s, cpu);
 
-               page = c->page;
-               node = c->node;
-               if (node < 0)
-                       continue;
-               if (page) {
-                       if (flags & SO_CPU) {
-                               if (flags & SO_OBJECTS)
-                                       x = page->inuse;
+                       if (!c || c->node < 0)
+                               continue;
+
+                       if (c->page) {
+                                       if (flags & SO_TOTAL)
+                                               x = c->page->objects;
+                               else if (flags & SO_OBJECTS)
+                                       x = c->page->inuse;
                                else
                                        x = 1;
+
                                total += x;
-                               nodes[node] += x;
+                               nodes[c->node] += x;
                        }
-                       per_cpu[node]++;
+                       per_cpu[c->node]++;
                }
        }
 
-       for_each_node_state(node, N_NORMAL_MEMORY) {
-               struct kmem_cache_node *n = get_node(s, node);
+       if (flags & SO_ALL) {
+               for_each_node_state(node, N_NORMAL_MEMORY) {
+                       struct kmem_cache_node *n = get_node(s, node);
+
+               if (flags & SO_TOTAL)
+                       x = atomic_long_read(&n->total_objects);
+               else if (flags & SO_OBJECTS)
+                       x = atomic_long_read(&n->total_objects) -
+                               count_partial(n, count_free);
 
-               if (flags & SO_PARTIAL) {
-                       if (flags & SO_OBJECTS)
-                               x = count_partial(n);
                        else
-                               x = n->nr_partial;
+                               x = atomic_long_read(&n->nr_slabs);
                        total += x;
                        nodes[node] += x;
                }
 
-               if (flags & SO_FULL) {
-                       int full_slabs = atomic_long_read(&n->nr_slabs)
-                                       - per_cpu[node]
-                                       - n->nr_partial;
+       } else if (flags & SO_PARTIAL) {
+               for_each_node_state(node, N_NORMAL_MEMORY) {
+                       struct kmem_cache_node *n = get_node(s, node);
 
-                       if (flags & SO_OBJECTS)
-                               x = full_slabs * s->objects;
+                       if (flags & SO_TOTAL)
+                               x = count_partial(n, count_total);
+                       else if (flags & SO_OBJECTS)
+                               x = count_partial(n, count_inuse);
                        else
-                               x = full_slabs;
+                               x = n->nr_partial;
                        total += x;
                        nodes[node] += x;
                }
        }
-
        x = sprintf(buf, "%lu", total);
 #ifdef CONFIG_NUMA
        for_each_node_state(node, N_NORMAL_MEMORY)
@@ -3729,14 +3758,6 @@ static ssize_t show_slab_objects(struct kmem_cache *s,
 static int any_slab_objects(struct kmem_cache *s)
 {
        int node;
-       int cpu;
-
-       for_each_possible_cpu(cpu) {
-               struct kmem_cache_cpu *c = get_cpu_slab(s, cpu);
-
-               if (c && c->page)
-                       return 1;
-       }
 
        for_each_online_node(node) {
                struct kmem_cache_node *n = get_node(s, node);
@@ -3744,7 +3765,7 @@ static int any_slab_objects(struct kmem_cache *s)
                if (!n)
                        continue;
 
-               if (n->nr_partial || atomic_long_read(&n->nr_slabs))
+               if (atomic_read(&n->total_objects))
                        return 1;
        }
        return 0;
@@ -3786,15 +3807,27 @@ SLAB_ATTR_RO(object_size);
 
 static ssize_t objs_per_slab_show(struct kmem_cache *s, char *buf)
 {
-       return sprintf(buf, "%d\n", s->objects);
+       return sprintf(buf, "%d\n", oo_objects(s->oo));
 }
 SLAB_ATTR_RO(objs_per_slab);
 
+static ssize_t order_store(struct kmem_cache *s,
+                               const char *buf, size_t length)
+{
+       int order = simple_strtoul(buf, NULL, 10);
+
+       if (order > slub_max_order || order < slub_min_order)
+               return -EINVAL;
+
+       calculate_sizes(s, order);
+       return length;
+}
+
 static ssize_t order_show(struct kmem_cache *s, char *buf)
 {
-       return sprintf(buf, "%d\n", s->order);
+       return sprintf(buf, "%d\n", oo_order(s->oo));
 }
-SLAB_ATTR_RO(order);
+SLAB_ATTR(order);
 
 static ssize_t ctor_show(struct kmem_cache *s, char *buf)
 {
@@ -3815,7 +3848,7 @@ SLAB_ATTR_RO(aliases);
 
 static ssize_t slabs_show(struct kmem_cache *s, char *buf)
 {
-       return show_slab_objects(s, buf, SO_FULL|SO_PARTIAL|SO_CPU);
+       return show_slab_objects(s, buf, SO_ALL);
 }
 SLAB_ATTR_RO(slabs);
 
@@ -3833,10 +3866,22 @@ SLAB_ATTR_RO(cpu_slabs);
 
 static ssize_t objects_show(struct kmem_cache *s, char *buf)
 {
-       return show_slab_objects(s, buf, SO_FULL|SO_PARTIAL|SO_CPU|SO_OBJECTS);
+       return show_slab_objects(s, buf, SO_ALL|SO_OBJECTS);
 }
 SLAB_ATTR_RO(objects);
 
+static ssize_t objects_partial_show(struct kmem_cache *s, char *buf)
+{
+       return show_slab_objects(s, buf, SO_PARTIAL|SO_OBJECTS);
+}
+SLAB_ATTR_RO(objects_partial);
+
+static ssize_t total_objects_show(struct kmem_cache *s, char *buf)
+{
+       return show_slab_objects(s, buf, SO_ALL|SO_TOTAL);
+}
+SLAB_ATTR_RO(total_objects);
+
 static ssize_t sanity_checks_show(struct kmem_cache *s, char *buf)
 {
        return sprintf(buf, "%d\n", !!(s->flags & SLAB_DEBUG_FREE));
@@ -3916,7 +3961,7 @@ static ssize_t red_zone_store(struct kmem_cache *s,
        s->flags &= ~SLAB_RED_ZONE;
        if (buf[0] == '1')
                s->flags |= SLAB_RED_ZONE;
-       calculate_sizes(s);
+       calculate_sizes(s, -1);
        return length;
 }
 SLAB_ATTR(red_zone);
@@ -3935,7 +3980,7 @@ static ssize_t poison_store(struct kmem_cache *s,
        s->flags &= ~SLAB_POISON;
        if (buf[0] == '1')
                s->flags |= SLAB_POISON;
-       calculate_sizes(s);
+       calculate_sizes(s, -1);
        return length;
 }
 SLAB_ATTR(poison);
@@ -3954,7 +3999,7 @@ static ssize_t store_user_store(struct kmem_cache *s,
        s->flags &= ~SLAB_STORE_USER;
        if (buf[0] == '1')
                s->flags |= SLAB_STORE_USER;
-       calculate_sizes(s);
+       calculate_sizes(s, -1);
        return length;
 }
 SLAB_ATTR(store_user);
@@ -4085,7 +4130,7 @@ STAT_ATTR(DEACTIVATE_EMPTY, deactivate_empty);
 STAT_ATTR(DEACTIVATE_TO_HEAD, deactivate_to_head);
 STAT_ATTR(DEACTIVATE_TO_TAIL, deactivate_to_tail);
 STAT_ATTR(DEACTIVATE_REMOTE_FREES, deactivate_remote_frees);
-
+STAT_ATTR(ORDER_FALLBACK, order_fallback);
 #endif
 
 static struct attribute *slab_attrs[] = {
@@ -4094,6 +4139,8 @@ static struct attribute *slab_attrs[] = {
        &objs_per_slab_attr.attr,
        &order_attr.attr,
        &objects_attr.attr,
+       &objects_partial_attr.attr,
+       &total_objects_attr.attr,
        &slabs_attr.attr,
        &partial_attr.attr,
        &cpu_slabs_attr.attr,
@@ -4136,6 +4183,7 @@ static struct attribute *slab_attrs[] = {
        &deactivate_to_head_attr.attr,
        &deactivate_to_tail_attr.attr,
        &deactivate_remote_frees_attr.attr,
+       &order_fallback_attr.attr,
 #endif
        NULL
 };
@@ -4422,7 +4470,8 @@ static int s_show(struct seq_file *m, void *p)
        unsigned long nr_partials = 0;
        unsigned long nr_slabs = 0;
        unsigned long nr_inuse = 0;
-       unsigned long nr_objs;
+       unsigned long nr_objs = 0;
+       unsigned long nr_free = 0;
        struct kmem_cache *s;
        int node;
 
@@ -4436,14 +4485,15 @@ static int s_show(struct seq_file *m, void *p)
 
                nr_partials += n->nr_partial;
                nr_slabs += atomic_long_read(&n->nr_slabs);
-               nr_inuse += count_partial(n);
+               nr_objs += atomic_long_read(&n->total_objects);
+               nr_free += count_partial(n, count_free);
        }
 
-       nr_objs = nr_slabs * s->objects;
-       nr_inuse += (nr_slabs - nr_partials) * s->objects;
+       nr_inuse = nr_objs - nr_free;
 
        seq_printf(m, "%-17s %6lu %6lu %6u %4u %4d", s->name, nr_inuse,
-                  nr_objs, s->size, s->objects, (1 << s->order));
+                  nr_objs, s->size, oo_objects(s->oo),
+                  (1 << oo_order(s->oo)));
        seq_printf(m, " : tunables %4u %4u %4u", 0, 0, 0);
        seq_printf(m, " : slabdata %6lu %6lu %6lu", nr_slabs, nr_slabs,
                   0UL);