From patchwork Fri Sep 18 05:19:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonsoo Kim X-Patchwork-Id: 7212951 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B63F29F380 for ; Fri, 18 Sep 2015 05:20:48 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9E1D220710 for ; Fri, 18 Sep 2015 05:20:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 77FA5204EC for ; Fri, 18 Sep 2015 05:20:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752654AbbIRFUV (ORCPT ); Fri, 18 Sep 2015 01:20:21 -0400 Received: from mail-pa0-f51.google.com ([209.85.220.51]:35711 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752529AbbIRFUR (ORCPT ); Fri, 18 Sep 2015 01:20:17 -0400 Received: by pacfv12 with SMTP id fv12so40912253pac.2; Thu, 17 Sep 2015 22:20:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qyNghl4aoZAMZA9AkXM96CMbrUxAbapiF6Z7L2LCZ6I=; b=tuAxJ9xry8bdIbdxtTnf+vkDNm8BoAG17jbvDuza48+1ingiziJcxaH0TNZJEXrwyN bWSOOuk6DROJ4+4F051lGvTP2zwpTzc/OMV9ZldUQeCnbfo3FXY+8PX2shZsNLckQmmO R3kcwMXr6ftTH5hDO8+/yQoexCrq7djo5CHrkj/0QaElbwD/+NEerVMcFaqEKN1S7vr/ 0rUnU67oRotSY1KcQixLdrzfgQaBiBwXuqwdThI5DZPggIzfCOKURAA/Mm1eflwI3lFc UvlI0zjjDxCvlycayDwbRxvHGxuGh64OLYe2gMisOM+4uImyy5Vl+MUoMPuCNtM3ukTO Jmgw== X-Received: by 10.66.254.201 with SMTP id ak9mr4823760pad.151.1442553617268; Thu, 17 Sep 2015 22:20:17 -0700 (PDT) Received: from localhost.localdomain ([119.69.155.252]) by smtp.gmail.com with ESMTPSA id bi2sm6443526pbb.45.2015.09.17.22.20.14 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Sep 2015 22:20:16 -0700 (PDT) From: Joonsoo Kim X-Google-Original-From: Joonsoo Kim To: Andrew Morton Cc: Minchan Kim , Nitin Gupta , Sergey Senozhatsky , linux-kernel@vger.kernel.org, linux-crypto@vger.kernel.org, Herbert Xu , "David S. Miller" , Stephan Mueller , Joonsoo Kim Subject: [PATCH v3 9/9] zram: use crypto decompress_noctx API Date: Fri, 18 Sep 2015 14:19:24 +0900 Message-Id: <1442553564-3476-10-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1442553564-3476-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1442553564-3476-1-git-send-email-iamjoonsoo.kim@lge.com> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Crypto subsystem now supports decompress_noctx 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 decompress_noctx 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-noctx Read 10411701.88 6426911.62 9423894.38 Re-read 10017386.62 6428218.88 11000063.50 Signed-off-by: Joonsoo Kim --- drivers/block/zram/zcomp.c | 24 +++++++++++++++++++++++- drivers/block/zram/zcomp.h | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/block/zram/zcomp.c b/drivers/block/zram/zcomp.c index c2ed7c8..a020200 100644 --- a/drivers/block/zram/zcomp.c +++ b/drivers/block/zram/zcomp.c @@ -319,9 +319,12 @@ 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) { + if (comp->tfm_noctx) + return NULL; + return zcomp_strm_find(comp); } @@ -346,11 +349,18 @@ int zcomp_decompress(struct zcomp *comp, struct zcomp_strm *zstrm, { unsigned int size = PAGE_SIZE; + if (!zstrm) { + return crypto_comp_decompress_noctx(comp->tfm_noctx, + 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_noctx(comp->tfm_noctx); comp->destroy(comp); kfree(comp); } @@ -366,6 +376,7 @@ struct zcomp *zcomp_create(const char *compress, int max_strm) { struct zcomp *comp; const char *backend; + struct crypto_comp *tfm; backend = find_backend(compress); if (!backend) @@ -384,5 +395,16 @@ struct zcomp *zcomp_create(const char *compress, int max_strm) kfree(comp); return ERR_PTR(-ENOMEM); } + + /* + * 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_noctx(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);