2 * Copyright (C) 2014 Sergey Senozhatsky.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
10 #include <linux/kernel.h>
11 #include <linux/slab.h>
12 #include <linux/lz4.h>
13 #include <linux/vmalloc.h>
16 #include "zcomp_lz4.h"
18 static void *zcomp_lz4_create(void)
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.
30 ret = kzalloc(LZ4_MEM_COMPRESS, GFP_NOIO | __GFP_NORETRY |
33 ret = __vmalloc(LZ4_MEM_COMPRESS,
34 GFP_NOIO | __GFP_NORETRY | __GFP_NOWARN |
35 __GFP_ZERO | __GFP_HIGHMEM,
40 static void zcomp_lz4_destroy(void *private)
45 static int zcomp_lz4_compress(const unsigned char *src, unsigned char *dst,
46 size_t *dst_len, void *private)
48 /* return : Success if return 0 */
49 return lz4_compress(src, PAGE_SIZE, dst, dst_len, private);
52 static int zcomp_lz4_decompress(const unsigned char *src, size_t src_len,
55 size_t dst_len = PAGE_SIZE;
56 /* return : Success if return 0 */
57 return lz4_decompress_unknownoutputsize(src, src_len, dst, &dst_len);
60 struct zcomp_backend zcomp_lz4 = {
61 .compress = zcomp_lz4_compress,
62 .decompress = zcomp_lz4_decompress,
63 .create = zcomp_lz4_create,
64 .destroy = zcomp_lz4_destroy,