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: 13561231 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 3174EC48BC3 for ; Sat, 17 Feb 2024 04:51:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 87B856B00A5; Fri, 16 Feb 2024 23:51:31 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 82B626B00A6; Fri, 16 Feb 2024 23:51:31 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CADA6B00A7; Fri, 16 Feb 2024 23:51:31 -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 565D76B00A5 for ; Fri, 16 Feb 2024 23:51:31 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 06188160135 for ; Sat, 17 Feb 2024 04:51:31 +0000 (UTC) X-FDA: 81800072382.09.D83AEF1 Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) by imf14.hostedemail.com (Postfix) with ESMTP id 3F1EF100008 for ; Sat, 17 Feb 2024 04:51:29 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=etMCtw4G; spf=pass (imf14.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.170 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=1708145489; a=rsa-sha256; cv=none; b=dSU3dHUsD37PBtEWwiK3TyX3te//Z2N1ly0JoXwppWLH1wsXHMELTXZRwmnfWIOzc4Km/t gDCw1vA4sRDeMpYUOKggOR6is7jXvarsJctgp4CSuWyzKEbf84uwz87G4H7t4Ca3N1tqhB S2wkbmybfTKRYrlZo33ZJhzYb9Cd1Ro= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=etMCtw4G; spf=pass (imf14.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.210.170 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=1708145489; 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=lBwGphqaBGgnqVopSLPzNP3HsID/sdo6yu3ftKGqOG4=; b=SexYvN1Ft699YrPJSfRccwIkRvp2NVYinwxD9wtePUlnXVAkxYQcldsJIl+XL+isKgKH9P lzJWoBzCszC823/BMBucRC9nUKvGJCL8mN2lQcyF8Tiv/FlfhKQ0jTc559UkWa3Fel7Gw4 fWF8xu9ibVv+03AeKjn4D+/kiVcpP4U= Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6e1126f57f1so1578128b3a.2 for ; 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=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=lBwGphqaBGgnqVopSLPzNP3HsID/sdo6yu3ftKGqOG4=; b=etMCtw4GEiypS8v68q43QuMtWFJCttI5gP/MeaB/zTRhmL5B9ygFmeCYt2caB3nRlk 3PvFnAArBoToRTiA9hpYM6eepSqhEOqtomL3CYo6FkSyEpObdgqyu8SiEZuc6TLFqfNC 9wQbejhH++vlabhENYI+qacsbn8GX0HeLxtOcr4qYFPRsoOM8HR1qEykIED0uCf75prH g3DvpEAhprYKbGP/VrCSVm625B8vJNGOl/lOvKswgFRqFtUQPf70wRTtufkxlS0g1R7H TVRJPEdEXPcyfwykoE28Zr2UXLzFI5JsFSA9OWh0C1V+Ayah0l+hZxIiI94yjOTRRQEf ZDbg== 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=aaaR/ewrouogviZbxroknzrKQDbPxyw0CYLsewkxjRY280z9Pvbd7RVZMDkjxwyyh5 JCfEXCeSvAJvhMYw8YTGMqhfWQkDvatkPG7GksKn6Cg6HMETqgucW54ScehgZids5oCw IcmLlX1cEvbp9xmdjnu64W46F+C3CNDISoLvICD6NxwSVnQq1ONcbZcpZQVcWM4iyeyf evbKk3MnLxdnXAkJOrlYR2aJyeaXqQXBMqdBhNITrSEEP3tK76pHQWmSCN/WaNMfJY7w mfYUeRvgaB0DODn6cUTXs4b7JV548fMTLjxsK0Q2sO5ITTxqBl33AvYyb5m3X9+rHUNJ 5Nbg== X-Forwarded-Encrypted: i=1; AJvYcCXrUQ+DdGyYuuQRi+fIpiFwmoebSjm5focj2HHFjj5owZ5z0Hlse3bIOsAeCQHeqhLxAxUmTnzjOu/8nb95T6h0tt4= X-Gm-Message-State: AOJu0Yylgjmcuq+NLYrYM/WhwfA8joPEAfK+bdI0Fl+F9hoEzXC0If2l oRLMPMeefV/IxYqAo8tb7It4IWX8AKHPQ9XJaPhJD/Ya+xdgHlwB X-Google-Smtp-Source: AGHT+IHDHukVZC3Tl6VbSP7cvk6J3RQAkpvZafO4xOt+DersUqDTPAn7tJNGZjo9EuDadh2/3wlOaA== 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> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 3F1EF100008 X-Stat-Signature: zej7pq8dko1ryranptfcdy76tfy9tdmx X-Rspam-User: X-HE-Tag: 1708145489-735161 X-HE-Meta: U2FsdGVkX19jOiG4rUav6sJ0cL2DxFD1mIeq1IqGsfh6u2qzGqqHCLNaZQdZj5xTKI4woumYrmtiYN5O0GZ5N+eASRoX1nsWC1rkkDlMNfRt7CV5GJWa//XvFwNtnAy4wHnuh0O9yqBjRtEEYeM6XVXqkgC+k4E7Bu+8wTM0ugYcvgIeIjXJ/utvyvpc/OB+uPgJOZuaPTgietWYAsZyb1kQu0gcgAy4R9aOLq/NqZEw9ndgkwJSLhBVmGMkS1TcwAsDR4l1Youdi1eA6ZwMU+nIXCEAWI0ntxX8T4RazfmgObbHrB7Itr9Qf8JoetnJauZ6Xnx6gz11Qup70PK0DiG2nlHpgN62F1zg8+3qxSdtRKPei3jJ+6PVpTiFakXVqq3hWGwQ2G1du5Mo6T3DiLAqItLP/IMffmIjE8xF3MOrRVcgytZab/fX6DIeUtCNbslIbtg/dCb9amyumniyWPWX34jPBlBc0JVjtyGGvnMhETQe9YO4Uitq6K3XOcYVZjncGZPZe69y/bRhdLa4Kq1/jkkzFw9utZhKVIU5InVvlu/I62rVgdgNhuwU/9EC5ON25dmLSgeCC1Sdt+xjZ1slbvI1QlrVUmGmEdIPBzSe3+XWIwin9BrEq0NmtNsxeiA8lXA1b9brOIbnDoVj4KgG8QaIGt0c0/Dws8GE5lioQ6H/0U7dlj3zo1AfG3i5R/k5VQ3kOp49tyIXFl5rC5QzcClNwKvOiI7QjHDBG9brcf1BaEgVpm81KFW/BraY9oLJpSWXctYSZKLllR/QsVgKzgoBlyoAT4qUGRNtR7HZzWivQTygY2+KAju6A139eqt69lmrCgGPivziOWFKde0/9ViCZuEKj8Hpy3zf8QfezexLKjQXnoaIUlMQLhVy8//wklCjG9D8ETXgrqSGjWKUBZnhMwXZRl/drcWuQae82OsXGYtMWCW9xOL/FxUX8kVHFdn7TtahQTU3zki DsnV0z6A K8HIo3LGwqdXJ48f3D37HcJwspEMREK9jJYqYnCL9ffZ1RRdlUYzCB4VWVIeWH+AIzOKEh+1VEUk/zjeQN2TSBL5xBSoia2F6IdtMpR9eXWK9Jp8nSpF+PckZWU28vJcNRcrBK18moSWuVmPuY+NqKXiXptNEGzFdUEt4pIlWHRiGHqWUv4vrQi/ANymGTM6NuHz3QAJQYPdFDch1h8it2c4ptqN5j9Hmko79+K+eF8CgwrPNZx3T8qA/ZOqe15+01edeDpHFRhpPaBr3w9osMapTyi4JFl3F88TMWdRQOaJD8g901/TVNuxuwhqStf9IVk7DBjgB3zDwc3IeVKjnqjGnUYhToazyLc24vFfiEPgamvm6eapMVa6VEg75KtoovmlP+K1IBGMe3mbIfKXe7rcgX+hqf+vrt1X5UYcTwmmhGZFbyefnEDbZQxAqHKUguvQYVWq2pLVq9rmOluRhHMSmMG9eGqQ80amdDjU9kNUB/doT/o7kuqatVeNvf8iGQswCcu1JNJq4qTPaqsQnydTbDrba9ToEeCm1590pMNl9k8i/05QfjEe/7pbhl6IugpA9x/9RjzRB8RsEcm63+fuUtfZnFnxTFHKhek9KZqVZ54RBTAJoVqZD8+FAl46tWnED 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 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: 13561232 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 2A410C48BF6 for ; Sat, 17 Feb 2024 04:51:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 964236B00A7; Fri, 16 Feb 2024 23:51:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 915986B00A9; Fri, 16 Feb 2024 23:51:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7B6936B00AA; Fri, 16 Feb 2024 23:51:37 -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 66FDB6B00A7 for ; Fri, 16 Feb 2024 23:51:37 -0500 (EST) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 401D0A0150 for ; Sat, 17 Feb 2024 04:51:37 +0000 (UTC) X-FDA: 81800072634.19.48E46C8 Received: from mail-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.50]) by imf06.hostedemail.com (Postfix) with ESMTP id 5B2D9180012 for ; Sat, 17 Feb 2024 04:51:35 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="S3BL/57n"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.160.50 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=1708145495; 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=evwrpqE1Hiz2u5sFXh0svc6RdlbtMXnztqrxU8YZhPQ=; b=mzy2E1bclv4x5HKtMJz9DmH6fk1Z7IVgcrW+0pvdyAaZvx+u95m+Jevu/XVKSTPNzrqGvH F3Doi9FzFI1897fS5fSwqB7qu2YvMS7bp1JLdv0ydMsChVy+MUTrD7SAnO9g9U7iuoxeIc TDY1s0Ii6GKJGCG6Ka+t0MDTYda1SFE= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="S3BL/57n"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf06.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.160.50 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708145495; a=rsa-sha256; cv=none; b=T6V2b7EoMxqy6Ot3manXk0K2oMM4nTAJ/VF7GaB7ePeLWFEQVxGn2WBOY6DFUsh/sJdILl LBQVaLCyDpjGMst9bcoUk+Tb2ZSrjDUCxE1webjUUWSV60UeJIJFr2KC6t2iza+WnyKxL7 cczLDjvxAV7aEWWHCKLHNq6III36JqY= Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-21e7c3e3cf3so630349fac.0 for ; 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=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=evwrpqE1Hiz2u5sFXh0svc6RdlbtMXnztqrxU8YZhPQ=; b=S3BL/57nvKdpctnWzNNqSL6qiZuXHsZ6K0IJinMzONv34CaSlzA3B+bbpp8s4dE3gp /B7ctb8MmlGolRCbvJLeFnVQJTyTsP1pM6kL56N/FqRREoG/feDnq3dXQSEfXLCJ8v1p xO4Lvr5JqJ56qr1aaMZ1o5goEp+wfRsO/kQqjOUktZlnR0p4vRy/4n0VQFSnp7IPSicp fzzHoWpSFl3ShMnEPl6be+ulPljsdtXOAkZFMzqLS4jAktRc0Iv7RmgWePICab7b7JAM 8AHs0xsmwtGIcvn5eKlkQChIJBDOjmqBRiqbl7FQalJf5Rz+6WKK5T1yjjfKcNFIpg/i x4Gw== 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=fxfGCsyCc1pwj1u1R/WM1C5OTVKe8eC7sMWay1d10I38qZQdw2AddqQB7Ah65BQcQU vDFBvoQkSEqS+Ud5p5xfHOoSG8I59MHruEYbwptf23bDlp9YwgkU570b7gBFQnPbpOiD BC9ETlbrf0pREA2abnhvYEeG4ksDaghmEpZBjI1z8B0qd+aYqSrC0NuZmvBchLM5cAPd iG29l1LBFenH/SikugOdj3BkFPJuObX+Fe7bI/uS/AUIRXxBPF+cLQa6atW9PAjHcu4N 0nOr9WN0wzg6jQRxvE46YzvtMRngSsooeBd90y8VlFbWif+FaidPlhw3Qjl7fKCT3uoM tq8Q== X-Forwarded-Encrypted: i=1; AJvYcCXZTGTmGMwci9LfkeNMdhw+jp7UZ7XfBJj/GK6q00OTxZ+dGMfprM9LoL3WnwBvmWIVsG/WOSZCwtdaHi9P+DnN3Jo= X-Gm-Message-State: AOJu0Yys5SQc7fpF7kWCi4bE0g0vblaIjOEX9/HuoeMT9RzH/z2sLAI3 0aZ5VhExtHBT0Zhwzjjt0gN3O3Ii3cqIqB9wqolaf7E0a0qYsR2b X-Google-Smtp-Source: AGHT+IGXBcB2jEgts68yjl1/2gfApQFlQtEQ7ti8tGvcpljUmlNkpP8SfC6UTw1pnxGbgjKEotNTBA== 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> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 5B2D9180012 X-Stat-Signature: jk5gygupj9nwrbjez8safh8njbucnkce X-Rspam-User: X-HE-Tag: 1708145495-617485 X-HE-Meta: U2FsdGVkX1/wYQqRq6FCuyPnANXrbn3Kx0GGgH8VvTiRsG9KxKhuKqDjXWYDzLZUP5D5cMTrRcRID82dBDXySNAxiyWrSFwQTSve+NphnnNXgg46z4C4CrK9DtTMTFVQRRo7a/+xeVxJB6HrCoZWCuNQUMWnAUOOdP2V9PoJK5PzUASeLAdAK3lDb1jPUi8UGUMB3nKEPNR5KF3g8tXgwUV1a7oC24H7m5E/283GTdR6nYlc5qZpwavz9aqnlezW9GJKhX3JymlbcuVzhZBy3ShZUt3aF01Vt4lo5voqIyyJ9l65hNUUZuxn4t4HWYII9cX3L28cBokvqLKonqHT7L+QA8dPBrrh2OPPSTOq6vqSK4uaX6pbBunEn2KjSPtYBgLTLZjVWRQOJH5ig0G2sf98CpxR3NgaemWnjojhRAuXUbtWiwWAG2AjQJCtAJxpJAAQnygtes487Oz7iUq0N+SHa5WBgS8lBpK0QE16sEARI3UVnCuum/XcyHgn5ogpaaBEPZI3wGrkCVGRu89SB2q6PLgFQO/CY5TEGNYjgFh9Uox9DSjjomTGH7iU8MOSa001IBopzJQYHc8i1374QbgneCeqAes1SNrns10ijMgth9bcs2bh33bNlz9ooLRVY27LX4q8byJCVnUKabtAaEFKPyyYSXrs2h4ovWC65iHCwgofK4uvt4YcdSxNw5L7gvHo28n3OsV/6Y58I+nc1YwrITIAWBJpcwtS96ARKG9H4Ew3V+OD0Nkn9PAgTama8etzXSd3GTigh//0N0p302U6CRLH/FAZoC9GadkkMRWzDBOFL6ZJ9CTRKD6ng1MIvDh12dxcRP+8hFpOFWyejEVAezCfvug8NctXByD8lZjCAb+ZqfRuPCpt7q9Qt6wfoX6UY2h54os8NiHIfNf9q4NTUYcR+PXFXIOJwBnSWfst2qRgZ9kyEeG6jWNy1fEeEHTxo1atllx/bs4vvpo RiBq/o0Q e6CqknxQPsrf/2eA70te/XuV+vKOWit4WlodPLj2BicBeCeGafbZqWatArH3QSYJmF8DaZs0m3tijm2D8PzNN2cNv0WOE2ZYsZTMpEtug5qxed4oxwfqbQzCEhc0KCVqkEr5LkSYHvKFKAYHeZsEWhVhjuBTzOl65L78TBhT3/XHJLDm9f/IbhHKDb6Ko7q7cBmTAMjvU+ZeV2/UgZzKMq6njVj+tn9znOXBm+3XhgPjSsza06LgAOke92goxzUuFgrypYLiZGGBccvdTi090NSj6gnk5imDBKoqQSidoUVXhLMsf88iAjqH/Vb8tF+pUFZ6DA7pIrsaIL5J+yYoFznDTthF39VnRFDkK57BCtdHksAMTP52dCRKJe8HBM8HGiWtNS9/VIHtZSoUggqCVQWgIRQoY+baG1+eGS2NTVfOOdjZAiTTsU48M7CovPNUC/eFWhxoRBm895LlNBH/jOEX0/ttzz4e4xE9l7Er5IBp8S0uX7LDV9HH8m7Rr/Ysjae9NMxaCt/Tz8LntNhumDygMXnFQ5FLb4Kf2VRcoao8v51KXKbPovzedfPJbgosz3M+VRpPc6OPtOyJM5YTEE0N+5A== 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. 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: 13561233 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 7EB5DC48BF6 for ; Sat, 17 Feb 2024 04:51:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE3FE6B00AA; Fri, 16 Feb 2024 23:51:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E94CF6B00AC; Fri, 16 Feb 2024 23:51:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D0D236B00AD; Fri, 16 Feb 2024 23:51:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BB5EC6B00AA for ; Fri, 16 Feb 2024 23:51:43 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 5026DA002F for ; Sat, 17 Feb 2024 04:51:43 +0000 (UTC) X-FDA: 81800072886.23.E6B60BF Received: from mail-io1-f45.google.com (mail-io1-f45.google.com [209.85.166.45]) by imf21.hostedemail.com (Postfix) with ESMTP id A63611C0004 for ; Sat, 17 Feb 2024 04:51:41 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YuDxUr3Y; spf=pass (imf21.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.166.45 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=1708145501; 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=kW/qQndLj7MYeSMYgAPMliKXg25U647vW1M3U8+Bgew=; b=C62WtD+g2If+pLeAMYBR4C5I4LD0b0Ps6NZp9aa9KaAsRu+0xcNntTNFzVEP1TNViuv+GL iWdenyMHl9GdOSlCZZzlZPzdaZyAIGXhiP8qwU9Trxb4m8kN8sRvLuITenbaMJpeBEDmSX dPa0kv+C7CIxfxP6TeobVAhQbXEpRkI= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=YuDxUr3Y; spf=pass (imf21.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.166.45 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=1708145501; a=rsa-sha256; cv=none; b=qIs4aZdEBICwfAF4viGaA7tl49LwWMGwj/WV53iBhIG/kx/P4VIIHqyF5RhMz4YwYXo/YV Ci4CWQsTL7ioGksVxf7SdaG18ZNDiNkxlx7HWqCZCZW4nUKQnydREJL5Vl/uliu38+HN+A N8EAMI1W7RoqvfLBGOYwvGLnoKAkh08= Received: by mail-io1-f45.google.com with SMTP id ca18e2360f4ac-7c3e01a7fe0so112228239f.2 for ; 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=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=kW/qQndLj7MYeSMYgAPMliKXg25U647vW1M3U8+Bgew=; b=YuDxUr3Y+QcdoF+ouIpufiHfhztKvwU/dCJ9P+We6pBKkULjwrc8viDThhAKsxDQjP p+dRWB0wBbhcd4Mn7oy54qHJcmQCjCwVdIwF0RHvv6ujih1yBWOC3UGmQ+xEF3Q022Y/ 89FwTBmlEC4u/FgW+lnjfHAEPekrKo+wmrIbj6Yd6O12Z3/az4TFXFfpSyhCtqNlan9d Iih4pwbsfir4hFtAWujF0120yAtZfq323VPUmCpujfCj2NSbmkMn+9hC1cXHqpO+SnWV OSiKytR/EssGSFmlZVpYh3cVTscAPQV4kDBQOWF/S0CuCqu4uEDv/uBRgvyLlhiUK1uf rXSg== 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=gfuHNwTnn2w4tbu3qS4HmgdCDmRQKcjfgwFD/7ILAIsqtJWwvMwiu0HXwt/zKqYp/g ljIi9MLIebuqMM8prGxkcZjbU8DJuRM+cwVbbsrQmxwbIfkMeuNq0x0Wg5ecD3a61LNX FxqOY+V4Aj0Tq+qQXrEZnWyqvimrkqC3/uFwH2OgHyey1/5+AZvK7tC/YUI8fYSSzqap 0gIGljwLMkSNkYa4EDfi8itxu81/iDBgTu6bCybrO0oCYRoTnySicSPpiQruBo452Eh3 aHSppYW3EvoHz9rWZSNlnWSaLdF8VZN8HY2CCmN37vhjaenireFfP+ckd1fl+pva3lmt xyLQ== X-Forwarded-Encrypted: i=1; AJvYcCV0D6kPVx4Vp7y4uFcJGp6l8li4xGGkkULQR6QY1wTiSqewKh7BfVYB++/3b5ZEh73fPVWsd7TOaYoYrM8F2upcs0E= X-Gm-Message-State: AOJu0Yy6BMO4wFz5koZmtE2UCOX2Ccy4bvgAOHB68iK1XReHl9ENAmdZ E07VNzN3u7DEXrN94Umi9WfycfMRP/OQf/V2dDT1rzSlYdlk9J3Z X-Google-Smtp-Source: AGHT+IEOW4DS9BP7Ysw7VmEnIq9KlLgS920AXTvAFRO+XZXAmVk4YcCGu0RWQu1NKlAdLNbOmorNFg== 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> MIME-Version: 1.0 X-Rspamd-Queue-Id: A63611C0004 X-Rspam-User: X-Stat-Signature: ffsw7deoqrqz36no9wnu98hwr1kyszpg X-Rspamd-Server: rspam01 X-HE-Tag: 1708145501-195840 X-HE-Meta: U2FsdGVkX1/BAnioSwup94f7f2J+SJXH14bgCGJxAcITliPk2x+XcTqMPD4QQFsZofvekrfxMQzacFJbOHzNNoiaRleN0oVV6W820RR4VlqlO4M9cRgJ05zxhGUNC3Lv2Pzb7kcgTRbCtxw+JYNi30ILZXOs8qd9+qwkfTLlsVZst46rPP5+n/G4SIJfqAfZFTMZWp8jsc1pd5eFrI+HnZMcAuIMJ+OIT3RcKsnHX8NWt1EcxtIfH3KwiYfCrMZUz2Urgz1geLB1JcPKh1yfVaNqxJs4sYSvTxvYQPo9ZLjQpEDiTN5Ns5x/Qa2Dl2r4N7hYK4Ja1uLMhIpRmLIKrRATZ3PqzRpr5NuFQ79btw3JiAa+dnd5aTOXFDjl1rkg9riLA4kSAXX8G1QPsVu8b3Pfd/v0K0gRwEtctiXHfWaX6MBHIT6Ep9POBvsthZ+04bKFs1IpvD43X12VK9CbfhYLU2FVC5DXz89RbipA+81kEq8Gs6VNL4QdLh3BpAtooWXtfxfbWWd5MNKQyeiZPC3xEqW1pMyhZlktsglPoxD9i+qJeNz7n8X6S0eWLTIN9EZVb2C8G766E9fSPJy7FVGR/4inImiC1AfYEfs4EF6bcmeCxoc1OBgvAIoKjN3wStom4GsvmGTuFNIGnb+nb1ILdtucdgPibL3du2lHNfJv9qp96TtFa30peWWmHELc5+hyK9vbISQ9UezK5eZH+uV66bg5TLLjH26ckIcJREzaujz6nk+LsG2JFvUPVcoZtH9b96993d+ou6VEAjXFgnXOfc85eOyP5mcOQuNd+XVS9Pri+s2t6VwqeHMoavP3blvyBwTSIzgedwS52S8ZIbTJ6IDH7QQ5M1z3w24uCohGy1n78z72BCm37VCyiANQAu+RVO8xyhG1+ryJBxz5abN/IBXCuKUJ5rJVDOaAmt9j2ab0NUm58f01EcrlcVRD/mLBSDBkUR6Gq+nV46W WOyQRU+w FKNWxZsq6zEAVv8RehGuqT2+0nr1XGQ8IJRTUV8Y8IZL3OrCvl/oBuH273AQ7WDQXBDPPzYKSxQFjEHESI1t/bJtszZs/h0U0D1JwzlbUPV0uaRSx14K192N3VkZYpmiqpqgwqJoAR9SfRdA2qaMA/WbMbB5vCb+oEz1I 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 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; }