From patchwork Wed Jan 3 09:50:06 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: 13509818 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 74DA3C3DA6E for ; Wed, 3 Jan 2024 09:50:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id ED9648D005F; Wed, 3 Jan 2024 04:50:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E87228D0053; Wed, 3 Jan 2024 04:50:49 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D2B248D005F; Wed, 3 Jan 2024 04:50:49 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id BCEF78D0053 for ; Wed, 3 Jan 2024 04:50:49 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 9F7C21A01CE for ; Wed, 3 Jan 2024 09:50:49 +0000 (UTC) X-FDA: 81637530618.04.A312F7E Received: from mail-oo1-f54.google.com (mail-oo1-f54.google.com [209.85.161.54]) by imf17.hostedemail.com (Postfix) with ESMTP id DA84740011 for ; Wed, 3 Jan 2024 09:50:47 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IHBlwAC2; spf=pass (imf17.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.161.54 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=1704275447; 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=Spb8sXhq6BQgZHawgszBp/yoNsRKTOzDWAXTsmTatzQ=; b=VGIfY0fgZszSIyVHbcOoawobyCm9j/XHdLLVIjH0KuSWeyRsjB0w09w7k4a/hOc6/RlcO4 6ZcV+09y3i5BgQezODhb9t9IBz7HIlmBgBvQB1DkhfbgEb0B0tJgDbnTkttiedtxHAEpEZ Io54CJ6ffOXYXeSoAjjQQsVIb6rjnM4= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IHBlwAC2; spf=pass (imf17.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.161.54 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=1704275447; a=rsa-sha256; cv=none; b=lNB0dPuTtn+zrmLSTlQv0RPCRxjPN5+X4FlR+AwkgYXDoXj+fuhEjS5XaxTQZlAiwjA7L1 rtW07LzPnMhse6JGMhGpW3SH5JUEOLiyiaG2NncBKzkKXBvN1zQY7S26VgN8oi3TdbhBB/ vhIB+m3iTvpI3YHFdY5rKAYgZsng32c= Received: by mail-oo1-f54.google.com with SMTP id 006d021491bc7-59502aa878aso2410372eaf.1 for ; Wed, 03 Jan 2024 01:50:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704275447; x=1704880247; 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=Spb8sXhq6BQgZHawgszBp/yoNsRKTOzDWAXTsmTatzQ=; b=IHBlwAC2aGdO/wXTyDPOlsZPuKblOWxAGM4o3OVUid1xWIPeDmu0iXv9FLTB+rb45W 7v1eBYdrIle+ca+Pk4wSA6Y7g9zzh1NJeA5UH9T32DPwg7WvP1N9KEK9HIrmrY6fQ0z0 jn+ynCNVz11V4Xv3GT40VzeJOsqiBhe9KTm5Wqfu6Uh1Esol1DLtbZwTMvvHXMP98sxm gBsK/LunlwynwqzxXiGOgoZs2P7j9zZRXLku1R4PaD8quOyF+EszdLCj9CfvdNKY0Tdy od7TT8KlEN/DVVLqKRLLzo02dKs5Pn6dm3vNlAvC1R17z7r7b85evbKeBZ1fUN3EgDiZ GVaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704275447; x=1704880247; 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=Spb8sXhq6BQgZHawgszBp/yoNsRKTOzDWAXTsmTatzQ=; b=CLjZtexewXmNWtBzbl7MAw1BXRgMaKPSRyLLBXxe3C91Wd6HZEvGmAqzr8aoE/b1Jh ZTnjKT1B0UY9IPOgDvDwOvwzpTp0j7VlH6liCGfY79CVfauA5YAgvwJi5LLYwfWvpDm3 9HrZnKDR5AyKq34pX3ZhFZ4DeL98+RkoZ8mQTgIVch/VC1K/3wZDs6/LCS6XLczXY8P5 JG8kruoqK8XuBMIHhYsFuApzDJK5n4dTuyWQoMWg9JUX8j6A9h/5Y5mSJN2uVwq0ERTK 6ZVAwnnN3MUMvXHwHzZFeA86PUDvhMR/WiOAeYyVu/GCLKo1BBtrHN4EB5hLfSlJzzn0 RVsw== X-Gm-Message-State: AOJu0Yxh5r/mYQX1L8TOdMM6acwn0rcNyLhGCRVw9WomDzxPk2icVNEc GYLmGBzxupIeDXmEXCdaik0= X-Google-Smtp-Source: AGHT+IGWL4R/FI9TYmsj+r7+/K6fqa31rQlyfEGBvFn+SUDBIfMJqSQf7Q/5XUbHS6iSKuuDD2GKeA== X-Received: by 2002:a05:6358:7f1e:b0:172:e3f6:12c0 with SMTP id p30-20020a0563587f1e00b00172e3f612c0mr17022730rwn.46.1704275446906; Wed, 03 Jan 2024 01:50:46 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:a7d6:f37a:9130:cd96]) by smtp.gmail.com with ESMTPSA id a34-20020a631a22000000b005c65e82a0cbsm21823483pga.17.2024.01.03.01.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 01:50:46 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: herbert@gondor.apana.org.au, davem@davemloft.net, akpm@linux-foundation.org, ddstreet@ieee.org, sjenning@redhat.com, vitaly.wool@konsulko.com, linux-crypto@vger.kernel.org Cc: chriscli@google.com, chrisl@kernel.org, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, nphamcs@gmail.com, yosryahmed@google.com, zhouchengming@bytedance.com, Barry Song Subject: [PATCH 3/3] crypto: scompress: remove memcpy if sg_nents is 1 Date: Wed, 3 Jan 2024 22:50:06 +1300 Message-Id: <20240103095006.608744-4-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240103095006.608744-1-21cnbao@gmail.com> References: <20240103095006.608744-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: DA84740011 X-Rspam-User: X-Stat-Signature: biomdyggndowq3t8ugp5195oz16ohdjb X-Rspamd-Server: rspam01 X-HE-Tag: 1704275447-262023 X-HE-Meta: U2FsdGVkX1+BRwIQL10QtnNR2Ev8NA/ePHncHpRQk5mv0RIM2fRqWpEsDtnZ3n0XHyVCYAQWUJJMzjGKqp+X4A7LuHCBe2YS+o5xcS7CMsEE6Hu0r100JR0FvHhTEsl+4jmDCwx8mb1MQeL2m+TseZ3OozvaZ4AFlwSzb0DWDuCmq9KwV2d1AyMD41yYtY++IYY0NjWgSUo5ds63JUZVW5bLae3qiiYXqtQ12VTNSkNxSKVkgEn54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nb8EH5uY9aseuV5wqjl8CNWdDIolLKWwd23DnPElJz1OqDwisb7W6Ql991BoQfty2TbyfdqmsHSTdiiPQDZvH6wq3D2fyRkBtoM7KQN9kGy+NCmtB7EX135gYx2JQg5R30ShtNjePdeX634mZh0voC4DAJp1jq5vTTIU9Jb4agaUEvFQtlc3ZjuZQzuBn8bv8am6nDSbpb9QpiHQwmofyJugdKTsERIY75vjWyox8ExgDNNnzDDH4pTV7XtTg03tZrk6q/TUL0dBCi7CjGpBxkvnFpcr069C9rRnbTJSqCEHIGyc8PQ4DDCXKie X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-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 | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) diff --git a/crypto/scompress.c b/crypto/scompress.c index 442a82c9de7d..d1bb40ef83a2 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; int ret; if (!req->src || !req->slen || req->slen > SCOMP_SCRATCH_SIZE) @@ -131,13 +132,26 @@ 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); @@ -146,10 +160,17 @@ static int scomp_acomp_comp_decomp(struct acomp_req *req, int dir) 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); + } } out: + if (src != scratch->src) + kunmap_local(src); + if (dst != scratch->dst) + kunmap_local(dst); + spin_unlock(&scratch->lock); return ret; }