mm: loosen MADV_NOHUGEPAGE to enable Qemu postcopy on s390
[linux-2.6-block.git] / mm / zsmalloc.c
index c4811067bec7c5420f057e17e585ba15f2602050..9f15bdd9163c2360edf2e070023b6099b683a85c 100644 (file)
@@ -16,7 +16,7 @@
  * struct page(s) to form a zspage.
  *
  * Usage of struct page fields:
- *     page->first_page: points to the first component (0-order) page
+ *     page->private: points to the first component (0-order) page
  *     page->index (union with page->freelist): offset of the first object
  *             starting in this page. For the first page, this is
  *             always 0, so we use this field (aka freelist) to point
@@ -26,8 +26,7 @@
  *
  *     For _first_ page only:
  *
- *     page->private (union with page->first_page): refers to the
- *             component page after the first page
+ *     page->private: refers to the component page after the first page
  *             If the page is first_page for huge object, it stores handle.
  *             Look at size_class->huge.
  *     page->freelist: points to the first free object in zspage.
@@ -167,9 +166,14 @@ enum zs_stat_type {
        OBJ_USED,
        CLASS_ALMOST_FULL,
        CLASS_ALMOST_EMPTY,
-       NR_ZS_STAT_TYPE,
 };
 
+#ifdef CONFIG_ZSMALLOC_STAT
+#define NR_ZS_STAT_TYPE        (CLASS_ALMOST_EMPTY + 1)
+#else
+#define NR_ZS_STAT_TYPE        (OBJ_USED + 1)
+#endif
+
 struct zs_size_stat {
        unsigned long objs[NR_ZS_STAT_TYPE];
 };
@@ -448,19 +452,23 @@ static int get_size_class_index(int size)
 static inline void zs_stat_inc(struct size_class *class,
                                enum zs_stat_type type, unsigned long cnt)
 {
-       class->stats.objs[type] += cnt;
+       if (type < NR_ZS_STAT_TYPE)
+               class->stats.objs[type] += cnt;
 }
 
 static inline void zs_stat_dec(struct size_class *class,
                                enum zs_stat_type type, unsigned long cnt)
 {
-       class->stats.objs[type] -= cnt;
+       if (type < NR_ZS_STAT_TYPE)
+               class->stats.objs[type] -= cnt;
 }
 
 static inline unsigned long zs_stat_get(struct size_class *class,
                                enum zs_stat_type type)
 {
-       return class->stats.objs[type];
+       if (type < NR_ZS_STAT_TYPE)
+               return class->stats.objs[type];
+       return 0;
 }
 
 #ifdef CONFIG_ZSMALLOC_STAT
@@ -765,7 +773,7 @@ static struct page *get_first_page(struct page *page)
        if (is_first_page(page))
                return page;
        else
-               return page->first_page;
+               return (struct page *)page_private(page);
 }
 
 static struct page *get_next_page(struct page *page)
@@ -950,7 +958,7 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags)
         * Allocate individual pages and link them together as:
         * 1. first page->private = first sub-page
         * 2. all sub-pages are linked together using page->lru
-        * 3. each sub-page is linked to the first page using page->first_page
+        * 3. each sub-page is linked to the first page using page->private
         *
         * For each size class, First/Head pages are linked together using
         * page->lru. Also, we set PG_private to identify the first page
@@ -975,7 +983,7 @@ static struct page *alloc_zspage(struct size_class *class, gfp_t flags)
                if (i == 1)
                        set_page_private(first_page, (unsigned long)page);
                if (i >= 1)
-                       page->first_page = first_page;
+                       set_page_private(page, (unsigned long)first_page);
                if (i >= 2)
                        list_add(&page->lru, &prev_page->lru);
                if (i == class->pages_per_zspage - 1)   /* last page */
@@ -1429,8 +1437,6 @@ static void obj_free(struct zs_pool *pool, struct size_class *class,
        struct page *first_page, *f_page;
        unsigned long f_objidx, f_offset;
        void *vaddr;
-       int class_idx;
-       enum fullness_group fullness;
 
        BUG_ON(!obj);
 
@@ -1438,7 +1444,6 @@ static void obj_free(struct zs_pool *pool, struct size_class *class,
        obj_to_location(obj, &f_page, &f_objidx);
        first_page = get_first_page(f_page);
 
-       get_zspage_mapping(first_page, &class_idx, &fullness);
        f_offset = obj_idx_to_offset(f_page, f_objidx, class->size);
 
        vaddr = kmap_atomic(f_page);
@@ -1823,9 +1828,6 @@ static unsigned long zs_shrinker_count(struct shrinker *shrinker,
        struct zs_pool *pool = container_of(shrinker, struct zs_pool,
                        shrinker);
 
-       if (!pool->shrinker_enabled)
-               return 0;
-
        for (i = zs_size_classes - 1; i >= 0; i--) {
                class = pool->size_class[i];
                if (!class)