From patchwork Wed Jan 3 05:31:34 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: 13509676 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 F3B5FC3DA6E for ; Wed, 3 Jan 2024 05:31:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 625D16B02AF; Wed, 3 Jan 2024 00:31:57 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D6286B02B0; Wed, 3 Jan 2024 00:31:57 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 49DAB6B02B2; Wed, 3 Jan 2024 00:31:57 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 3B64F6B02AF for ; Wed, 3 Jan 2024 00:31:57 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 0AA3F140C0D for ; Wed, 3 Jan 2024 05:31:57 +0000 (UTC) X-FDA: 81636878274.29.6AB1BD8 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf26.hostedemail.com (Postfix) with ESMTP id 3587B140006 for ; Wed, 3 Jan 2024 05:31:53 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nGhKxZs2; spf=pass (imf26.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.179 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=1704259914; 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=w8EF56Awke+XwfA1XTbGHCbaLEHxvYXZLhOGAQUZsss=; b=tBId89eX3GNq1J6jUI7Pj2Pw/mBwmXgVTc7zGvycm7h7HNaf9omh5khcq4kFRD79na8PAK 4P5NipBxFCxQc3pL/jEWXjUiQbBniXpGh5BsjyV7SW7gpUlrq5BS1tgrPiuVjXzfANDp0z H7mFE5isbyg9DJGmhVelXjQmkSTJ8rc= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704259914; a=rsa-sha256; cv=none; b=Sb97Ajew4PsCcm6BvQnP9a98K50FpjspsNaWKw4VcsnKLc04g6rulS25nq95Dnk1I2tDr+ MSq90RD5/+07ja2jEr5iig5X+gWBCCT2neZQFagaqs8T1T7M+8VpuCp8AyQNZlMCD5xeMN 6QjZ/srTuD60BSqYYmN02yUOQf7bBNM= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=nGhKxZs2; spf=pass (imf26.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.179 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f179.google.com with SMTP id 41be03b00d2f7-5cda24a77e0so3353277a12.2 for ; Tue, 02 Jan 2024 21:31:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704259913; x=1704864713; 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=w8EF56Awke+XwfA1XTbGHCbaLEHxvYXZLhOGAQUZsss=; b=nGhKxZs2I9h/0pdp/sDNhuEG9LhG7TI5j6KVV0GoCatd3f25yDPklazbfZnnXR17xV GMrcVVr7LFQ6dRhR7hsxsGRZmcZ4O/LP3CguBMFNRotX7Z3UK0gBty8xFAKOd4ReJQdD CzIPtaJlReAWlHE5EUmn4kEfOgq0mGGzRsB7DBHnp20jagudcPqxKrd13nQxkH/Ekz+i ozzTns6ePPL8yJ5FI5JLqfAy89DFV36uX4ZjQ1WTQTBfPrMw0KBxn7jjr4yS5J33Pphc 3TCmWoaGJGyvSanfhX6F2C5WPA2oqu4QNtk1dv2V9aQc4Xr/CgmaScYx0Hm0pYu14p0C 5VaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704259913; x=1704864713; 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=w8EF56Awke+XwfA1XTbGHCbaLEHxvYXZLhOGAQUZsss=; b=DRdnfenQlc11l1f+aqMI7qkCpUykae4hhPqrTs8b7TlKpZV/h+b//Sddk13QbSlLJb 5D12DFIoGkX2CCfh83qZ3rapx4hczuQSwGjzd9cRQYYkJ9XUbZvyqCGgGZ+3WXx5okxj rPntpAJ59urSqM6RjcNUluDFjh1P1j8YHBbxpBx0CDflc0HnjJ7bxm2qVVZNaMKtfD6z ISg1GXf8IauBclofA/WzuPzBJ3yoSjaWEkgfpQgTPU+0Ltl9savZqbfLrZvVnFJSNOT6 CcKQFRv1NzgYsHea8rSO1R8KODt20mOgxDui3kFnprM0iN5ZtQAPxF1n4Bq3LpOcrMph njSA== X-Gm-Message-State: AOJu0YwzMysmKbMB5OzfGpDV2tUmhmWEmOXxjdWNTleMEZgBfbh3EO+2 cpYcOBU9awPj6WslGCwR9HI= X-Google-Smtp-Source: AGHT+IFCc/wIV6TxJsUS4zh9doG+Bj0rfKw5jQPtBPmClb1Odv3n75NqVqKfTtyxMLF8C2LcHTND4w== X-Received: by 2002:a05:6a20:7291:b0:197:5045:d299 with SMTP id o17-20020a056a20729100b001975045d299mr1568700pzk.76.1704259912854; Tue, 02 Jan 2024 21:31:52 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:a7d6:f37a:9130:cd96]) by smtp.gmail.com with ESMTPSA id 4-20020a631244000000b0050f85ef50d1sm21303808pgs.26.2024.01.02.21.31.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 21:31:52 -0800 (PST) From: Barry Song <21cnbao@gmail.com> To: herbert@gondor.apana.org.au, davem@davemloft.net, zhouchengming@bytedance.com, linux-crypto@vger.kernel.org Cc: akpm@linux-foundation.org, chriscli@google.com, chrisl@kernel.org, ddstreet@ieee.org, hannes@cmpxchg.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, nphamcs@gmail.com, sjenning@redhat.com, vitaly.wool@konsulko.com, yosryahmed@google.com, Barry Song Subject: [PATCH RFC] crypto: scompress: remove memcpy if sg_nents is 1 Date: Wed, 3 Jan 2024 18:31:34 +1300 Message-Id: <20240103053134.564457-1-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <5aff3bcf-ef36-45b3-8ac0-a4b19697419c@bytedance.com> References: <5aff3bcf-ef36-45b3-8ac0-a4b19697419c@bytedance.com> MIME-Version: 1.0 X-Stat-Signature: 9przxnteg33xashmk4yhcpgrq81qwfgi X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 3587B140006 X-Rspam-User: X-HE-Tag: 1704259913-670792 X-HE-Meta: U2FsdGVkX19RUqWZ1mXX4AZg9tr3oYZdS9z2XFiVwBAI+zyESKrnYOVbcEnopkZ9wgmiID+ZOrld7NijVd6PzKYycmjw7X05DoejJuDViEqNB/0qaAd8g/7PaKu5nPrlIVc47jqgNkl2vVjPqcm69E15vQqtyqewfF/II1tp5hOaRBAc9nPc52mIznn5I2brP8llTO1LOq7Ovy6+SfYva7mxSc5VvpFBpUXIVjoU8xTrUkEjoc1i1bsTK+ucuA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ZjZfw5osKSytlbry+eX7BdWiouwfDsIXKM6rK5I3FDaBAcC1J6znz/WDyOC9cxqtnNYo3FGR5iINOmqKWjPXS45pOsj8dKR42pvejPzCfLObLCeNsaUjJ5ZE0Wwf49lTeBzLKQb+ibz6RsNiI659zCaT/pWExXP6AWB/Tl8ncDtxHBo7FSRonldk2Ev79XMBUfLRVOGXwgwx0NZD 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 be able to drop these two big memcpy. Signed-off-by: Barry Song --- 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; }