|
@@ -170,6 +170,11 @@ enum fullness_group {
|
|
ZS_FULL
|
|
ZS_FULL
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+/*
|
|
|
|
+ * number of size_classes
|
|
|
|
+ */
|
|
|
|
+static int zs_size_classes;
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* We assign a page to ZS_ALMOST_EMPTY fullness group when:
|
|
* We assign a page to ZS_ALMOST_EMPTY fullness group when:
|
|
* n <= N / f, where
|
|
* n <= N / f, where
|
|
@@ -214,7 +219,7 @@ struct link_free {
|
|
};
|
|
};
|
|
|
|
|
|
struct zs_pool {
|
|
struct zs_pool {
|
|
- struct size_class *size_class[ZS_SIZE_CLASSES];
|
|
|
|
|
|
+ struct size_class **size_class;
|
|
|
|
|
|
gfp_t flags; /* allocation flags used when growing pool */
|
|
gfp_t flags; /* allocation flags used when growing pool */
|
|
atomic_long_t pages_allocated;
|
|
atomic_long_t pages_allocated;
|
|
@@ -785,7 +790,7 @@ static inline int __zs_cpu_up(struct mapping_area *area)
|
|
*/
|
|
*/
|
|
if (area->vm_buf)
|
|
if (area->vm_buf)
|
|
return 0;
|
|
return 0;
|
|
- area->vm_buf = (char *)__get_free_page(GFP_KERNEL);
|
|
|
|
|
|
+ area->vm_buf = kmalloc(ZS_MAX_ALLOC_SIZE, GFP_KERNEL);
|
|
if (!area->vm_buf)
|
|
if (!area->vm_buf)
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
return 0;
|
|
return 0;
|
|
@@ -793,8 +798,7 @@ static inline int __zs_cpu_up(struct mapping_area *area)
|
|
|
|
|
|
static inline void __zs_cpu_down(struct mapping_area *area)
|
|
static inline void __zs_cpu_down(struct mapping_area *area)
|
|
{
|
|
{
|
|
- if (area->vm_buf)
|
|
|
|
- free_page((unsigned long)area->vm_buf);
|
|
|
|
|
|
+ kfree(area->vm_buf);
|
|
area->vm_buf = NULL;
|
|
area->vm_buf = NULL;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -912,6 +916,17 @@ static int zs_register_cpu_notifier(void)
|
|
return notifier_to_errno(ret);
|
|
return notifier_to_errno(ret);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+static void init_zs_size_classes(void)
|
|
|
|
+{
|
|
|
|
+ int nr;
|
|
|
|
+
|
|
|
|
+ nr = (ZS_MAX_ALLOC_SIZE - ZS_MIN_ALLOC_SIZE) / ZS_SIZE_CLASS_DELTA + 1;
|
|
|
|
+ if ((ZS_MAX_ALLOC_SIZE - ZS_MIN_ALLOC_SIZE) % ZS_SIZE_CLASS_DELTA)
|
|
|
|
+ nr += 1;
|
|
|
|
+
|
|
|
|
+ zs_size_classes = nr;
|
|
|
|
+}
|
|
|
|
+
|
|
static void __exit zs_exit(void)
|
|
static void __exit zs_exit(void)
|
|
{
|
|
{
|
|
#ifdef CONFIG_ZPOOL
|
|
#ifdef CONFIG_ZPOOL
|
|
@@ -929,6 +944,8 @@ static int __init zs_init(void)
|
|
return ret;
|
|
return ret;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ init_zs_size_classes();
|
|
|
|
+
|
|
#ifdef CONFIG_ZPOOL
|
|
#ifdef CONFIG_ZPOOL
|
|
zpool_register_driver(&zs_zpool_driver);
|
|
zpool_register_driver(&zs_zpool_driver);
|
|
#endif
|
|
#endif
|
|
@@ -972,11 +989,18 @@ struct zs_pool *zs_create_pool(gfp_t flags)
|
|
if (!pool)
|
|
if (!pool)
|
|
return NULL;
|
|
return NULL;
|
|
|
|
|
|
|
|
+ pool->size_class = kcalloc(zs_size_classes, sizeof(struct size_class *),
|
|
|
|
+ GFP_KERNEL);
|
|
|
|
+ if (!pool->size_class) {
|
|
|
|
+ kfree(pool);
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
|
|
|
+
|
|
/*
|
|
/*
|
|
* Iterate reversly, because, size of size_class that we want to use
|
|
* Iterate reversly, because, size of size_class that we want to use
|
|
* for merging should be larger or equal to current size.
|
|
* for merging should be larger or equal to current size.
|
|
*/
|
|
*/
|
|
- for (i = ZS_SIZE_CLASSES - 1; i >= 0; i--) {
|
|
|
|
|
|
+ for (i = zs_size_classes - 1; i >= 0; i--) {
|
|
int size;
|
|
int size;
|
|
int pages_per_zspage;
|
|
int pages_per_zspage;
|
|
struct size_class *class;
|
|
struct size_class *class;
|
|
@@ -1029,7 +1053,7 @@ void zs_destroy_pool(struct zs_pool *pool)
|
|
{
|
|
{
|
|
int i;
|
|
int i;
|
|
|
|
|
|
- for (i = 0; i < ZS_SIZE_CLASSES; i++) {
|
|
|
|
|
|
+ for (i = 0; i < zs_size_classes; i++) {
|
|
int fg;
|
|
int fg;
|
|
struct size_class *class = pool->size_class[i];
|
|
struct size_class *class = pool->size_class[i];
|
|
|
|
|
|
@@ -1047,6 +1071,8 @@ void zs_destroy_pool(struct zs_pool *pool)
|
|
}
|
|
}
|
|
kfree(class);
|
|
kfree(class);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ kfree(pool->size_class);
|
|
kfree(pool);
|
|
kfree(pool);
|
|
}
|
|
}
|
|
EXPORT_SYMBOL_GPL(zs_destroy_pool);
|
|
EXPORT_SYMBOL_GPL(zs_destroy_pool);
|