From patchwork Thu Feb 22 08:11: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: 13566843 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 BDD65C48BF8 for ; Thu, 22 Feb 2024 08:12:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 502A76B006E; Thu, 22 Feb 2024 03:12:04 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 48A056B0080; Thu, 22 Feb 2024 03:12:04 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 352736B0081; Thu, 22 Feb 2024 03:12:04 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 2489D6B0080 for ; Thu, 22 Feb 2024 03:12:04 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B83A9A0CF8 for ; Thu, 22 Feb 2024 08:12:03 +0000 (UTC) X-FDA: 81818721726.07.426C215 Received: from mail-pf1-f178.google.com (mail-pf1-f178.google.com [209.85.210.178]) by imf04.hostedemail.com (Postfix) with ESMTP id D40E840015 for ; Thu, 22 Feb 2024 08:12:01 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TrVY9nm6; spf=pass (imf04.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.178 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=1708589521; a=rsa-sha256; cv=none; b=7NyOEnJ02+3cikm1yShSbxrDtIT0sqCeRatzT3i1oeddGtifQChSDyvZCVFPELcY0puEe1 2unfk5hAbLdqezGSgcW301oYFHlu92jKQ+l9rPL1w4LW3C6rN8/a47wgT0oUBVLh+sQIki 58KXXI1eK7kKjwyolGdT0AF3qpSDAbU= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=TrVY9nm6; spf=pass (imf04.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.178 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=1708589521; 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=ejiG5wp8wHYtqv4OVHF7H3n1cMrEsgDccZLLuZArdnY=; b=FH6Q+FjeHJzZsBsHs1eeP0VV6Qfyuw3tHUWTJ0cD6a5cRUePirAl5kHcHmDC50a08YgcC1 UUNwWjRx4oLYUNffjwrU6q9d/JLnZY9LW83pb1PBThC2R2JwCEZcdb+Pf9aEhyzmGIOEzA dU8JDG0RsW8nH2zezeToHo9ASZk9nKM= Received: by mail-pf1-f178.google.com with SMTP id d2e1a72fcca58-6e08dd0fa0bso553167b3a.1 for ; Thu, 22 Feb 2024 00:12:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708589520; x=1709194320; 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=ejiG5wp8wHYtqv4OVHF7H3n1cMrEsgDccZLLuZArdnY=; b=TrVY9nm6aMXtx4fdSjNjE/FAD+7icL1YbWJnD2d90FIJa6RvLKQhm8Otduplwccli8 92nTM/59MvddWt0LjiLP9+Ue4zvTsziMJ/VelftBkyH0apcskpELdfxzCdNAkH0Bxahf SEVIKhwiAstTdr3QTvvt30KopNCNwMGQY6RyRB+7HfY4H5GgFyEchF+BnfbMdZrdSywp zyH9+SQo5g3TG2cbQ0A056iHcIB9JD9pnqHbiJhiaqAPb0Yeqvt4+ail0Jnrd8QscTyd FBZNr6ynAyPmxPsinYbHE8zX+gathiLnayJqW34CgXval2IrpuoeEDEssuM+c8ZVELpS W7KA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708589520; x=1709194320; 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=ejiG5wp8wHYtqv4OVHF7H3n1cMrEsgDccZLLuZArdnY=; b=SWPucf51801nQd07Hq7mhpgbgMwfZQMqotdL6qTqplCaw5wXWQyPi9ApDDG4t9Ostt QQzpD31kpdvO+jVL677YVj6y8UK65Syn5K5KfrnpVtXAOB+DxAMXx8ZRZSIS2YoqHwLi Ih+HZxyLlP7QLIOeeYxkzO4MBHC91XSEPClliXo2cOnS1Gu8Sue7uou2Y9AY6OYTy1Ui BEq6mvzIUtwwLGZmDcTnyllz44gqePsJakeIsfi66lkpmbV0LK/2AcMwP5k/95UFkEiV ktMqFG4D4tX6Iw35ogxpDQdTOEjzyAE97/0GxN33ub+7YqU+jK1PQDqqV3ynQQkaprI1 q6VQ== X-Forwarded-Encrypted: i=1; AJvYcCXUZm+uTdufbkfLZ2LnedUcyT7/D39fcpRbr08LXql/3TYNOcxm7giXLL6rje7tc6SAOjGdkCouWkNLSCwpCxjjQiM= X-Gm-Message-State: AOJu0Yxpor8cKl4NibUu7fZMVXAyJNI4zL66ILzieo8Ncee5YRpzN5x8 Lzc3RhoRMR3XsQENEjTcdyGcSO7DK/mvnm26mLfEg10UEB8/ztEf X-Google-Smtp-Source: AGHT+IG4Sfvb1A6057v5bmOBRwDro0a1UI6orgA95fIP6RLJByG94Z7EUV9wpMjkFx/vclOd59g6pw== X-Received: by 2002:a05:6a00:1d03:b0:6e4:c3e1:8fb8 with SMTP id a3-20020a056a001d0300b006e4c3e18fb8mr3075598pfx.8.1708589520591; Thu, 22 Feb 2024 00:12:00 -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.11.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 00:12:00 -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 1/2] crypto: introduce: acomp_is_async to expose if comp drivers might sleep Date: Thu, 22 Feb 2024 21:11:34 +1300 Message-Id: <20240222081135.173040-2-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-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: D40E840015 X-Stat-Signature: oeq88rfxfzy4fik96348gqz7ht9ac7e9 X-Rspam-User: X-HE-Tag: 1708589521-287437 X-HE-Meta: U2FsdGVkX1950UlRwyTLnknUC9pLZlzBJ7RyTz9bvkvt4VjN/EvJz0zTFjhx8H1cRrFNHHIw299EAqQRwOX9a+JaySVaKsb0IQ6XFlFUUSPUHzT4N4+OcVnvvjKq8JqXnAvk9Hi21e55rF1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/0n48eHTa+WagVqSd9UZypAHAP2LHBzMaz8Jj1BvLjGA3tEdgIUf1FZAgZ+nimWAYZOiH1XlNgrrWr776haRJfTqMTrYmNADZxIRmys/g6bDrTQS6sOL+IhGG1TSfw2mf8qGncZaf0SEKdsxBwpA3W5wpLVsXeuZd7Ra6NrH1RfKDOZ3PFlWZACCj7M1HZwdM/XQ4te/C3zOUhkua+MqkxcZAqxVbojNcAIfmEeYj0kpm2ClLx5kgHN5AiuH2B1PIUGKL8jcRByswXLrw8e+OMbWXA1HFszWu0ctAbhQJC+SZmRJ7zJc+HrzbnS9Uo4rCxPe1LzNj17ub3QpkyfaSJ2gPF9yQ5DVwD063p9mGvZDQnJvADo8HOijHIs8mmIbR4aYZgXaJbu8/czDDY/e9z 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 acomp's users might want to know if acomp is really async to optimize themselves. One typical user which can benefit from exposed async stat is zswap. In zswap, zsmalloc is the most commonly used allocator for (and perhaps the only one). For zsmalloc, we cannot sleep while we map the compressed memory, so we copy it to a temporary buffer. By knowing the alg won't sleep can help zswap to avoid the need for a buffer. This shows noticeable improvement in load/store latency of zswap. Signed-off-by: Barry Song Acked-by: Herbert Xu Acked-by: Chris Li --- include/crypto/acompress.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h index 574cffc90730..80e243611fe2 100644 --- a/include/crypto/acompress.h +++ b/include/crypto/acompress.h @@ -160,6 +160,12 @@ static inline void acomp_request_set_tfm(struct acomp_req *req, req->base.tfm = crypto_acomp_tfm(tfm); } +static inline bool acomp_is_async(struct crypto_acomp *tfm) +{ + return crypto_comp_alg_common(tfm)->base.cra_flags & + CRYPTO_ALG_ASYNC; +} + static inline struct crypto_acomp *crypto_acomp_reqtfm(struct acomp_req *req) { return __crypto_acomp_tfm(req->base.tfm); 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/IGW5q0FGPrUdLJ8toY2MNG9WYS9CObYlIpB3xw4l6kp2QOjoPu78MJlFl4EZavar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56qGTZB6xT6bhzIUj2BmK2RFCZA/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); }