From patchwork Thu Feb 22 08:11:35 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: 13566844 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 0EC7EC48BF8 for ; Thu, 22 Feb 2024 08:12:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9BBF26B0082; Thu, 22 Feb 2024 03:12:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 96D076B0083; Thu, 22 Feb 2024 03:12:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 80E136B0085; Thu, 22 Feb 2024 03:12:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 6F0AE6B0082 for ; Thu, 22 Feb 2024 03:12:10 -0500 (EST) Received: from smtpin21.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 30FBFC048B for ; Thu, 22 Feb 2024 08:12:10 +0000 (UTC) X-FDA: 81818722020.21.8A6C031 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) by imf26.hostedemail.com (Postfix) with ESMTP id 54646140003 for ; Thu, 22 Feb 2024 08:12:08 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QfFpXP9T; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708589528; 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=Jyzbw4yb6Txj6TvozTLsczGvcpX/acfEaP+bFGtpG1E=; b=iojEvJsFg0x+qb0q6fdkEsL9N856IffkYVPdghFbodzNIVmoTIzzTvX4+mTPajoEHMG04T OXn0pciImwa+S3dNS+ssQJTO8WLZ/5DlayUb2Y+DX6xLdoK3atwLOrBU41v5heDcLdSPsw /ugr4niPjjsjg5d5JCQJIF2GAC2wKbc= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=QfFpXP9T; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.171 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708589528; a=rsa-sha256; cv=none; b=o3JgupPSDp9G+w5w2u85L6/Oee7GKiaRrMKANFvFTXgRHqApJcqRR79jGTF5EmV6dyZDC4 Z7TmuTSR+QqwjZomyJamAbZOMHhcMWv+8Z/JdnuqjeQ0zqHuNhOeXZHrKu9TB3NfLxApoe XBbuFnoSVKsTPueEF+VkziPWHD1T3C0= Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-6e46e07ff07so2685894b3a.3 for ; Thu, 22 Feb 2024 00:12:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708589527; x=1709194327; 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=Jyzbw4yb6Txj6TvozTLsczGvcpX/acfEaP+bFGtpG1E=; b=QfFpXP9TmIulgnMLx7DgOZzTfT9F8Y2Sc4z8j9J55ScvDZO/rk2I1rnA+t79/1JV1p mkCa++Cm+dYZYKunY+3O1Z7eQONtEEAeUNxqUbYPknz8cvWf7Rdv3eKbP6fu+/4dB8p6 hSBus3r4Q/tbJun5g16FJVyz/fS8ITlIlg5i2KGJx6S4c8Ni9NRdbHVTc4i9Uc0Kfhre Div3RQ+/7t3RsjWMm/BVAK/banWTQFZMQOzJ0GMydYkW1Wq8JF/v7r9p5I3nuAcGiRHN iNHHKnraDjYydG30x9op2BAD/+LuyCyypL/VU2+Lw4BHdZGXStP6kikKmsie/4YsBzxh PZNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708589527; x=1709194327; 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=Jyzbw4yb6Txj6TvozTLsczGvcpX/acfEaP+bFGtpG1E=; b=tK2QiERiEcfEgHUGTcrXwDaJhfQY9rDlpEujmzAhA7QIqVroJIYk3LEZrlop1DI+4d ZLcw+WgLTnUtVn1sWQhr8LdfPrSv7hjU4WnpEpCQl1fobJef5PRfmeCd+Nc8eFVHep1e TElTlveNRXgyuJnTk5ytYuc78T8QgnElQ5V6V1FKw25Ac3R8lCsWa2Ebmrp2nUeRu4Cq etRmvAjJngED+jC6/JppGeO3vtUpSfY0nYgnvluo4CJZ2+xsV1loI+S074WHKH8gYQeI VE3UfX69/pMD+uLrW5uE+EFG7w/5jeYO3Nsgd1N2GanU3i/B5wqvI2je3CrP3wq4LFCq qZyA== X-Forwarded-Encrypted: i=1; AJvYcCW1QYyy2mZQKGKhz8zjyiGIJ5EE7hawpFhvgzXWfzDNNLu2ToYzjDAj1SUkXOjSLh6NDRtSM25ZX6rSu6JI7Cnx2Ig= X-Gm-Message-State: AOJu0YwW1MnmGxwaM4oA0HX47nz8mi+sM0QgKGLVFnbM/6NO3vTy8MNf AL8wn7eJeQ2i5RI7RrcZ0gsHHApPaXrjMdJnzaIeXzaLdKACt/dd X-Google-Smtp-Source: AGHT+IFbrZ0+tDkMM94Z/QC2yq6Sf/RISBWbgl0RWkGMZYK099YKho/soN4snFIb+Czo7k6uHvjhzg== X-Received: by 2002:a05:6a00:13a6:b0:6e4:c54b:9681 with SMTP id t38-20020a056a0013a600b006e4c54b9681mr2437450pfg.9.1708589527080; Thu, 22 Feb 2024 00:12:07 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:3b18:a2e2:f00b:c965]) by smtp.gmail.com with ESMTPSA id du17-20020a056a002b5100b006e46672df97sm6989554pfb.75.2024.02.22.00.12.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 00:12:06 -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 v6 2/2] mm/zswap: remove the memcpy if acomp is not sleepable Date: Thu, 22 Feb 2024 21:11:35 +1300 Message-Id: <20240222081135.173040-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240222081135.173040-1-21cnbao@gmail.com> References: <20240222081135.173040-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 54646140003 X-Stat-Signature: kew8wnzrnynmamud6zwd9xf96e93d6t9 X-HE-Tag: 1708589528-390554 X-HE-Meta: U2FsdGVkX18i9ymmAF/njT7/kvtHGdhjz95mL7UmLll/IGW5q0FGPrUdLJ8toY2MNG9WYS9CObYlIpB3xw4l6kp2QOjoPu78MJlFl4EZavarGyLFBFDyNj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6bhzIUj2BmK2RFCZA/YlJu+slk3vN/DWf6xP7yKC7p4YpHz2u9l6Ge16OfxvhXgYaV4y9BPwCYdwBZVxD7lMkIMi8XR13jReF/seu+lhmsXU90f68bs0aunjjbr8sIZQdNzankYqyZEg+xAN70NiO58U9swZCx6+zvjG0AxQg7z6PP1woRhijG/W9OPNa7tJMJ5p4S5s+eT+egiA84+CUatmhP2euieIfEJ69IhXBi3RPwWLfJvpG76Dq3D03ltNnTLGdWTfaDpxma1uo6sfpgDMeglb9rbwXI8pzAbOtpsAKgq0rinTxJL7fGk+zZrMShx/ejMFUcjFY/VBlXj+omMb5aWIaRzerkrD65zX/sCvBOGfMbdQEwVC/EMw/2gGSA== 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 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 Acked-by: Chris Li --- 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, struct hlist_node *node) goto acomp_fail; } acomp_ctx->acomp = acomp; + acomp_ctx->is_sleepable = acomp_is_async(acomp); req = acomp_request_alloc(acomp_ctx->acomp); if (!req) { @@ -1077,7 +1079,7 @@ static void zswap_decompress(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); @@ -1091,7 +1093,7 @@ static void zswap_decompress(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); }