]> Pileus Git - ~andy/linux/commitdiff
Merge branch 'slab/next' of git://git.kernel.org/pub/scm/linux/kernel/git/penberg...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sun, 2 Feb 2014 19:30:08 +0000 (11:30 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sun, 2 Feb 2014 19:30:08 +0000 (11:30 -0800)
Pull SLAB changes from Pekka Enberg:
 "Random bug fixes that have accumulated in my inbox over the past few
  months"

* 'slab/next' of git://git.kernel.org/pub/scm/linux/kernel/git/penberg/linux:
  mm: Fix warning on make htmldocs caused by slab.c
  mm: slub: work around unneeded lockdep warning
  mm: sl[uo]b: fix misleading comments
  slub: Fix possible format string bug.
  slub: use lockdep_assert_held
  slub: Fix calculation of cpu slabs
  slab.h: remove duplicate kmalloc declaration and fix kernel-doc warnings

1  2 
include/linux/slab.h
mm/slub.c

diff --combined include/linux/slab.h
index a060142aa5f53daa9bbfe147b0834a1bcb079c63,f76e956b4011e2a67ee7b1fafa283bc2ebc8e483..9260abdd67df801e002f18faf3f17bd00d494867
@@@ -205,8 -205,8 +205,8 @@@ struct kmem_cache 
  
  #ifdef CONFIG_SLUB
  /*
-  * SLUB allocates up to order 2 pages directly and otherwise
-  * passes the request to the page allocator.
+  * SLUB directly allocates requests fitting in to an order-1 page
+  * (PAGE_SIZE*2).  Larger requests are passed to the page allocator.
   */
  #define KMALLOC_SHIFT_HIGH    (PAGE_SHIFT + 1)
  #define KMALLOC_SHIFT_MAX     (MAX_ORDER + PAGE_SHIFT)
  
  #ifdef CONFIG_SLOB
  /*
-  * SLOB passes all page size and larger requests to the page allocator.
+  * SLOB passes all requests larger than one page to the page allocator.
   * No kmalloc array is necessary since objects of different sizes can
   * be allocated from the same page.
   */
- #define KMALLOC_SHIFT_MAX     30
  #define KMALLOC_SHIFT_HIGH    PAGE_SHIFT
+ #define KMALLOC_SHIFT_MAX     30
  #ifndef KMALLOC_SHIFT_LOW
  #define KMALLOC_SHIFT_LOW     3
  #endif
