From patchwork Sat Feb 17 04:51:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Barry Song <21cnbao@gmail.com> X-Patchwork-Id: 13561233 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7EB5DC48BF6 for ; Sat, 17 Feb 2024 04:51:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE3FE6B00AA; Fri, 16 Feb 2024 23:51:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E94CF6B00AC; Fri, 16 Feb 2024 23:51:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0D236B00AD; Fri, 16 Feb 2024 23:51:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BB5EC6B00AA for ; Fri, 16 Feb 2024 23:51:43 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5026DA002F for ; Sat, 17 Feb 2024 04:51:43 +0000 (UTC) X-FDA: 81800072886.23.E6B60BF Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) by imf21.hostedemail.com (Postfix) with ESMTP id A63611C0004 for ; Sat, 17 Feb 2024 04:51:41 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YuDxUr3Y; spf=pass (imf21.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.166.45 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708145501; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=kW/qQndLj7MYeSMYgAPMliKXg25U647vW1M3U8+Bgew=; b=C62WtD+g2If+pLeAMYBR4C5I4LD0b0Ps6NZp9aa9KaAsRu+0xcNntTNFzVEP1TNViuv+GL iWdenyMHl9GdOSlCZZzlZPzdaZyAIGXhiP8qwU9Trxb4m8kN8sRvLuITenbaMJpeBEDmSX dPa0kv+C7CIxfxP6TeobVAhQbXEpRkI= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YuDxUr3Y; spf=pass (imf21.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.166.45 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708145501; a=rsa-sha256; cv=none; b=qIs4aZdEBICwfAF4viGaA7tl49LwWMGwj/WV53iBhIG/kx/P4VIIHqyF5RhMz4YwYXo/YV Ci4CWQsTL7ioGksVxf7SdaG18ZNDiNkxlx7HWqCZCZW4nUKQnydREJL5Vl/uliu38+HN+A N8EAMI1W7RoqvfLBGOYwvGLnoKAkh08= Received: by mail-io1-f45.google.com with SMTP id ca18e2360f4ac-7c3e01a7fe0so112228239f.2 for ; Fri, 16 Feb 2024 20:51:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708145500; x=1708750300; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kW/qQndLj7MYeSMYgAPMliKXg25U647vW1M3U8+Bgew=; b=YuDxUr3Y+QcdoF+ouIpufiHfhztKvwU/dCJ9P+We6pBKkULjwrc8viDThhAKsxDQjP p+dRWB0wBbhcd4Mn7oy54qHJcmQCjCwVdIwF0RHvv6ujih1yBWOC3UGmQ+xEF3Q022Y/ 89FwTBmlEC4u/FgW+lnjfHAEPekrKo+wmrIbj6Yd6O12Z3/az4TFXFfpSyhCtqNlan9d Iih4pwbsfir4hFtAWujF0120yAtZfq323VPUmCpujfCj2NSbmkMn+9hC1cXHqpO+SnWV OSiKytR/EssGSFmlZVpYh3cVTscAPQV4kDBQOWF/S0CuCqu4uEDv/uBRgvyLlhiUK1uf rXSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708145500; x=1708750300; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kW/qQndLj7MYeSMYgAPMliKXg25U647vW1M3U8+Bgew=; b=gfuHNwTnn2w4tbu3qS4HmgdCDmRQKcjfgwFD/7ILAIsqtJWwvMwiu0HXwt/zKqYp/g ljIi9MLIebuqMM8prGxkcZjbU8DJuRM+cwVbbsrQmxwbIfkMeuNq0x0Wg5ecD3a61LNX FxqOY+V4Aj0Tq+qQXrEZnWyqvimrkqC3/uFwH2OgHyey1/5+AZvK7tC/YUI8fYSSzqap 0gIGljwLMkSNkYa4EDfi8itxu81/iDBgTu6bCybrO0oCYRoTnySicSPpiQruBo452Eh3 aHSppYW3EvoHz9rWZSNlnWSaLdF8VZN8HY2CCmN37vhjaenireFfP+ckd1fl+pva3lmt xyLQ== X-Forwarded-Encrypted: i=1; AJvYcCV0D6kPVx4Vp7y4uFcJGp6l8li4xGGkkULQR6QY1wTiSqewKh7BfVYB++/3b5ZEh73fPVWsd7TOaYoYrM8F2upcs0E= X-Gm-Message-State: AOJu0Yy6BMO4wFz5koZmtE2UCOX2Ccy4bvgAOHB68iK1XReHl9ENAmdZ E07VNzN3u7DEXrN94Umi9WfycfMRP/OQf/V2dDT1rzSlYdlk9J3Z X-Google-Smtp-Source: AGHT+IEOW4DS9BP7Ysw7VmEnIq9KlLgS920AXTvAFRO+XZXAmVk4YcCGu0RWQu1NKlAdLNbOmorNFg== X-Received: by 2002:a05:6e02:13e2:b0:363:c63a:7975 with SMTP id w2-20020a056e0213e200b00363c63a7975mr6639713ilj.24.1708145500701; Fri, 16 Feb 2024 20:51:40 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:e82e:22f2:1bdb:989f]) by smtp.gmail.com with ESMTPSA id n14-20020a635c4e000000b005dc2ca5b667sm610703pgm.10.2024.02.16.20.51.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 20:51:40 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: akpm@linux-foundation.org, davem@davemloft.net, hannes@cmpxchg.org, herbert@gondor.apana.org.au, linux-crypto@vger.kernel.org, linux-mm@kvack.org, nphamcs@gmail.com, yosryahmed@google.com, zhouchengming@bytedance.com Cc: chriscli@google.com, chrisl@kernel.org, ddstreet@ieee.org, linux-kernel@vger.kernel.org, sjenning@redhat.com, vitaly.wool@konsulko.com, Barry Song Subject: [PATCH v3 3/3] crypto: scompress: remove memcpy if sg_nents is 1 Date: Sat, 17 Feb 2024 17:51:02 +1300 Message-Id: <20240217045102.55339-4-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240217045102.55339-1-21cnbao@gmail.com> References: <20240217045102.55339-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: A63611C0004 X-Rspam-User: X-Stat-Signature: ffsw7deoqrqz36no9wnu98hwr1kyszpg X-Rspamd-Server: rspam01 X-HE-Tag: 1708145501-195840 X-HE-Meta: U2FsdGVkX1/BAnioSwup94f7f2J+SJXH14bgCGJxAcITliPk2x+XcTqMPD4QQFsZofvekrfxMQzacFJbOHzNNoiaRleN0oVV6W820RR4VlqlO4M9cRgJ05zxhGUNC3Lv2Pzb7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mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Barry Song while sg_nents is 1 which is always true for the current kernel as the only user - zswap is the case, we should remove two big memcpy. Signed-off-by: Barry Song Tested-by: Chengming Zhou --- crypto/scompress.c | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/crypto/scompress.c b/crypto/scompress.c index b108a30a7600..50a487eac792 100644 --- a/crypto/scompress.c +++ b/crypto/scompress.c @@ -117,6 +117,7 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) struct crypto_scomp *scomp = *tfm_ctx; void **ctx = acomp_request_ctx(req); struct scomp_scratch *scratch; + void *src, *dst; unsigned int dlen; int ret; @@ -134,13 +135,25 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) scratch = raw_cpu_ptr(&scomp_scratch); spin_lock(&scratch->lock); - scatterwalk_map_and_copy(scratch->src, req->src, 0, req->slen, 0); + if (sg_nents(req->src) == 1) { + src = kmap_local_page(sg_page(req->src)) + req->src->offset; + } else { + scatterwalk_map_and_copy(scratch->src, req->src, 0, + req->slen, 0); + src = scratch->src; + } + + if (req->dst && sg_nents(req->dst) == 1) + dst = kmap_local_page(sg_page(req->dst)) + req->dst->offset; + else + dst = scratch->dst; + if (dir) - ret = crypto_scomp_compress(scomp, scratch->src, req->slen, - scratch->dst, &req->dlen, *ctx); + ret = crypto_scomp_compress(scomp, src, req->slen, + dst, &req->dlen, *ctx); else - ret = crypto_scomp_decompress(scomp, scratch->src, req->slen, - scratch->dst, &req->dlen, *ctx); + ret = crypto_scomp_decompress(scomp, src, req->slen, + dst, &req->dlen, *ctx); if (!ret) { if (!req->dst) { req->dst = sgl_alloc(req->dlen, GFP_ATOMIC, NULL); @@ -152,10 +165,19 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) ret = -ENOSPC; goto out; } - scatterwalk_map_and_copy(scratch->dst, req->dst, 0, req->dlen, - 1); + if (dst == scratch->dst) { + scatterwalk_map_and_copy(scratch->dst, req->dst, 0, + req->dlen, 1); + } else { + flush_dcache_page(sg_page(req->dst)); + } } out: + if (src != scratch->src) + kunmap_local(src); + if (dst != scratch->dst) + kunmap_local(dst); + spin_unlock(&scratch->lock); return ret; }