Merge tag 'armsoc-soc' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[linux-2.6-block.git] / mm / vmalloc.c
index 45e0dc0e09f80b632c0c0203815ed2486fffb18a..4fa8d84599b0bad60d03c87243c9cf97ec9bb52e 100644 (file)
@@ -406,6 +406,13 @@ static void purge_vmap_area_lazy(void);
 static BLOCKING_NOTIFIER_HEAD(vmap_notify_list);
 static unsigned long lazy_max_pages(void);
 
+static atomic_long_t nr_vmalloc_pages;
+
+unsigned long vmalloc_nr_pages(void)
+{
+       return atomic_long_read(&nr_vmalloc_pages);
+}
+
 static struct vmap_area *__find_vmap_area(unsigned long addr)
 {
        struct rb_node *n = vmap_area_root.rb_node;
@@ -534,20 +541,17 @@ link_va(struct vmap_area *va, struct rb_root *root,
 static __always_inline void
 unlink_va(struct vmap_area *va, struct rb_root *root)
 {
-       /*
-        * During merging a VA node can be empty, therefore
-        * not linked with the tree nor list. Just check it.
-        */
-       if (!RB_EMPTY_NODE(&va->rb_node)) {
-               if (root == &free_vmap_area_root)
-                       rb_erase_augmented(&va->rb_node,
-                               root, &free_vmap_area_rb_augment_cb);
-               else
-                       rb_erase(&va->rb_node, root);
+       if (WARN_ON(RB_EMPTY_NODE(&va->rb_node)))
+               return;
 
-               list_del(&va->list);
-               RB_CLEAR_NODE(&va->rb_node);
-       }
+       if (root == &free_vmap_area_root)
+               rb_erase_augmented(&va->rb_node,
+                       root, &free_vmap_area_rb_augment_cb);
+       else
+               rb_erase(&va->rb_node, root);
+
+       list_del(&va->list);
+       RB_CLEAR_NODE(&va->rb_node);
 }
 
 #if DEBUG_AUGMENT_PROPAGATE_CHECK
@@ -719,9 +723,6 @@ merge_or_add_vmap_area(struct vmap_area *va,
                        /* Check and update the tree if needed. */
                        augment_tree_propagate_from(sibling);
 
-                       /* Remove this VA, it has been merged. */
-                       unlink_va(va, root);
-
                        /* Free vmap_area object. */
                        kmem_cache_free(vmap_area_cachep, va);
 
@@ -746,12 +747,11 @@ merge_or_add_vmap_area(struct vmap_area *va,
                        /* Check and update the tree if needed. */
                        augment_tree_propagate_from(sibling);
 
-                       /* Remove this VA, it has been merged. */
-                       unlink_va(va, root);
+                       if (merged)
+                               unlink_va(va, root);
 
                        /* Free vmap_area object. */
                        kmem_cache_free(vmap_area_cachep, va);
-
                        return;
                }
        }
@@ -1166,8 +1166,6 @@ EXPORT_SYMBOL_GPL(unregister_vmap_purge_notifier);
 
 static void __free_vmap_area(struct vmap_area *va)
 {
-       BUG_ON(RB_EMPTY_NODE(&va->rb_node));
-
        /*
         * Remove from the busy tree/list.
         */
@@ -2246,6 +2244,7 @@ static void __vunmap(const void *addr, int deallocate_pages)
                        BUG_ON(!page);
                        __free_pages(page, 0);
                }
+               atomic_long_sub(area->nr_pages, &nr_vmalloc_pages);
 
                kvfree(area->pages);
        }
@@ -2423,12 +2422,14 @@ static void *__vmalloc_area_node(struct vm_struct *area, gfp_t gfp_mask,
                if (unlikely(!page)) {
                        /* Successfully allocated i pages, free them in __vunmap() */
                        area->nr_pages = i;
+                       atomic_long_add(area->nr_pages, &nr_vmalloc_pages);
                        goto fail;
                }
                area->pages[i] = page;
                if (gfpflags_allow_blocking(gfp_mask|highmem_mask))
                        cond_resched();
        }
+       atomic_long_add(area->nr_pages, &nr_vmalloc_pages);
 
        if (map_vm_area(area, prot, pages))
                goto fail;
@@ -2821,7 +2822,7 @@ static int aligned_vwrite(char *buf, char *addr, unsigned long count)
  * Note: In usual ops, vread() is never necessary because the caller
  * should know vmalloc() area is valid and can use memcpy().
  * This is for routines which have to access vmalloc area without
- * any informaion, as /dev/kmem.
+ * any information, as /dev/kmem.
  *
  * Return: number of bytes for which addr and buf should be increased
  * (same number as @count) or %0 if [addr...addr+count) doesn't
@@ -2900,7 +2901,7 @@ finished:
  * Note: In usual ops, vwrite() is never necessary because the caller
  * should know vmalloc() area is valid and can use memcpy().
  * This is for routines which have to access vmalloc area without
- * any informaion, as /dev/kmem.
+ * any information, as /dev/kmem.
  *
  * Return: number of bytes for which addr and buf should be
  * increased (same number as @count) or %0 if [addr...addr+count)