From: Joonsoo Kim <js1304@gmail.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Minchan Kim <minchan@kernel.org>, Nitin Gupta <ngupta@vflare.org>,
Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Stephan Mueller <smueller@chronox.de>,
linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org,
Joonsoo Kim <iamjoonsoo.kim@lge.com>
Subject: [PATCH v4 3/8] crypto/lz4: support contextless compressiona API
Date: Wed, 14 Oct 2015 16:38:19 +0900 [thread overview]
Message-ID: <1444808304-29320-4-git-send-email-iamjoonsoo.kim@lge.com> (raw)
In-Reply-To: <1444808304-29320-1-git-send-email-iamjoonsoo.kim@lge.com>
Now, contextless compression API is introduced and it can reduce
memory overhead in some cases. All compression algorithm will
support it.
Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
---
crypto/lz4.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 67 insertions(+), 10 deletions(-)
diff --git a/crypto/lz4.c b/crypto/lz4.c
index aefbcea..9720409 100644
--- a/crypto/lz4.c
+++ b/crypto/lz4.c
@@ -23,36 +23,53 @@
#include <linux/crypto.h>
#include <linux/vmalloc.h>
#include <linux/lz4.h>
+#include <crypto/compress.h>
struct lz4_ctx {
void *lz4_comp_mem;
};
+static void *lz4_alloc_context(struct crypto_ccomp *tfm)
+{
+ void *ctx;
+
+ ctx = vmalloc(LZ4_MEM_COMPRESS);
+ if (!ctx)
+ return ERR_PTR(-ENOMEM);
+
+ return ctx;
+}
+
static int lz4_init(struct crypto_tfm *tfm)
{
struct lz4_ctx *ctx = crypto_tfm_ctx(tfm);
- ctx->lz4_comp_mem = vmalloc(LZ4_MEM_COMPRESS);
- if (!ctx->lz4_comp_mem)
+ ctx->lz4_comp_mem = lz4_alloc_context(NULL);
+ if (IS_ERR(ctx->lz4_comp_mem))
return -ENOMEM;
return 0;
}
+static void lz4_free_context(struct crypto_ccomp *tfm, void *ctx)
+{
+ vfree(ctx);
+}
+
static void lz4_exit(struct crypto_tfm *tfm)
{
struct lz4_ctx *ctx = crypto_tfm_ctx(tfm);
- vfree(ctx->lz4_comp_mem);
+
+ lz4_free_context(NULL, ctx->lz4_comp_mem);
}
-static int lz4_compress_crypto(struct crypto_tfm *tfm, const u8 *src,
- unsigned int slen, u8 *dst, unsigned int *dlen)
+static int __lz4_compress_crypto(const u8 *src, unsigned int slen,
+ u8 *dst, unsigned int *dlen, void *ctx)
{
- struct lz4_ctx *ctx = crypto_tfm_ctx(tfm);
size_t tmp_len = *dlen;
int err;
- err = lz4_compress(src, slen, dst, &tmp_len, ctx->lz4_comp_mem);
+ err = lz4_compress(src, slen, dst, &tmp_len, ctx);
if (err < 0)
return -EINVAL;
@@ -61,8 +78,16 @@ static int lz4_compress_crypto(struct crypto_tfm *tfm, const u8 *src,
return 0;
}
-static int lz4_decompress_crypto(struct crypto_tfm *tfm, const u8 *src,
- unsigned int slen, u8 *dst, unsigned int *dlen)
+static int lz4_compress_crypto(struct crypto_tfm *tfm, const u8 *src,
+ unsigned int slen, u8 *dst, unsigned int *dlen)
+{
+ struct lz4_ctx *ctx = crypto_tfm_ctx(tfm);
+
+ return __lz4_compress_crypto(src, slen, dst, dlen, ctx->lz4_comp_mem);
+}
+
+static int __lz4_decompress_crypto(const u8 *src, unsigned int slen,
+ u8 *dst, unsigned int *dlen, void *ctx)
{
int err;
size_t tmp_len = *dlen;
@@ -76,6 +101,12 @@ static int lz4_decompress_crypto(struct crypto_tfm *tfm, const u8 *src,
return err;
}
+static int lz4_decompress_crypto(struct crypto_tfm *tfm, const u8 *src,
+ unsigned int slen, u8 *dst, unsigned int *dlen)
+{
+ return __lz4_decompress_crypto(src, slen, dst, dlen, NULL);
+}
+
static struct crypto_alg alg_lz4 = {
.cra_name = "lz4",
.cra_flags = CRYPTO_ALG_TYPE_COMPRESS,
@@ -89,14 +120,40 @@ static struct crypto_alg alg_lz4 = {
.coa_decompress = lz4_decompress_crypto } }
};
+static struct ccomp_alg ccomp = {
+ .alloc_context = lz4_alloc_context,
+ .free_context = lz4_free_context,
+ .compress = __lz4_compress_crypto,
+ .decompress = __lz4_decompress_crypto,
+ .flags = CCOMP_TYPE_DECOMP_NOCTX,
+ .base = {
+ .cra_name = "lz4",
+ .cra_flags = CRYPTO_ALG_TYPE_CCOMPRESS,
+ .cra_module = THIS_MODULE,
+ }
+};
+
static int __init lz4_mod_init(void)
{
- return crypto_register_alg(&alg_lz4);
+ int ret;
+
+ ret = crypto_register_alg(&alg_lz4);
+ if (ret)
+ return ret;
+
+ ret = crypto_register_ccomp(&ccomp);
+ if (ret) {
+ crypto_unregister_alg(&alg_lz4);
+ return ret;
+ }
+
+ return ret;
}
static void __exit lz4_mod_fini(void)
{
crypto_unregister_alg(&alg_lz4);
+ crypto_unregister_ccomp(&ccomp);
}
module_init(lz4_mod_init);
--
1.9.1
next prev parent reply other threads:[~2015-10-14 7:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-10-14 7:38 [PATCH v4 0/8] zram: introduce contextless compression API and use it on zram Joonsoo Kim
2015-10-14 7:38 ` [PATCH v4 1/8] crypto/compress: introduce contextless compression and remove unused pcomp Joonsoo Kim
2015-10-14 7:38 ` [PATCH v4 2/8] crypto/lzo: support contextless compression API Joonsoo Kim
2015-10-14 7:38 ` Joonsoo Kim [this message]
2015-10-14 8:38 ` [PATCH v4 3/8] crypto/lz4: support contextless compressiona API kbuild test robot
2015-10-14 7:38 ` [PATCH v4 4/8] crypto/deflate: support contextless compression API Joonsoo Kim
2015-10-14 8:33 ` kbuild test robot
2015-10-14 10:08 ` kbuild test robot
2015-10-14 10:26 ` kbuild test robot
2015-10-14 7:38 ` [PATCH v4 5/8] zram: make stream find and release functions static Joonsoo Kim
2015-10-14 7:38 ` [PATCH v4 6/8] zram: pass zstrm down to decompression path Joonsoo Kim
2015-10-14 7:38 ` [PATCH v4 7/8] zram: use crypto contextless compression API to (de)compress Joonsoo Kim
2015-10-15 0:38 ` Sergey Senozhatsky
2015-10-15 1:07 ` Joonsoo Kim
2015-10-15 1:53 ` Sergey Senozhatsky
2015-10-14 7:38 ` [PATCH v4 8/8] zram: enable contextless compression alg in zram Joonsoo Kim
2015-10-15 0:29 ` Sergey Senozhatsky
2015-10-15 0:45 ` Joonsoo Kim
2015-10-15 2:05 ` Sergey Senozhatsky
2015-10-15 2:48 ` Joonsoo Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1444808304-29320-4-git-send-email-iamjoonsoo.kim@lge.com \
--to=js1304@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=davem@davemloft.net \
--cc=herbert@gondor.apana.org.au \
--cc=iamjoonsoo.kim@lge.com \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=minchan@kernel.org \
--cc=ngupta@vflare.org \
--cc=sergey.senozhatsky.work@gmail.com \
--cc=smueller@chronox.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®