aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMinchan Kim <minchan@kernel.org>2016-01-14 18:22:32 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2016-01-15 14:40:51 -0500
commit75d8947a36d0c9aedd69118d1f14bf424005c7c2 (patch)
tree2fb49d36e4db0591ebd3fe42101379f9aa9b9c90
parentd913897abace843bba20249f3190167f7895e9c3 (diff)
zram: pass gfp from zcomp frontend to backend
Each zcomp backend uses own gfp flag but it's pointless because the context they could be called is driven by upper layer(ie, zcomp frontend). As well, zcomp frondend could call them in different context. One context(ie, zram init part) is it should be better to make sure successful allocation other context(ie, further stream allocation part for accelarating I/O speed) is just optional so let's pass gfp down from driver (ie, zcomp frontend) like normal MM convention. [sergey.senozhatsky@gmail.com: add missing __vmalloc zero and highmem gfps] Signed-off-by: Minchan Kim <minchan@kernel.org> Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--drivers/block/zram/zcomp.c24
-rw-r--r--drivers/block/zram/zcomp.h2
-rw-r--r--drivers/block/zram/zcomp_lz4.c16
-rw-r--r--drivers/block/zram/zcomp_lzo.c16
4 files changed, 23 insertions, 35 deletions
diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index c53617752b93..3ef42e563bb5 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -74,18 +74,18 @@ static void zcomp_strm_free(struct zcomp *comp, struct zcomp_strm *zstrm)
74 * allocate new zcomp_strm structure with ->private initialized by 74 * allocate new zcomp_strm structure with ->private initialized by
75 * backend, return NULL on error 75 * backend, return NULL on error
76 */ 76 */
77static struct zcomp_strm *zcomp_strm_alloc(struct zcomp *comp) 77static struct zcomp_strm *zcomp_strm_alloc(struct zcomp *comp, gfp_t flags)
78{ 78{
79 struct zcomp_strm *zstrm = kmalloc(sizeof(*zstrm), GFP_NOIO); 79 struct zcomp_strm *zstrm = kmalloc(sizeof(*zstrm), flags);
80 if (!zstrm) 80 if (!zstrm)
81 return NULL; 81 return NULL;
82 82
83 zstrm->private = comp->backend->create(); 83 zstrm->private = comp->backend->create(flags);
84 /* 84 /*
85 * allocate 2 pages. 1 for compressed data, plus 1 extra for the 85 * allocate 2 pages. 1 for compressed data, plus 1 extra for the
86 * case when compressed size is larger than the original one 86 * case when compressed size is larger than the original one
87 */ 87 */
88 zstrm->buffer = (void *)__get_free_pages(GFP_NOIO | __GFP_ZERO, 1); 88 zstrm->buffer = (void *)__get_free_pages(flags | __GFP_ZERO, 1);
89 if (!zstrm->private || !zstrm->buffer) { 89 if (!zstrm->private || !zstrm->buffer) {
90 zcomp_strm_free(comp, zstrm); 90 zcomp_strm_free(comp, zstrm);
91 zstrm = NULL; 91 zstrm = NULL;
@@ -120,8 +120,16 @@ static struct zcomp_strm *zcomp_strm_multi_find(struct zcomp *comp)
120 /* allocate new zstrm stream */ 120 /* allocate new zstrm stream */
121 zs->avail_strm++; 121 zs->avail_strm++;
122 spin_unlock(&zs->strm_lock); 122 spin_unlock(&zs->strm_lock);
123 123 /*
124 zstrm = zcomp_strm_alloc(comp); 124 * This function can be called in swapout/fs write path
125 * so we can't use GFP_FS|IO. And it assumes we already
126 * have at least one stream in zram initialization so we
127 * don't do best effort to allocate more stream in here.
128 * A default stream will work well without further multiple
129 * streams. That's why we use NORETRY | NOWARN.
130 */
131 zstrm = zcomp_strm_alloc(comp, GFP_NOIO | __GFP_NORETRY |
132 __GFP_NOWARN);
125 if (!zstrm) { 133 if (!zstrm) {
126 spin_lock(&zs->strm_lock); 134 spin_lock(&zs->strm_lock);
127 zs->avail_strm--; 135 zs->avail_strm--;
@@ -209,7 +217,7 @@ static int zcomp_strm_multi_create(struct zcomp *comp, int max_strm)
209 zs->max_strm = max_strm; 217 zs->max_strm = max_strm;
210 zs->avail_strm = 1; 218 zs->avail_strm = 1;
211 219
212 zstrm = zcomp_strm_alloc(comp); 220 zstrm = zcomp_strm_alloc(comp, GFP_KERNEL);
213 if (!zstrm) { 221 if (!zstrm) {
214 kfree(zs); 222 kfree(zs);
215 return -ENOMEM; 223 return -ENOMEM;
@@ -259,7 +267,7 @@ static int zcomp_strm_single_create(struct zcomp *comp)
259 267
260 comp->stream = zs; 268 comp->stream = zs;
261 mutex_init(&zs->strm_lock); 269 mutex_init(&zs->strm_lock);
262 zs->zstrm = zcomp_strm_alloc(comp); 270 zs->zstrm = zcomp_strm_alloc(comp, GFP_KERNEL);
263 if (!zs->zstrm) { 271 if (!zs->zstrm) {
264 kfree(zs); 272 kfree(zs);
265 return -ENOMEM; 273 return -ENOMEM;
diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h
index 46e2b9f8f1f0..b7d2a4bcae54 100644
--- a/drivers/block/zram/zcomp.h
+++ b/drivers/block/zram/zcomp.h
@@ -33,7 +33,7 @@ struct zcomp_backend {
33 int (*decompress)(const unsigned char *src, size_t src_len, 33 int (*decompress)(const unsigned char *src, size_t src_len,
34 unsigned char *dst); 34 unsigned char *dst);
35 35
36 void *(*create)(void); 36 void *(*create)(gfp_t flags);
37 void (*destroy)(void *private); 37 void (*destroy)(void *private);
38 38
39 const char *name; 39 const char *name;
diff --git a/drivers/block/zram/zcomp_lz4.c b/drivers/block/zram/zcomp_lz4.c
index dd6083124276..dc2338d5258c 100644
--- a/drivers/block/zram/zcomp_lz4.c
+++ b/drivers/block/zram/zcomp_lz4.c
@@ -15,24 +15,14 @@
15 15
16#include "zcomp_lz4.h" 16#include "zcomp_lz4.h"
17 17
18static void *zcomp_lz4_create(void) 18static void *zcomp_lz4_create(gfp_t flags)
19{ 19{
20 void *ret; 20 void *ret;
21 21
22 /* 22 ret = kzalloc(LZ4_MEM_COMPRESS, flags);
23 * This function can be called in swapout/fs write path
24 * so we can't use GFP_FS|IO. And it assumes we already
25 * have at least one stream in zram initialization so we
26 * don't do best effort to allocate more stream in here.
27 * A default stream will work well without further multiple
28 * streams. That's why we use NORETRY | NOWARN.
29 */
30 ret = kzalloc(LZ4_MEM_COMPRESS, GFP_NOIO | __GFP_NORETRY |
31 __GFP_NOWARN);
32 if (!ret) 23 if (!ret)
33 ret = __vmalloc(LZ4_MEM_COMPRESS, 24 ret = __vmalloc(LZ4_MEM_COMPRESS,
34 GFP_NOIO | __GFP_NORETRY | __GFP_NOWARN | 25 flags | __GFP_ZERO | __GFP_HIGHMEM,
35 __GFP_ZERO | __GFP_HIGHMEM,
36 PAGE_KERNEL); 26 PAGE_KERNEL);
37 return ret; 27 return ret;
38} 28}
diff --git a/drivers/block/zram/zcomp_lzo.c b/drivers/block/zram/zcomp_lzo.c
index edc549920fa0..0ab6fce8abe4 100644
--- a/drivers/block/zram/zcomp_lzo.c
+++ b/drivers/block/zram/zcomp_lzo.c
@@ -15,24 +15,14 @@
15 15
16#include "zcomp_lzo.h" 16#include "zcomp_lzo.h"
17 17
18static void *lzo_create(void) 18static void *lzo_create(gfp_t flags)
19{ 19{
20 void *ret; 20 void *ret;
21 21
22 /* 22 ret = kzalloc(LZO1X_MEM_COMPRESS, flags);
23 * This function can be called in swapout/fs write path
24 * so we can't use GFP_FS|IO. And it assumes we already
25 * have at least one stream in zram initialization so we
26 * don't do best effort to allocate more stream in here.
27 * A default stream will work well without further multiple
28 * streams. That's why we use NORETRY | NOWARN.
29 */
30 ret = kzalloc(LZO1X_MEM_COMPRESS, GFP_NOIO | __GFP_NORETRY |
31 __GFP_NOWARN);
32 if (!ret) 23 if (!ret)
33 ret = __vmalloc(LZO1X_MEM_COMPRESS, 24 ret = __vmalloc(LZO1X_MEM_COMPRESS,
34 GFP_NOIO | __GFP_NORETRY | __GFP_NOWARN | 25 flags | __GFP_ZERO | __GFP_HIGHMEM,
35 __GFP_ZERO | __GFP_HIGHMEM,
36 PAGE_KERNEL); 26 PAGE_KERNEL);
37 return ret; 27 return ret;
38} 28}