All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
To: Joonsoo Kim <js1304@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>,
	Minchan Kim <minchan@kernel.org>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S. Miller" <davem@davemloft.net>,
	Stephan Mueller <smueller@chronox.de>,
	Joonsoo Kim <iamjoonsoo.kim@lge.com>,
	Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>,
	Sergey Senozhatsky <sergey.senozhatsky@gmail.com>,
	linux-crypto@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [RFC][PATCH 9/9] zram: use crypto CRYPTO_ALG_TFM_MAY_SHARE API
Date: Mon, 21 Sep 2015 22:25:53 +0900	[thread overview]
Message-ID: <1442841953-11588-1-git-send-email-sergey.senozhatsky@gmail.com> (raw)
In-Reply-To: <1442841229-8122-1-git-send-email-sergey.senozhatsky@gmail.com>

Crypto subsystem now supports CRYPTO_ALG_TFM_MAY_SHARE API that
requires special tfm_noctx. This tfm can be shared by multiple
concurrent decompress user because this API doesn't rely on this
tfm object except to fetch decompress function pointer.

Until changing to use crypto API, zram doesn't require any zstrm
on decompress so decompress is parallelized unlimitedly. But, previous
patch make zram to use crypto API and this requires one zstrm on every
decompress users so, in some zstrm contended situations, zram's
performance would be degraded.

This patch makes zram use CRYPTO_ALG_TFM_MAY_SHARE API and
restore zram's performance as the time that zram doesn't use
crypto API.

Following is zram's read performance number.

* iozone -t 4 -R -r 16K -s 60M -I +Z -i 0 -i 1
* max_stream is set to 1
* Output is in Kbytes/sec

zram-base vs zram-crypto vs zram-crypto-CRYPTO_ALG_TFM_MAY_SHARE

Read		10411701.88	6426911.62	9423894.38
Re-read		10017386.62	6428218.88	11000063.50

Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com>
Signed-off-by: Sergey Senozhatsky <sergey.senozhatsky@gmail.com>
---
 drivers/block/zram/zcomp.c | 27 +++++++++++++++++++++++++--
 drivers/block/zram/zcomp.h |  1 +
 2 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c
index 6219d4d..b768dc9 100644
--- a/drivers/block/zram/zcomp.c
+++ b/drivers/block/zram/zcomp.c
@@ -319,9 +319,14 @@ void zcomp_compress_end(struct zcomp *comp, struct zcomp_strm *zstrm)
 	zcomp_strm_release(comp, zstrm);
 }
 
-/* Never return NULL, may sleep */
+/* May return NULL, may sleep */
 struct zcomp_strm *zcomp_decompress_begin(struct zcomp *comp)
 {
+	struct crypto_comp *tfm = comp->tfm_noctx;
+
+	if (tfm && crypto_tfm_may_share(crypto_comp_tfm(tfm)))
+		return NULL;
+
 	return zcomp_strm_find(comp);
 }
 
@@ -345,12 +350,18 @@ int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm,
 		unsigned int src_len, unsigned char *dst)
 {
 	unsigned int size = PAGE_SIZE;
+	struct crypto_comp *tfm = comp->tfm_noctx;
+
+	if (tfm && crypto_tfm_may_share(crypto_comp_tfm(tfm)))
+		return crypto_comp_decompress(tfm, src, src_len, dst, &size);
 
-	return crypto_comp_decompress(zstrm->tfm, src, src_len,	dst, &size);
+	return crypto_comp_decompress(zstrm->tfm, src, src_len, dst, &size);
 }
 
 void zcomp_destroy(struct zcomp *comp)
 {
+	if (comp->tfm_noctx)
+		crypto_free_comp(comp->tfm_noctx);
 	comp->destroy(comp);
 	kfree(comp);
 }
@@ -367,6 +378,7 @@ struct zcomp *zcomp_create(const char *compress, int max_strm)
 {
 	struct zcomp *comp;
 	const char *backend;
+	struct crypto_comp *tfm;
 	int error;
 
 	backend = find_backend(compress);
@@ -386,5 +398,16 @@ struct zcomp *zcomp_create(const char *compress, int max_strm)
 		kfree(comp);
 		return ERR_PTR(error);
 	}
+
+	/*
+	 * Prepare to use crypto decompress_noctx API. One tfm is required
+	 * to initialize crypto algorithm properly and fetch corresponding
+	 * function pointer. But, it is sharable for multiple concurrent
+	 * decompress users.
+	 */
+	tfm = crypto_alloc_comp(compress, 0, 0);
+	if (!IS_ERR(tfm))
+		comp->tfm_noctx = tfm;
+
 	return comp;
 }
