Received: by 2002:a05:7208:9594:b0:7e:5202:c8b4 with SMTP id gs20csp486029rbb; Sat, 24 Feb 2024 08:54:04 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWcI1VuxbGmtpb3qcpk5MBuXdMGMrBkgXQx5puaL3y9yJib3/R9UfROHFl87oGvuEUAsGgY98tLyImCsWUHWoiLf1tLHk8KIhfRx1KPpA== X-Google-Smtp-Source: AGHT+IF+10GsvuP8cdOy3QkznRgqqU/DT1e2w87YnXQvbeciP8IodCmdVpdOgeduT7O+yd6hxEEy X-Received: by 2002:a05:6402:22f4:b0:565:c59b:8372 with SMTP id dn20-20020a05640222f400b00565c59b8372mr160442edb.30.1708793644463; Sat, 24 Feb 2024 08:54:04 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708793644; cv=pass; d=google.com; s=arc-20160816; b=GDBd8npGih2Ch/7yrhBadzMsJAOsBN859X1Xw1OEGLMJ9l/HqfOAE+TL0OmLwCmaxF fwKkmTHQ/R7myo75FRZzoKnx6sRpJveB2HY5DF3gtWX7JNwa3kKMa0jDuzrSr0zPp91m i4UnfWSxKA/XkPGcFytESAEasqlY3zss/vGQke8XXBOE5yH9AKcQytts9LpjHjLLvPvV BUF1WHrzTSTnX/95Zw1u5R17nAeOgz2jydnnz2cgY8SRg6dqhuVHVYYiyBRWzz3Hex4a KKtMPSVtYi2XdvRgtprLaXB+KRMpOViX44Ir0OnIB/aLwNxQ0jQ0rur5LBRA75QYloIy ytCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=M7sAyNhnzKfrLl5iZR/YcIb69ymmulA1x3BROrJDvPE=; fh=+kQ/36wvBkunYGNnN+Jv90HhEwl/6ztn0xTU7j+/zb8=; b=fZNBJ1cm7h9b5irJ+BHc+rJEJT/qCxiJXliRcSWP+PkeL4BubtaH/7R/sl2o6iQgLE nI2pUXnGAblAgZbTlQ7/HLUtFJb8ow3vvy5Ip9GqJVp6oXkyPM5hUgWaz+I4yTWYTUYm LtZWTaLHMuglx+8uKZGWQYjk4riFV2fEUNY+/6TbcAElxZFa++e3GHwJyE0wjs7WvnK0 br15q2CqSIPn0g8+tu5mKbOSe3umuDwnyv3UTzTmCCE6o2l1KlDRVfHB+VkKIYtdhdYz LDyapFyPsu4b7TwHORUYt9avSp/I78SWSLESCczl6GUVLtYzjDqO0dYXH2sq4ActoOH5 y7xg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZkROrc93; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-2305-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2305-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id t13-20020a50ab4d000000b005642ea075aesi636376edc.314.2024.02.24.08.54.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Feb 2024 08:54:04 -0800 (PST) Received-SPF: pass (google.com: domain of linux-crypto+bounces-2305-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZkROrc93; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-crypto+bounces-2305-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-crypto+bounces-2305-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 30CF31F2201E for ; Sat, 24 Feb 2024 16:54:04 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BD56324B29; Sat, 24 Feb 2024 16:53:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ZkROrc93" X-Original-To: linux-crypto@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E90A8488 for ; Sat, 24 Feb 2024 16:53:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708793638; cv=none; b=fCGiFj4G7ypMJSAPOfjHc2IGLlTUNIbNI55f6ghJv30aYeoTWXuc6nIzhrFCJK1VgWIk1BwcVkIEYzmM6tT3hnNcaW2V6uokLl0pL36yILqs7hzeDKq57dCHDk5SGTyVaeTsiQOy8vmu4B2sn/cfZJ5k9QBGjQtFBMydE7f3T2g= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708793638; c=relaxed/simple; bh=z9zQiP3XZXSgVaP4ozx7WT6lEl1K4J/Q7eJNF6Jv8m4=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=VPwuCrc8U3iDAJ4K4pvCnDj4JlG73AyHtIHta6bnpkEH3ArwGEcAD3K8YFCDH+ZFcLU5pJnr0hhg6t2WRdaZIK5joHGSaOhUhk94amLZ6+vNF1LZ3w1K+HcasqiZ+Ib94mcXRNlJ41KuCeFaoceoGhHXQT0xuwtb6nJ9O3jk+yg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ZkROrc93; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FB8DC43394 for ; Sat, 24 Feb 2024 16:53:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1708793638; bh=z9zQiP3XZXSgVaP4ozx7WT6lEl1K4J/Q7eJNF6Jv8m4=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=ZkROrc934Ipl6NHNHnwyToE+bfGW2rDvuPc10PLblBYpyiIUfBtjCM/UKTmYgLi92 IpFtO4qVJ74Xj80R2YdjzwNQFVgyRzzdu33qzbm3DVDhqLFlWcAtbgaNm8lfg4KFji 8ZlZ9C/SesV25q2gtHiyZ77V+j43Sk+I0HGA1tFsV0Ltj7a0+9GYRKIsqcmd3iflvz bwXLa1b1sTsOureqC71dSHIr2MKD6Srk1nml67bDQnBDCtOZgW1mF/v+FYgtGrOn0a cXAPnRHzXJ8FoyzC1bW5nZYR4vyYbZNZOxy7ccUo3CcU+JMGxjwZNEw4MpX1XcjgUI GBplIvhVzToFA== Received: by mail-il1-f178.google.com with SMTP id e9e14a558f8ab-36576cf5fe0so5242655ab.0 for ; Sat, 24 Feb 2024 08:53:58 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCUTdpPV5ev0IjfNqr8TtR4hZY40z8o05KeZrJSXJOPgkR+oJ2DMUwPCEYqWwYjm0p7t6GM+86yWDBq9CeOAMH/ePvNFT2IiVmFCW69f X-Gm-Message-State: AOJu0Yw8q4L7PcUyijyW+M6C4d/zvDNq2tS6fe1kt+48wgvp0/+sudxK oXZF0m/No/iU7Cienrf/bCRayuGL7bIBkzRUsMl/NHBQiPhK96NQ0xfsks9dbv3y5f5efzHZO2H avCgTwePxRYJV9tKtciH1QtwubZ8rVE0zLA0G X-Received: by 2002:a05:6e02:13e5:b0:363:e99e:42e0 with SMTP id w5-20020a056e0213e500b00363e99e42e0mr3109696ilj.15.1708793637472; Sat, 24 Feb 2024 08:53:57 -0800 (PST) Precedence: bulk X-Mailing-List: linux-crypto@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240222081135.173040-1-21cnbao@gmail.com> <20240222081135.173040-3-21cnbao@gmail.com> In-Reply-To: <20240222081135.173040-3-21cnbao@gmail.com> From: Chris Li Date: Sat, 24 Feb 2024 08:53:46 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v6 2/2] mm/zswap: remove the memcpy if acomp is not sleepable To: Barry Song <21cnbao@gmail.com> Cc: 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, ddstreet@ieee.org, linux-kernel@vger.kernel.org, sjenning@redhat.com, vitaly.wool@konsulko.com, Barry Song Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Acked-by: Chris Li Chris On Thu, Feb 22, 2024 at 12:12=E2=80=AFAM Barry Song <21cnbao@gmail.com> wro= te: > > 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. > This patch checks if the algorithm is sleepable by testing the > CRYPTO_ALG_ASYNC algorithm flag. > Generally speaking, async and sleepable are semantically similar > but not equal. But for compress drivers, they are basically 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. > One exception is that an async driver can sometimes still return > synchronously per Herbert's clarification. In this case, we are > still having a redundant memcpy. But we can't know if one > particular acomp request will sleep or not unless crypto can > expose more details for each specific request from offload > drivers. > > 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 011e068eb355..de3c9e30bed7 100644 > --- a/mm/zswap.c > +++ b/mm/zswap.c > @@ -162,6 +162,7 @@ struct crypto_acomp_ctx { > struct crypto_wait wait; > u8 *buffer; > struct mutex mutex; > + bool is_sleepable; > }; > > /* > @@ -950,6 +951,7 @@ static int zswap_cpu_comp_prepare(unsigned int cpu, s= truct hlist_node *node) > goto acomp_fail; > } > acomp_ctx->acomp =3D acomp; > + acomp_ctx->is_sleepable =3D acomp_is_async(acomp); > > req =3D acomp_request_alloc(acomp_ctx->acomp); > if (!req) { > @@ -1077,7 +1079,7 @@ static void zswap_decompress(struct zswap_entry *en= try, struct page *page) > mutex_lock(&acomp_ctx->mutex); > > src =3D 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 =3D acomp_ctx->buffer; > zpool_unmap_handle(zpool, entry->handle); > @@ -1091,7 +1093,7 @@ static void zswap_decompress(struct zswap_entry *en= try, struct page *page) > BUG_ON(acomp_ctx->req->dlen !=3D 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); > } > > -- > 2.34.1 >