From patchwork Sat Feb 17 04:51:00 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: 202564 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp149177dyc; Fri, 16 Feb 2024 20:51:52 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVzrPNy2kK3gZOaMmZmtIUlexWTykUvNOLYKyeOCqA2t39XpmfzVPbJ8GLyF1o8beRdzx0nawOXBjGgxMoGOI8Z/kHxjg== X-Google-Smtp-Source: AGHT+IFRZBJ4qtsFLGF4hDf2f1xh/0yImg6AOIfmEc5L/4gpm7wEa//UEHISDLfebBRmpVHITiNt X-Received: by 2002:a05:6402:3788:b0:563:ccd1:26c0 with SMTP id et8-20020a056402378800b00563ccd126c0mr4240674edb.8.1708145512556; Fri, 16 Feb 2024 20:51:52 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708145512; cv=pass; d=google.com; s=arc-20160816; b=yWtUiCFmPbUYFz4+WSfr8fWurFCEcTZjWtVKP5EvFOKBOykyxuCJrPxYg3ARQ/JWsW VzWK9GA0O3mUJ8GeKywPuY9b4mFj18n5JOeG4BiIROBLICbTW6nGJsU8WVZtzIcmDbCs QUs9uBb0bAsrbOvZczHTDG0KzLYdJMj1ugiS1uUBJ52HpN1uedSXW8LY8rfpP0+3I9yh YwcF+Rm/DKCGQjIbDh4GLQIKzeTK4FfsMVUg+AI/4aBufeb9VjQd+tcMC05HoNzGa7B+ 2Ypo7ykaKLVufJbn31PoK7dwNcvLGGCnTgSdRfjIeMI6mi4uCKPkMIlOHqqaayKj+DxM Pzqw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=lBwGphqaBGgnqVopSLPzNP3HsID/sdo6yu3ftKGqOG4=; fh=2yeMTSvD3DF4SFYiNh3KQKal0zTF6yrLL4EN5YL61ZU=; b=vy4I2Wo8FR8grA+3smCItpUbN2JvF5S9KCljR3nD9rTf/aSiJ/ow/ja2+d0HyzsBa3 uVrMS0XfA3nAPnblATSkOq7g1sjHVkaPgtmQHgO1IcJrw7z4U2TtNsB6bNSHaH/qrbH4 9oBr+LvKzpuNB7u2YN4SOoMmFQuiHwXdfITqFt2E62opA4BOOjZdEHngB6+avVUIGmau Ti62VRcm4QxKdfbab+UxjQHRjbgNRNiYMJDIxiq85HKRm0Mc3SJd2rnpbQCvQSi2aBFy CfSdpKy5OsPjNAj5oZEckxEjQFGJiI2Wk0hEHUHomAeUeMwmrpV62EbxEtE/u/kqY9J1 Zrgg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=lyUDzjsZ; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-69680-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69680-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id l25-20020aa7c3d9000000b0056406116f18si550698edr.207.2024.02.16.20.51.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 20:51:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69680-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=lyUDzjsZ; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-69680-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69680-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 2F6C81F2209D for ; Sat, 17 Feb 2024 04:51:52 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0B8D41CD16; Sat, 17 Feb 2024 04:51:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lyUDzjsZ" Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D00081CAA1; Sat, 17 Feb 2024 04:51:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708145490; cv=none; b=OMBmIFGJgiIJRi8FUDYuMcNZ71NZtBATTDWhcw9bELds8JBWreiQUwzIq3nu64i9RvesQif9MfqWU4ZCv05GK2HcjVSie6IywQmN6e6y0Qvys5ANV+9ogBWUpn+KG3/T8nHZihcU2tioQBwRNHufxQaIvuzv3/c5q2RSFkQf3qs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708145490; c=relaxed/simple; bh=Ew9zGK8bj2uKG63OPEEIKUoe5Q8XkSHHeHR+1OENHDY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ga+53xREkGOwewq40piUCrZNsqagl1c9+feEdWHn0X4XrnHLBLbtElHKEOAuZGGeYBfH9yTazd6EjiuUOSiGZF2fTfGcm0RGT7tYH89tygO7gpqEP8BYoY6d7R++UikAM/jXAWgU1kohaeB3occwAzIj92/k6kBzpFlH00SXzzk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lyUDzjsZ; arc=none smtp.client-ip=209.85.215.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-5cfd95130c6so1646083a12.1; Fri, 16 Feb 2024 20:51:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708145488; x=1708750288; darn=vger.kernel.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=lBwGphqaBGgnqVopSLPzNP3HsID/sdo6yu3ftKGqOG4=; b=lyUDzjsZ4AraNAd8lELDST4SeqlNvDThJ9p/Ea9CZaadbnWAonEmlvVKXVVd0jWNhE ieVily6OX9jMZLBgdSprUIrezOWEtakIhowbbsOv9aT1bA/oEWXmXzuDvB5/CTbpKGT0 JMj+phAJYH2834ZYC9wYr37Rs87oGFCciKsBZm35kNIt+I3eMtISzCHISotxUL+81tw6 6g/p15hwZBEczxFUmPOBIIyyJfgtDt9yytu+/eX2VyPaXlGxOGPRmGH8dP6ABTE+LVX2 i1TMVvD21d/y1On/hmqbGOz4TtVPngwIz/yBSxiIc42EoJKcCqRPLeJ5sOYo2oK5KKHr Aukg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708145488; x=1708750288; 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=lBwGphqaBGgnqVopSLPzNP3HsID/sdo6yu3ftKGqOG4=; b=Cnv2qX7iWhPHBPNuFVIazNWoRAQiIVG6hIDDPPwNVVS6u1Ws0L6NH7iYOVXGyBJ2E/ Xph6ib+snvSBlhaMpf+Ikjjs3FRXqHYv57N+8Rl40AsHWlXKTHvF37rjuJF1PIP4VvMR OuuInqcsFdSk+4XyygLeusl9gb+vGQlFrieeThZkf1qp32XwporuNzsffuUTzhffDR+M Pgll5DL2Y6LdMwsvPj3DtvVDxRGlOSJgSlyo29zSuhx0chbmpaAHRa1viCheWtGnHI8x 3UyEyNt9ng8gN0h7dkwhyUMU2K43MYgYfRVDb5o3mres00InW7+9B+mMVwcFn5vAxWay cp0g== X-Forwarded-Encrypted: i=1; AJvYcCUC7k1LjFYUyOKyev/D74/fTGqWcHoH/ZSjhAarbIk6IkXqOA48mXRn8D+Ent6f8JEokvqbjKLrzCpai5m2xPqGBUqHWigqKTLSlLyJSd5DRUQ6u60G/xhBRuv/4zzr+7qJL43e3vWFK+NV X-Gm-Message-State: AOJu0Yx+0j5Gu0ROH0ZbEbWAoteGngi0LEkOsX+97H9t1nqy271cGDBv IUnuY+oaVVgQjzaRwxdfoAkbRWiImUbNhlRddT+MwihvsPiauUR6 X-Received: by 2002:a05:6a00:80b:b0:6e0:71bd:3322 with SMTP id m11-20020a056a00080b00b006e071bd3322mr9708070pfk.10.1708145487782; Fri, 16 Feb 2024 20:51:27 -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.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 20:51:27 -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 1/3] crypto: introduce acomp_is_sleepable to expose if comp drivers might sleep Date: Sat, 17 Feb 2024 17:51:00 +1300 Message-Id: <20240217045102.55339-2-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791120388987633205 X-GMAIL-MSGID: 1791120388987633205 From: Barry Song Almost all CPU-based compressors/decompressors are actually synchronous though they support acomp APIs. While some hardware has hardware-based accelerators to offload CPU's work such as hisilicon and intel/qat/, their drivers are working in async mode. Letting acomp's users know exactly if the acomp is really async will help users know if the compression and decompression procedure can sleep. Generally speaking, async and sleepable are semantically similar but not equal. But for compress drivers, they are actually equal at least due to the below facts. Firstly, scompress drivers - crypto/deflate.c, lz4.c, zstd.c, lzo.c etc have no sleep. Secondly, zRAM has been using these scompress drivers for years in atomic contexts, and never worried those drivers going to sleep. Signed-off-by: Barry Song Tested-by: Chengming Zhou --- crypto/acompress.c | 8 ++++++++ include/crypto/acompress.h | 9 +++++++++ 2 files changed, 17 insertions(+) diff --git a/crypto/acompress.c b/crypto/acompress.c index 1c682810a484..fa15df394a4c 100644 --- a/crypto/acompress.c +++ b/crypto/acompress.c @@ -152,6 +152,14 @@ struct crypto_acomp *crypto_alloc_acomp_node(const char *alg_name, u32 type, } EXPORT_SYMBOL_GPL(crypto_alloc_acomp_node); +bool acomp_is_sleepable(struct crypto_acomp *acomp) +{ + struct crypto_tfm *tfm = crypto_acomp_tfm(acomp); + + return tfm->__crt_alg->cra_type == &crypto_acomp_type; +} +EXPORT_SYMBOL_GPL(acomp_is_sleepable); + struct acomp_req *acomp_request_alloc(struct crypto_acomp *acomp) { struct crypto_tfm *tfm = crypto_acomp_tfm(acomp); diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h index 574cffc90730..88ca33532313 100644 --- a/include/crypto/acompress.h +++ b/include/crypto/acompress.h @@ -204,6 +204,15 @@ struct acomp_req *acomp_request_alloc(struct crypto_acomp *tfm); */ void acomp_request_free(struct acomp_req *req); +/** + * acomp_is_sleepable() -- check if an acomp is sleepable + * + * @tfm: ACOMPRESS tfm handle allocated with crypto_alloc_acomp() + * + * Return: true if the acomp is sleepable, otherwise, false + */ +bool acomp_is_sleepable(struct crypto_acomp *tfm); + /** * acomp_request_set_callback() -- Sets an asynchronous callback * From patchwork Sat Feb 17 04:51:01 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: 202565 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp149239dyc; Fri, 16 Feb 2024 20:52:06 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUyWOkmHVO2DefBaZK/SONhze9VTijLlFrq9Bg2z+LqWUet33k5lD1WfGQuZnQunV/RxWJfhIgt45sgxu4yu0/twr/ShA== X-Google-Smtp-Source: AGHT+IGveMX0oHj+CfPQtICq55syNKmqONwBUCGZoGL3hFH+RrOVP6006KpwWjFxdPGwgaqZdk89 X-Received: by 2002:a17:906:57d2:b0:a3d:916d:caba with SMTP id u18-20020a17090657d200b00a3d916dcabamr4510575ejr.58.1708145526359; Fri, 16 Feb 2024 20:52:06 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708145526; cv=pass; d=google.com; s=arc-20160816; b=J89eQkH+45qXzqZ9s5VLzuMJa3uSF+tL1/jEGjuKkl40sP+R01CZcEbzAR440BUOUK BsXhaZLxc9yjxg4O5Xeg/hyysWLQg7LA03gqT3ZnNCLqoFRp4kWt+Tj+MgpvPpU5ZAqA TfgLpF3BpTODS/2xFN1rTyrmaIY3KmfzNcBVWaMUupuAUVuBDUiyhAcwzGxBtnzjX/3z O860LSqS1GKJcE8gg7X10txVoZ84zp+Q2m4T2t/DHKz1j5ROkCIg4PTL4pH6LSB5pXjJ tzzUculJ1IBTxqxfXElC19T1FE2U1jdo9StQon0XsgbblAOWGePSTG/ceBkHbGK0UmWT OUKw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=evwrpqE1Hiz2u5sFXh0svc6RdlbtMXnztqrxU8YZhPQ=; fh=NF6UJfMnwIRqEQMUVUinZ70FD8ZpqfwNbzKI8Uls590=; b=CYTO2H6cnJlJtK/TW422xjYrYHEjwih5AX5XuzeE2m7PqWOWnYGvO+70fiixnpjRCb l9DJnaOY1WHa4Ow6ckNK0j++ksOcR24H/b9pzbsYkfRx+xrPoMGypKKKr8OymOJsr8H2 lUQHQqv+yBzr+dlD4zrUQ8pg+3yYcG8N9YxY17mIkgZb5tyC6tdJHJfqencpmB/b5tLS ftZ+oImIsdVyckChs/jm9NWXl4is/bPO11ZA6zt2Z0oxdCunaxMYLsnu5SpnefRbfSeJ NfouhNU3vcWZpnu/7mdEhS188ZJMLLj9GVYnU6OQzGf14UbwRpqSz0aJhOv6QXSx/qyv ErFw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=E+pVfu5D; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-69681-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69681-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id ss26-20020a170907039a00b00a3e0bd23acdsi475883ejb.124.2024.02.16.20.52.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 20:52:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69681-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=E+pVfu5D; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-69681-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69681-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id F393D1F21DDD for ; Sat, 17 Feb 2024 04:52:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8FC731CF94; Sat, 17 Feb 2024 04:51:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="E+pVfu5D" Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 67C1D1CD0B; Sat, 17 Feb 2024 04:51:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708145496; cv=none; b=Q9w/gnEr3yPcTwxio7VtV+PYZ1CNUHhdPPWf7TT8JwpOtQDMhXA9VHy7/Ih1527DKJd4aMS8ld705cf5pR3Rh1JAJc9NqKrEiNcR+WJ6HK6F+tW/SQ/QC+OsJqbx9q+8Ap6MzXh7JZmVhw3CSUU9m9VtI7nKqV0n1ZitKjgv2sY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708145496; c=relaxed/simple; bh=RaujQfpbxxDx841ddUw9WtlW0oC4ty8/luxjiNzGCf4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=r8P2GRzR02SQ9VH4MMYdLC2qHnB1C6QkpWl6fEGZNQxxboJCfGhcQZet49Jb+D9aTrPJWoPgebAPs7YDOSBNCDRfaJgzV4MC/4w5xY/iHDMrPk9M+w/Qwmk4UHAkg718piHYuD4UReEbBrKxfBEIF5CgPE3I5+7CHaQseeKAgpc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=E+pVfu5D; arc=none smtp.client-ip=209.85.161.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-598699c0f1eso980948eaf.2; Fri, 16 Feb 2024 20:51:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708145494; x=1708750294; darn=vger.kernel.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=evwrpqE1Hiz2u5sFXh0svc6RdlbtMXnztqrxU8YZhPQ=; b=E+pVfu5D0HJFR4naP45XBuYDA2xqPtKQiR7CktDgUyEkEpy9oLTOtxJM+47IdknSlT JFKPd7r74MEXUB9KrNtg+I2nL/V0BesK//sW9dpBWWsD6RCKi6qAeIIkTrM0hZJp/vlx FLQ3dO86wGDeIzVgyaGIzgcofUwY3+sVAh9LJupuM9Uj/0eR+o4t7d72Oa10TZRPTl07 Kfxd081WMU8xw8A65AVUknUWMxxG5KUv04s1/wgm53wp0YRKVLOnl00k6W0e6xLUHBAu /a5O1FASb8zDyGw04j4VSgPX1Pnnjh5rpLLBonDbgI1IZ6t/QKfUllp4ihtRJAqlHagT d9Uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708145494; x=1708750294; 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=evwrpqE1Hiz2u5sFXh0svc6RdlbtMXnztqrxU8YZhPQ=; b=sF2AIadDbPibjy8j5RphFzOPoAZfOdbEc4pakgWhC1d8LvrUY/O45F83c5qeeBfeWo LUizVVSpd8lmc01/FnNms+EH+HbNrIuFoF8+Hx61Uj1v96AaB3/1UaacNOXtWBf3r0d4 XzfZ6UQubYJ8rnsU7C6aw2VfiDN4dSJ774JVsfk4GN8HsYzI/ao7v7U7SvQsJjCc22/B Frui2R9BYrWeB0zBP1tiQ5BQgxRaVE3B1IjEUCJ34LxgHqpGewIqn29o16de55fOq/Ma F/FwDLNvXQPGMymfbqpnNskamocIZOY2GDySytYIIOUEn+tp0x4CSLtLC5AZfdz6TPrP x41A== X-Forwarded-Encrypted: i=1; AJvYcCUNhLY7e0lu85wdyLpebscElEzq1selaBC5UeIpPMNaUtrwpkS/+SoKIgChPkzKi6StUzS0cTFFHzVY7INKQC4ZgGxmhdYre/3Y+6223SM2XSKGWIbZMWpoznE9Zak6+RIvAa3p1uBkcFT1 X-Gm-Message-State: AOJu0Yy/Kf5VoWP4fij/grGw9EJUT/vTc4TsCzGRJCnRxYqsXag3ox7i Dp+BL1p/1yziSvfXsXCNKeDf/whN5OAkmPyleVTbWuZY1q2MH9tt X-Received: by 2002:a05:6358:3a04:b0:178:f895:5978 with SMTP id g4-20020a0563583a0400b00178f8955978mr9891587rwe.10.1708145494362; Fri, 16 Feb 2024 20:51:34 -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.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 20:51:34 -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 2/3] mm/zswap: remove the memcpy if acomp is not sleepable Date: Sat, 17 Feb 2024 17:51:01 +1300 Message-Id: <20240217045102.55339-3-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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791120403891242923 X-GMAIL-MSGID: 1791120403891242923 From: Barry Song Most compressors are actually CPU-based and won't sleep during compression and decompression. We should remove the redundant memcpy for them. Signed-off-by: Barry Song Tested-by: Chengming Zhou Reviewed-by: Nhat Pham Acked-by: Yosry Ahmed Reviewed-by: Chengming Zhou --- mm/zswap.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/zswap.c b/mm/zswap.c index 350dd2fc8159..6319d2281020 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -168,6 +168,7 @@ struct crypto_acomp_ctx { struct crypto_wait wait; u8 *buffer; struct mutex mutex; + bool is_sleepable; }; /* @@ -716,6 +717,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, struct hlist_node *node) goto acomp_fail; } acomp_ctx->acomp = acomp; + acomp_ctx->is_sleepable = acomp_is_sleepable(acomp); req = acomp_request_alloc(acomp_ctx->acomp); if (!req) { @@ -1368,7 +1370,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) mutex_lock(&acomp_ctx->mutex); src = zpool_map_handle(zpool, entry->handle, ZPOOL_MM_RO); - if (!zpool_can_sleep_mapped(zpool)) { + if (acomp_ctx->is_sleepable && !zpool_can_sleep_mapped(zpool)) { memcpy(acomp_ctx->buffer, src, entry->length); src = acomp_ctx->buffer; zpool_unmap_handle(zpool, entry->handle); @@ -1382,7 +1384,7 @@ static void __zswap_load(struct zswap_entry *entry, struct page *page) BUG_ON(acomp_ctx->req->dlen != PAGE_SIZE); mutex_unlock(&acomp_ctx->mutex); - if (zpool_can_sleep_mapped(zpool)) + if (!acomp_ctx->is_sleepable || zpool_can_sleep_mapped(zpool)) zpool_unmap_handle(zpool, entry->handle); } 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: 202566 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:693c:2685:b0:108:e6aa:91d0 with SMTP id mn5csp149295dyc; Fri, 16 Feb 2024 20:52:20 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCW4cSINn7O9ssgq9X//HoR4akBpUkW5Bv+RQaGmvJWOs557/Xin+fANfmJJ7pFKY+yHVvQ2IF1/Z0M4lfw6YFrxYrIX3A== X-Google-Smtp-Source: AGHT+IHaw8CwiNAUw1Ek81RbpFt3epmeBrkH7QFN9tMqKJcxdKp+5YpfBcYKzS3T54cgKlQQEF0X X-Received: by 2002:a05:6a00:6c9f:b0:6e0:a30c:8c84 with SMTP id jc31-20020a056a006c9f00b006e0a30c8c84mr8280268pfb.1.1708145539932; Fri, 16 Feb 2024 20:52:19 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708145539; cv=pass; d=google.com; s=arc-20160816; b=yzFchYdFlYk9i9i7QJHU+trPDufzzGVx+IWhmZT0bv1AXKki4+YLwlxg3Sew8Od5LL pihxprnvEYe30RKTk8Q8yuJ7l9pR9hj0enyET/r+yQ+4x5/dV43uzGBwza80c3zJQ3l+ TIHv0uFYC8exSYHdirmvOJiyQ7UDJr+zL+PllQTX1v3zKNvPl9mmPQt01+dQwqDBIOn/ gUSNzpj/eqCFmDEdtXxvMXSTEvejzsrfjlrQv9rehwecSJtZ+BZhB1HE3Z8uoDmL5nFd PsYTH4fZKets5eSoLPpK3yA5maPV2tcUrxk1JJhhOBlv63bA6IgrTfcHnglDxU985owC eUFA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kW/qQndLj7MYeSMYgAPMliKXg25U647vW1M3U8+Bgew=; fh=gFCNvX/0r3HoZEqWUOLqYxfBebO26YqJn1G4XXnnnlE=; b=LoQzwOjJ+pv2ehW1XwKtlmDCMvhLrMaTkDlbiKdAaAuMC71T3/2CayOfD3GdYVlTv5 gvh2e7EO3OQYQBRWWTHEgtGjlcoAYMHbEUW4Ptgaq3OI0d3Tsq1V6+VwduLvBxQUADNT u9GVVv4VtczK0NhDTivYIs4JuUwyptWYXKD2+lzMCoR5ZVF3eE7wJlnlp/rTpHz5RMVw UxF8K4xmhT2rDEAcxhTQ6aQnFRx6BKsHMm/exZah6TAWpPaLdtNYPz0AyXC3L3PLYTwU u9Keu83QIRCdQ5pNRpCwoeXDK6ltxKBICqxNPv4tIyyQ0teyrPhdxAffhQcgquw2jQEW JI9w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GhD1c8DO; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-69682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69682-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s128-20020a637786000000b005d8b7053276si956579pgc.160.2024.02.16.20.52.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Feb 2024 20:52:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-69682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GhD1c8DO; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-69682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-69682-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id B685F2828EE for ; Sat, 17 Feb 2024 04:52:19 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 18B731D54D; Sat, 17 Feb 2024 04:51:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GhD1c8DO" Received: from mail-io1-f51.google.com (mail-io1-f51.google.com [209.85.166.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8CC9B1CF8B; Sat, 17 Feb 2024 04:51:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.166.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708145503; cv=none; b=A08wxn7k5odK9mWA0Zpm4XCJrlYQlMs3geU3Yes+c8gggnaPi+uc+O00cVjxrPsLb4DcWV2rnofXL0WXLB8N8HfvARQ2wb6Rdc6B4PlfGkdp63ppvfWyKIe+6+IdNshLHuuT3g+4Sbawn8ZeiNxsVlvtT2RMhGiIA1p4DwMdQUA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708145503; c=relaxed/simple; bh=OXsYoToIjgeSRYAs9X9E0bo5WCdOjPMMPVgmJGURH78=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kCEQojNmjLnpL671iBNqw9ABIKqpozRsEV+tVE/Q4LtYWLqSHGk/X6uHkD3WyPPIL9gakE5Tgtf7ydLO0P8NYc9lB3i3TdTPpjB7lWcI/YwRRdlBDT4G+kIw3maKI9UbNxqD5CZ22kXamFGxoYDqgL16jAZCZzaTHXxpqJ76+UY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GhD1c8DO; arc=none smtp.client-ip=209.85.166.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-io1-f51.google.com with SMTP id ca18e2360f4ac-7bf7e37dc60so145971739f.3; 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=vger.kernel.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=GhD1c8DOfSx/cvZLwz0Xk2k2Et3ZwFV169yH93IYF0UPQWfZdf8zNSH4tse5ipK53w PKgh/Y4f5q9CrylOtc6a+ot+k76IzBr7Pr1BBYQGGEhDOyUNP9+kJryEF+PB7nAeB0YU 1XPpJFiz+JJL/EEKUE5ZQ4cHrH7FgEDOnkI8XeOob610Ms1B4a91eTJMKeSJ3Wu3iDxe uFQ9r1Tu66qq01zgid2EFxz7bAaQIFYjxAIb3EY/TrwZYvDeVtROdbayCuvM0cstN3wi Rk4pX4yvEKMW4EuSvF+pvd5CBrt5P+VqvZzEmdIVWOVA+hNoBbjdfnYskS9i/dy7qCiV 6tPQ== 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=eEkoOAZ4HiQCxgEs6ZCh6W4CIsFtC45qdbB2RUoSrBZawozVhrDAgH2p08nHtCiqLM l7CyI3Mmb4+FVR/El+yWQ+TFKLo1/saHdl8UMA2gDIk7N3PoFK7NDA+j/lDhpRIevn35 tF/p6zKCO/XpKv4/g1M9ZcLwMd8TkSK0BRE4G4YRwIUc53mTtwgH+2ikP2eLR3cHv48M y23t52HCqxYAbbia1YYAJUqgvbcVJpZH5rPsLfB6Z2IiXOUx3XmyTTMDpFDlib2mKgY3 3b2hn72EDMPcdtTwZkhngdmNZBB4FCAqoVgyQ97bvERgiT7UTeQJIQjsNPBnAiTjaGXi kebw== X-Forwarded-Encrypted: i=1; AJvYcCUoPilh/j3il++8x/aM5Jx/3oEK63zsBP7p9x3ZA7XqZ8mS9dhAArvT+viR872gUeD1WZVW0fqqVH0KYmGcGJDej6L1uhS5jJnS0/hvlcsc4mnIADc5+/7s4Gr0Eajgl4njYoxMxlYkCMkc X-Gm-Message-State: AOJu0YwmO9H0cM0ovuKrS5RA65sDrh+8QGuKeyOoEyZSjeg/6nH07OLh cKTAyojN1zDThOQ1ynxUCQFau2RmX0SkgLSsGdDt+Mz/L+ttbsX0 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791120417739166971 X-GMAIL-MSGID: 1791120417739166971 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; }