diff --git a/drivers/block/zram/zcomp.h b/drivers/block/zram/zcomp.h
index 4f9df8e..c76d8e4 100644
--- a/drivers/block/zram/zcomp.h
+++ b/drivers/block/zram/zcomp.h
@@ -26,6 +26,7 @@ struct zcomp_strm {
 /* dynamic per-device compression frontend */
 struct zcomp {
 	void *stream;
+	struct crypto_comp *tfm_noctx;
 	const char *backend;
 
 	struct zcomp_strm *(*strm_find)(struct zcomp *comp);
-- 
2.5.3

  parent reply	other threads:[~2015-09-21 13:27 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-18  5:19 [PATCH v3 0/9] zram: introduce crypto decompress noctx API and use it on zram Joonsoo Kim
2015-09-18  5:19 ` [PATCH v3 1/9] crypto: introduce decompression API that can be called via sharable tfm object Joonsoo Kim
2015-09-21  5:38   ` Sergey Senozhatsky
2015-09-25  5:29     ` Joonsoo Kim
2015-09-21  6:18   ` Sergey Senozhatsky
2015-09-25  5:26     ` Joonsoo Kim
2015-09-25  7:56       ` Sergey Senozhatsky
2015-09-25  7:58         ` Herbert Xu
2015-09-22 12:43   ` Herbert Xu
2015-09-25  5:25     ` Joonsoo Kim
2015-09-18  5:19 ` [PATCH v3 2/9] crypto/lzo: support decompress_noctx Joonsoo Kim
2015-09-18  5:19 ` [PATCH v3 3/9] crypyo/lz4: " Joonsoo Kim
2015-09-18  5:19 ` [PATCH v3 4/9] crypto/lz4hc: " Joonsoo Kim
2015-09-18  5:19 ` [PATCH v3 5/9] crypto/842: " Joonsoo Kim
2015-09-18  5:19 ` [PATCH v3 6/9] zram: make stream find and release functions static Joonsoo Kim
2015-09-20 23:39   ` Minchan Kim
2015-09-18  5:19 ` [PATCH v3 7/9] zram: pass zstrm down to decompression path Joonsoo Kim
2015-09-20 23:42   ` Minchan Kim
2015-09-18  5:19 ` [PATCH v3 8/9] zram: use crypto API for compression Joonsoo Kim
2015-09-21  3:45   ` Minchan Kim
2015-09-25  5:44     ` Joonsoo Kim
2015-09-21  5:19   ` Sergey Senozhatsky
2015-09-25  5:43     ` Joonsoo Kim
2015-09-25  7:50       ` Sergey Senozhatsky
2015-09-18  5:19 ` [PATCH v3 9/9] zram: use crypto decompress_noctx API Joonsoo Kim
2015-09-21  3:51   ` Minchan Kim
2015-09-25  5:46     ` Joonsoo Kim
2015-09-25  7:51       ` Sergey Senozhatsky
2015-09-21  5:29   ` Sergey Senozhatsky
2015-09-25  5:48     ` Joonsoo Kim
2015-09-21  7:56   ` Sergey Senozhatsky
2015-09-25  5:47     ` Joonsoo Kim
2015-09-21  3:58 ` [PATCH v3 0/9] zram: introduce crypto decompress noctx API and use it on zram Minchan Kim
2015-09-25  5:31   ` Joonsoo Kim
2015-09-21 13:13 ` [RFC][PATCH 0/9] use CRYPTO_ALG_TFM_MAY_SHARE cra flag (full patchset) Sergey Senozhatsky
2015-09-21 13:13   ` [RFC][PATCH 1/9] crypto: introduce CRYPTO_ALG_TFM_MAY_SHARE flag Sergey Senozhatsky
2015-09-21 13:13   ` [RFC][PATCH 2/9] crypto/lzo: set CRYPTO_ALG_TFM_MAY_SHARE Sergey Senozhatsky
2015-09-21 13:13   ` [RFC][PATCH 3/9] crypto/lz4: " Sergey Senozhatsky
2015-09-21 13:13   ` [RFC][PATCH 4/9] crypto/lz4hc: " Sergey Senozhatsky
2015-09-21 13:13   ` [RFC][PATCH 5/9] crypto/842: " Sergey Senozhatsky
2015-09-21 13:13   ` [RFC][PATCH 6/9] zram: make stream find and release functions static Sergey Senozhatsky
2015-09-21 13:13   ` [RFC][PATCH 7/9] zram: pass zstrm down to decompression path Sergey Senozhatsky
2015-09-21 13:17   ` [RFC][PATCH 0/9] use CRYPTO_ALG_TFM_MAY_SHARE cra flag (full patchset) Sergey Senozhatsky
2015-09-21 13:25   ` Sergey Senozhatsky [this message]
2015-09-21 13:40   ` [RFC][PATCH 8/9] zram: use crypto API for compression Sergey Senozhatsky

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=1442841953-11588-1-git-send-email-sergey.senozhatsky@gmail.com \
    --to=sergey.senozhatsky@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=davem@davemloft.net \
    --cc=herbert@gondor.apana.org.au \
    --cc=iamjoonsoo.kim@lge.com \
    --cc=js1304@gmail.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=minchan@kernel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.