@@@ -513,9 -513,7 +513,9 @@@ static __always_inline void *kmalloc_no
   *
   * Both the root cache and the child caches will have it. For the root cache,
   * this will hold a dynamically allocated array large enough to hold
 - * information about the currently limited memcgs in the system.
 + * information about the currently limited memcgs in the system. To allow the
 + * array to be accessed without taking any locks, on relocation we free the old
 + * version only after a grace period.
   *
   * Child caches will hold extra metadata needed for its operation. Fields are:
   *
  struct memcg_cache_params {
        bool is_root_cache;
        union {
 -              struct kmem_cache *memcg_caches[0];
 +              struct {
 +                      struct rcu_head rcu_head;
 +                      struct kmem_cache *memcg_caches[0];
 +              };
                struct {
                        struct mem_cgroup *memcg;
                        struct list_head list;
diff --combined mm/slub.c
index 2b1a6970e46f05f3458aaab76102a976088906aa,432bddf484bbf943da517f364f759ea5f448ef29..7e3e0458bce4180d115469b8ce622afef9b1e367
+++ b/mm/slub.c
@@@ -355,21 -355,6 +355,21 @@@ static __always_inline void slab_unlock
        __bit_spin_unlock(PG_locked, &page->flags);
  }
  
 +static inline void set_page_slub_counters(struct page *page, unsigned long counters_new)
 +{
 +      struct page tmp;
 +      tmp.counters = counters_new;
 +      /*
 +       * page->counters can cover frozen/inuse/objects as well
 +       * as page->_count.  If we assign to ->counters directly
 +       * we run the risk of losing updates to page->_count, so
 +       * be careful and only assign to the fields we need.
 +       */
 +      page->frozen  = tmp.frozen;
 +      page->inuse   = tmp.inuse;
 +      page->objects = tmp.objects;
 +}
 +
  /* Interrupts must be disabled (for the fallback code to work right) */
  static inline bool __cmpxchg_double_slab(struct kmem_cache *s, struct page *page,
                void *freelist_old, unsigned long counters_old,
                if (page->freelist == freelist_old &&
                                        page->counters == counters_old) {
                        page->freelist = freelist_new;
 -                      page->counters = counters_new;
 +                      set_page_slub_counters(page, counters_new);
                        slab_unlock(page);
                        return 1;
                }
@@@ -430,7 -415,7 +430,7 @@@ static inline bool cmpxchg_double_slab(
                if (page->freelist == freelist_old &&
                                        page->counters == counters_old) {
                        page->freelist = freelist_new;
 -                      page->counters = counters_new;
 +                      set_page_slub_counters(page, counters_new);
                        slab_unlock(page);
                        local_irq_restore(flags);
                        return 1;
@@@ -1000,23 -985,22 +1000,22 @@@ static inline void slab_free_hook(struc
  
  /*
   * Tracking of fully allocated slabs for debugging purposes.
-  *
-  * list_lock must be held.
   */
  static void add_full(struct kmem_cache *s,
        struct kmem_cache_node *n, struct page *page)
  {
+       lockdep_assert_held(&n->list_lock);
        if (!(s->flags & SLAB_STORE_USER))
                return;
  
        list_add(&page->lru, &n->full);
  }
  
- /*
-  * list_lock must be held.
-  */
- static void remove_full(struct kmem_cache *s, struct page *page)
+ static void remove_full(struct kmem_cache *s, struct kmem_cache_node *n, struct page *page)
  {
+       lockdep_assert_held(&n->list_lock);
        if (!(s->flags & SLAB_STORE_USER))
                return;
  
@@@ -1265,7 -1249,8 +1264,8 @@@ static inline int check_object(struct k
                        void *object, u8 val) { return 1; }
  static inline void add_full(struct kmem_cache *s, struct kmem_cache_node *n,
                                        struct page *page) {}
- static inline void remove_full(struct kmem_cache *s, struct page *page) {}
+ static inline void remove_full(struct kmem_cache *s, struct kmem_cache_node *n,
+                                       struct page *page) {}
  static inline unsigned long kmem_cache_flags(unsigned long object_size,
        unsigned long flags, const char *name,
        void (*ctor)(void *))
@@@ -1519,12 -1504,12 +1519,12 @@@ static void discard_slab(struct kmem_ca
  
  /*
   * Management of partially allocated slabs.
-  *
-  * list_lock must be held.
   */
  static inline void add_partial(struct kmem_cache_node *n,
                                struct page *page, int tail)
  {
+       lockdep_assert_held(&n->list_lock);
        n->nr_partial++;
        if (tail == DEACTIVATE_TO_TAIL)
                list_add_tail(&page->lru, &n->partial);
                list_add(&page->lru, &n->partial);
  }
  
- /*
-  * list_lock must be held.
-  */
  static inline void remove_partial(struct kmem_cache_node *n,
                                        struct page *page)
  {
+       lockdep_assert_held(&n->list_lock);
        list_del(&page->lru);
        n->nr_partial--;
  }
   * return the pointer to the freelist.
   *
   * Returns a list of objects or NULL if it fails.
-  *
-  * Must hold list_lock since we modify the partial list.
   */
  static inline void *acquire_slab(struct kmem_cache *s,
                struct kmem_cache_node *n, struct page *page,
        unsigned long counters;
        struct page new;
  
+       lockdep_assert_held(&n->list_lock);
        /*
         * Zap the freelist and set the frozen bit.
         * The old freelist is the list of objects for the
@@@ -1902,7 -1886,7 +1901,7 @@@ redo
  
                else if (l == M_FULL)
  
-                       remove_full(s, page);
+                       remove_full(s, n, page);
  
                if (m == M_PARTIAL) {
  
@@@ -2556,7 -2540,7 +2555,7 @@@ static void __slab_free(struct kmem_cac
                new.inuse--;
                if ((!new.inuse || !prior) && !was_frozen) {
  
-                       if (kmem_cache_has_cpu_partial(s) && !prior)
+                       if (kmem_cache_has_cpu_partial(s) && !prior) {
  
                                /*
                                 * Slab was on no list before and will be
                                 */
                                new.frozen = 1;
  
-                       else { /* Needs to be taken off a list */
+                       else { /* Needs to be taken off a list */
  
                                n = get_node(s, page_to_nid(page));
                                /*
         */
        if (!kmem_cache_has_cpu_partial(s) && unlikely(!prior)) {
                if (kmem_cache_debug(s))
-                       remove_full(s, page);
+                       remove_full(s, n, page);
                add_partial(n, page, DEACTIVATE_TO_TAIL);
                stat(s, FREE_ADD_PARTIAL);
        }
@@@ -2629,9 -2613,10 +2628,10 @@@ slab_empty
                 */
                remove_partial(n, page);
                stat(s, FREE_REMOVE_PARTIAL);
-       } else
+       } else {
                /* Slab must be on the full list */
-               remove_full(s, page);
+               remove_full(s, n, page);
+       }
  
        spin_unlock_irqrestore(&n->list_lock, flags);
        stat(s, FREE_SLAB);
@@@ -2905,7 -2890,13 +2905,13 @@@ static void early_kmem_cache_node_alloc
        init_kmem_cache_node(n);
        inc_slabs_node(kmem_cache_node, node, page->objects);
  
+       /*
+        * the lock is for lockdep's sake, not for any actual
+        * race protection
+        */
+       spin_lock(&n->list_lock);
        add_partial(n, page, DEACTIVATE_TO_HEAD);
+       spin_unlock(&n->list_lock);
  }
  
  static void free_kmem_cache_nodes(struct kmem_cache *s)
@@@ -4314,7 -4305,13 +4320,13 @@@ static ssize_t show_slab_objects(struc
  
                        page = ACCESS_ONCE(c->partial);
                        if (page) {
-                               x = page->pobjects;
+                               node = page_to_nid(page);
+                               if (flags & SO_TOTAL)
+                                       WARN_ON_ONCE(1);
+                               else if (flags & SO_OBJECTS)
+                                       WARN_ON_ONCE(1);
+                               else
+                                       x = page->pages;
                                total += x;
                                nodes[node] += x;
                        }
@@@ -5178,7 -5175,7 +5190,7 @@@ static int sysfs_slab_add(struct kmem_c
        }
  
        s->kobj.kset = slab_kset;
-       err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
+       err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
        if (err) {
                kobject_put(&s->kobj);
                return err;