]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
zram: pass gfp from zcomp frontend to backend
authorMinchan Kim <minchan@kernel.org>
Thu, 14 Jan 2016 23:22:32 +0000 (15:22 -0800)
committerLinus Torvalds <torvalds@linux-foundation.org>
Fri, 15 Jan 2016 19:40:51 +0000 (11:40 -0800)
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>
drivers/block/zram/zcomp.c
drivers/block/zram/zcomp.h
drivers/block/zram/zcomp_lz4.c
drivers/block/zram/zcomp_lzo.c

index c53617752b93cc3976f764e19cc436b5cb66cdcf..3ef42e563bb5d73df2edc5b881744d3b97a214b3 100644 (file)
@@ -74,18 +74,18 @@ static void zcomp_strm_free(struct zcomp *comp, struct zcomp_strm *zstrm)
  * allocate new zcomp_strm structure with ->private initialized by
  * backend, return NULL on error
  */
-static struct zcomp_strm *zcomp_strm_alloc(struct zcomp *comp)
+static struct zcomp_strm *zcomp_strm_alloc(struct zcomp *comp, gfp_t flags)
 {
-       struct zcomp_strm *zstrm = kmalloc(sizeof(*zstrm), GFP_NOIO);
+       struct zcomp_strm *zstrm = kmalloc(sizeof(*zstrm), flags);
        if (!zstrm)
                return NULL;
 
-       zstrm->private = comp->backend->create();
+       zstrm->private = comp->backend->create(flags);
        /*
         * allocate 2 pages. 1 for compressed data, plus 1 extra for the
         * case when compressed size is larger than the original one
         */
-       zstrm->buffer = (void *)__get_free_pages(GFP_NOIO | __GFP_ZERO, 1);
+       zstrm->buffer = (void *)__get_free_pages(flags | __GFP_ZERO, 1);
        if (!zstrm->private || !zstrm->buffer) {
                zcomp_strm_free(comp, zstrm);
                zstrm = NULL;
@@ -120,8 +120,16 @@ static struct zcomp_strm *zcomp_strm_multi_find(struct zcomp *comp)
                /* allocate new zstrm stream */
                zs->avail_strm++;
                spin_unlock(&zs->strm_lock);
-
-               zstrm = zcomp_strm_alloc(comp);
+               /*
+                * This function can be called in swapout/fs write path
+                * so we can't use GFP_FS|IO. And it assumes we already
+                * have at least one stream in zram initialization so we
+                * don't do best effort to allocate more stream in here.
+                * A default stream will work well without further multiple
+                * streams. That's why we use NORETRY | NOWARN.
+                */
+               zstrm = zcomp_strm_alloc(comp, GFP_NOIO | __GFP_NORETRY |
+                                       __GFP_NOWARN);
                if (!zstrm) {
                        spin_lock(&zs->strm_lock);
                        zs->avail_strm--;
@@ -209,7 +217,7 @@ static int zcomp_strm_multi_create(struct zcomp *comp, int max_strm)
        zs->max_strm = max_strm;
        zs->avail_strm = 1;
 
-       zstrm = zcomp_strm_alloc(comp);
+       zstrm = zcomp_strm_alloc(comp, GFP_KERNEL);
        if (!zstrm) {
                kfree(zs);
                return -ENOMEM;
@@ -259,7 +267,7 @@ static int zcomp_strm_single_create(struct zcomp *comp)
 
        comp->stream = zs;
        mutex_init(&zs->strm_lock);
-       zs->zstrm = zcomp_strm_alloc(comp);
+       zs->zstrm = zcomp_strm_alloc(comp, GFP_KERNEL);
        if (!zs->zstrm) {
                kfree(zs);
                return -ENOMEM;
index 46e2b9f8f1f0e3ec684736305c4d8a1ab8de0c97..b7d2a4bcae54009ea4e1c8b52f666ad4c43a9e30 100644 (file)
@@ -33,7 +33,7 @@ struct zcomp_backend {
        int (*decompress)(const unsigned char *src, size_t src_len,
                        unsigned char *dst);
 
-       void *(*create)(void);
+       void *(*create)(gfp_t flags);
        void (*destroy)(void *private);
 
        const char *name;
index dd6083124276fa107717112cb273648887f1d52e..dc2338d5258c171f55ac5d4d3576fbb9465c4643 100644 (file)
 
 #include "zcomp_lz4.h"
 
-static void *zcomp_lz4_create(void)
+static void *zcomp_lz4_create(gfp_t flags)
 {
        void *ret;
 
-       /*
-        * This function can be called in swapout/fs write path
-        * so we can't use GFP_FS|IO. And it assumes we already
-        * have at least one stream in zram initialization so we
-        * don't do best effort to allocate more stream in here.
-        * A default stream will work well without further multiple
-        * streams. That's why we use NORETRY | NOWARN.
-        */
-       ret = kzalloc(LZ4_MEM_COMPRESS, GFP_NOIO | __GFP_NORETRY |
-                                       __GFP_NOWARN);
+       ret = kzalloc(LZ4_MEM_COMPRESS, flags);
        if (!ret)
                ret = __vmalloc(LZ4_MEM_COMPRESS,
-                               GFP_NOIO | __GFP_NORETRY | __GFP_NOWARN |
-                               __GFP_ZERO | __GFP_HIGHMEM,
+                               flags | __GFP_ZERO | __GFP_HIGHMEM,
                                PAGE_KERNEL);
        return ret;
 }
index edc549920fa069478e24edf9fa4e416fdbb8adf6..0ab6fce8abe4782994c7f425300a6cce1e21afaf 100644 (file)
 
 #include "zcomp_lzo.h"
 
-static void *lzo_create(void)
+static void *lzo_create(gfp_t flags)
 {
        void *ret;
 
-       /*
-        * This function can be called in swapout/fs write path
-        * so we can't use GFP_FS|IO. And it assumes we already
-        * have at least one stream in zram initialization so we
-        * don't do best effort to allocate more stream in here.
-        * A default stream will work well without further multiple
-        * streams. That's why we use NORETRY | NOWARN.
-        */
-       ret = kzalloc(LZO1X_MEM_COMPRESS, GFP_NOIO | __GFP_NORETRY |
-                                       __GFP_NOWARN);
+       ret = kzalloc(LZO1X_MEM_COMPRESS, flags);
        if (!ret)
                ret = __vmalloc(LZO1X_MEM_COMPRESS,
-                               GFP_NOIO | __GFP_NORETRY | __GFP_NOWARN |
-                               __GFP_ZERO | __GFP_HIGHMEM,
+                               flags | __GFP_ZERO | __GFP_HIGHMEM,
                                PAGE_KERNEL);
        return ret;
 }