From patchwork Fri Feb 16 04:08:13 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: 13559557 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 ACB5CC48260 for ; Fri, 16 Feb 2024 05:44:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1920D8D0006; Fri, 16 Feb 2024 00:44:35 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 142AE8D0001; Fri, 16 Feb 2024 00:44:35 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0093B8D0006; Fri, 16 Feb 2024 00:44:34 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id E560D8D0001 for ; Fri, 16 Feb 2024 00:44:34 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 2461F128CA3 for ; Fri, 16 Feb 2024 04:09:03 +0000 (UTC) X-FDA: 81796336608.29.A59F713 Received: from mail-pg1-f175.google.com (mail-pg1-f175.google.com [209.85.215.175]) by imf15.hostedemail.com (Postfix) with ESMTP id EB91CA0031 for ; Fri, 16 Feb 2024 04:08:59 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=i664MK+2; spf=pass (imf15.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.175 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=1708056540; 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=ip6H/hpmZhzyeEdQqkgVS2/3JYDDw9wfoPqTzf/YhGo=; b=wB4RI0ealuWX3HZiVG8Nz6iVicHz6idJ6H/TmoACtUEbECeU+F8bmmXCybUnvjig8HN+C0 RvFHrPvou5H0lB8e/Dn46an9y4pukxuK/GPCuqhlJKC2uCZQt1/TUvZKEBMHU2VfSyvg7k htQAsy3kEUYB8UwoyRxTiykt43I5mS0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708056540; a=rsa-sha256; cv=none; b=HIpY+ij7x6lGFVaMIQKu9vByheBvWdflbo6kUvCnZnLqELuux/Mr3i4gthC0tiRxJjDY3M Vark5y4VfAS2Xm8NasT1UmOXCLJUgSYKjE/LgK4lNx2DiOc53qTvGuFm7rlHbu0Q3LOPMs tCZMtjJxw8vydYZTHasiuqGsczZEv50= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=i664MK+2; spf=pass (imf15.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.175 as permitted sender) smtp.mailfrom=21cnbao@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pg1-f175.google.com with SMTP id 41be03b00d2f7-5ce942efda5so293143a12.2 for ; Thu, 15 Feb 2024 20:08:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708056539; x=1708661339; 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=ip6H/hpmZhzyeEdQqkgVS2/3JYDDw9wfoPqTzf/YhGo=; b=i664MK+2H9mWqj8LnCs+6lREXOcsa29fd3kbVsYgU+WbxIUYU3H+rvy6RYbhlnU3pO BEplOA/7i6S37kXbhfz4hUpKEFp/FEAV1++1QZwQbSaxW/9p8w4K1imNDKedIpID5nSH lHm9MBqBv4IY458mwhuxSo6EXo071Crgs/42tWCJQkraI7vLNjum0pzbnQfi9ut2IhNy 8MbstOwpMloTEgjC64FYQqw8kIzxG0Qb/+hQQOe6hWg+1pAj2Ysu4DWfRalMSy300JhT BrrkwLk2q9WsLeQOuyNCsECUz2VjwyNwaWfuXU6nsykJNdhD7HPV+dOfO3EB05NjlvSy vBBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708056539; x=1708661339; 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=ip6H/hpmZhzyeEdQqkgVS2/3JYDDw9wfoPqTzf/YhGo=; b=b3i4kGYXek+bwdaqjEqcddmr4Cz4yCHzt/Zg/Pbb5n1hxvX7MnVbR5/cHMhE2IUCQu jldtop+VGYnYdJjSl0otsBPgYihyOhkHXHgn1o7tBEQHaH3/qvw71Wt3CD0Qhi/i9Ev+ cwZ2WrsQen5n/lAnSxYF5+xNcpVmhLYrtctSl4XgqSoSuTqHDWcoqHritEDXZeE0O9/b MhNRf1KzP6VNxqB1GoEyF4lb04ULzK5dqzMY1qHdV82Q2y5yffwuL0UsKUFcx/C7yvPV tu9cI8CX5DwX+R8lVFgjbaU2RVYp9OmNKgXH33oAkDHREoa2djQTdnlmbn2K/U+Q1EKW lvtA== X-Forwarded-Encrypted: i=1; AJvYcCWvLciyDZJD8+T4aGeKOkmI6I3eFzoy7WR76MEDEQ63VSc6bjG2/WdAVA6jXibAbWJ+kQ6N05K4i2VIfdEnGK6mEM8= X-Gm-Message-State: AOJu0YwAZZEcNhQCfNjodUyQk8Fu5SwqQbnRktwoWI8eVazgAN4AXhuK cQz9BoiQI5mCyz004iitMMyg0XfPQXfkbVj7FAfqarkpDMYDXWtM X-Google-Smtp-Source: AGHT+IGnxw942wN0X8APNw9Z9LImEaaq2+ARj4+iKb7RV8ZNkpfq2Y5zhnFisTYBv2GrtJMh2d8vNg== X-Received: by 2002:a05:6a20:9585:b0:19e:3709:f3f9 with SMTP id iu5-20020a056a20958500b0019e3709f3f9mr5626996pzb.2.1708056538819; Thu, 15 Feb 2024 20:08:58 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:f28b:3925:777f:45d4]) by smtp.gmail.com with ESMTPSA id pt12-20020a17090b3d0c00b00298ff26e4c8sm2321393pjb.26.2024.02.15.20.08.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 20:08:58 -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 v2 1/3] crypto: introduce acomp_is_sleepable to expose if a acomp has a scomp backend Date: Fri, 16 Feb 2024 17:08:13 +1300 Message-Id: <20240216040815.114202-2-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240216040815.114202-1-21cnbao@gmail.com> References: <20240216040815.114202-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: EB91CA0031 X-Rspam-User: X-Stat-Signature: uxbpwhejunwark8deacxg8886dcqxid1 X-Rspamd-Server: rspam03 X-HE-Tag: 1708056539-379358 X-HE-Meta: U2FsdGVkX1/HPhPhmevpUr0YpAVyxzlzUzqymHTkkn1iE1/1gqHZSxlAe3nMmEzlnRt43NCEd/sQgyVdSloGsuhUlHblRsgC0enoqusw2WoPL39A0ZbXwPvt7mAFXwaHVJZ+oI4rNh/n6ePvjprOT3bpS09lGljvSrJnErscy/1NQizR41JPaJ1vs27QBMriXz2zNZJFvlvQs9rPR6vqcsaEw3LQGbynFZyyvOs58kLD1pL1AC0N2wBmvE7UTo3R5r1DiDD5EUVPdNLm+L3tJS5WZrJN8vZla/wqcTEeEhG7l5UEBzU1m8OTvEsvbR5jdtVxcDAymaeamKm7ONM4yKby+c+cTQX4IRwD3R8VAn7Lz00ZCqKlz8cIHEcn2h/chgWIaH8No27+ZjZnMk7BfDpHykBXVr+qh2vlu1Y3Iq/uBwNqY7SAh3fo3v25vKOcKEVS+Z9VbTqiKXwkORHo3IdidpI4Qc8a/3B4MMxRDzP17dVX+xYzGl+5wo5BItESjYuqytNDvOdFfew7kwyp5JomnMlAct2sZjf4Cy/7EwTrKVYGkaNnKryfn3X32CG25NYlAN3KzFZ4/+XN5N/gxHP0k+ThjGmHudN1dJEAbzC4jhHLZ6kUp65uKTbOhNyJc91D/2GwpEYkJX4hW1nhhMXJRni3hs2qyebo+/QOso0oFx8zdy3PQZ57ZwCvlrBH2ZfVjlgYso6kme1F1v+oUCYo71h11HB4k7nCi8fNw8MpBrEgm4i7GuaiHyu+hL+w23hHZXVK8/jb+MBlzLlRhpUU7bAEsbOhQX/S2aoXMiHKzkR3vPFYEMyAYaR8+KnQteBjPhVxD1z7ns6DyOlwM9Uo3t1ux1HhEnWTHZeG0nYG7kpfMjtCxIRbdPVtblut6eHWWSRpxCo71CpWlZ7AJfzKKfXoLaLsFtYFfxGaAPRIcwkssMzAfHdM5TDohIVojoobLi8LHUcmTe9S7un INGFOGDU 08KdzQKqPsSaqBDVDYDXoxp3nwVFo+Tc4GniXqBW9TXkvigah9dTUKWZN4ddvSJlWTAiS5VySYTScsB91lDBDl0P3RuyOCq+shGBGCJyJnc+hO9io/7u0/QQ3QKeWm2F5kB9FGCUehajzpEzgajZy+HSlje7WRQlRQhAZH/yGnZGxwRGo9vxOK8/OIAhF6HJ0viXCY5XTcPOIaav4Kk8E70w/JLm0Awbl77fme62ozfXK2sFiGiQnkuQaTLgI+ebW9znat8x35MFFDc0sGxKjWXoOZErd96skJFYIbt32jZXtZyTZSsfTbMZtigF1/lasOvraRLgihaq+sO2hXh81rA6b7n+Y3sK7zgIzXs5Emw7Rkm8ytIKKODaKUpZgyqSSCQmmVt9fjqNctsyFE6YDSwp8ztjU2eLeFl//AKwkdAHIsQO9Fp8geyF/B9Fp4eZhKj44xBd9meBbBNBsaS1HcGjUEse6hkIAlXczEknKvy7LO4IvMTEV9u2RZPiDUbx333KxOoa/h2R5TB59U0wAkf7eG/C+ldIAub/wM7+hUa97PC6Z/GpRUfVOh8OneHfiJF2q8ChO6HiJIwfS/Luxq/TDjZj6atByw+7cQVGJK19LPJ7ODbf5urbiM8pzUVkj8iH3UQrp9GM1G36hPbsZKqNNIPe+WbIuNR0f 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. 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 Fri Feb 16 04:08:14 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: 13559572 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 297F7C48BEC for ; Fri, 16 Feb 2024 06:28:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A101C6B007B; Fri, 16 Feb 2024 01:28:34 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 997AE8D0006; Fri, 16 Feb 2024 01:28:34 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 810856B008C; Fri, 16 Feb 2024 01:28:34 -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 68D156B007B for ; Fri, 16 Feb 2024 01:28:34 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id AC1EF146725 for ; Fri, 16 Feb 2024 04:09:07 +0000 (UTC) X-FDA: 81796336776.12.A89CBEC Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by imf11.hostedemail.com (Postfix) with ESMTP id CA7064001B for ; Fri, 16 Feb 2024 04:09:05 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PM9x79hb; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.172 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=1708056545; 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=uQ9C4C07Lh00QdEMEtLL7F2M/Vil3VvFnVKlElC+iJU=; b=GfHnmwL3mjLTi01Mbk6iWzSnD+01BvYg15nLzAA3e3a5zuTfeI22M/BImoYkBMEpJAvDn6 FI4MnsqkvvaEBW/7FqxMkIwMprpT4T7xcVh6BYAlpRAYRSmhFf+vhWMZ/aFOl6l4R1i0tt /c28U0OuQKEhL79erDsgkceryWcIPpc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=PM9x79hb; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.215.172 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708056545; a=rsa-sha256; cv=none; b=IxZ8GCNKpTSf2VZzZkFQXxp8m3XlHnL3WrOBYwfVEHIgKo6UX+Z5kC5/CzByiper+4Y49q Lq621QBHP/W7n5n4eQBQMsfOj7uVGG247rcdtsIhKkdWQq5h3uznuZfu6UOaOJMGD5Ox8C ibawuaZkc0LF8PxkQBDuuBZYgSV06hM= Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-53fbf2c42bfso302339a12.3 for ; Thu, 15 Feb 2024 20:09:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708056545; x=1708661345; 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=uQ9C4C07Lh00QdEMEtLL7F2M/Vil3VvFnVKlElC+iJU=; b=PM9x79hbNqQEohP3WZNV4dEN6LpnX3glsogVL6HDFlbTgcwDppqK8QKEMF5YxNQDPD QPX+tRFqRkyXYLJzb8bu9m2CIWEX6FxxUW4bDm84WZJg7V+4+dBkm06ftzhqWpXdf0zC lDPA26CfcaH/EF3EvnEKl3I7UWy5sB65p67qdasFXtbPR2XYMiJiPb8qRDmTC/fRIYrV HArLlLezTBcY3U3feihODAATl5bcxBXqvzpA7Yck4oOgpRweTU8N8KkiVgGgvfrBMtws FAM9y78fUM+Q+7znnaEgfTSnGCHrWuRty+KJHKuWK7/SEYRFYblx6Itn/CZnMClJzFl5 XLSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708056545; x=1708661345; 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=uQ9C4C07Lh00QdEMEtLL7F2M/Vil3VvFnVKlElC+iJU=; b=pSkAmuAHuc/M3lnM0CY0RTY/uY017jcMwv0OJfNOwmiw/slhMbYOYTmt20JHmLK187 jDv/BoiZeT8yrK7Z4h87/kHuO8TduDav1U3aXcbp6tMEt+DkkxAtRzxxkzPsevXeS1HK K5Wu6SZjBWOIoY+2QZNXx2Qpcaf/nC66Ig6q+S0Njnj3kmXp1jqRrY4kTdVQfJRbLZRP BCAO/QX2ZZdRjpciyzEc5MvjLVrsgSobEs5eLlgRHu/7daS4kwFugVRmKaH60u7ViXW4 X0fhCDb1jWFZvGhGs2wLyCK0QYMGy6UPGQpMMdVPP3ovUQegGBAYLFFoTp8ttymKORuQ WkUA== X-Forwarded-Encrypted: i=1; AJvYcCVlEff+yKzJnW7rCmkzml72aiqiHAVbY137Vv2wiQmvLv96RmRlAWEddomZX7cAUCXNYrqxXpNUNZ4lv51a4zoJWwE= X-Gm-Message-State: AOJu0Yx2Ceb0bGM2KBohOksYlS1NbkDPNOrShLQlL4PP9LP5maxzPC86 Hmwoqo5FgXu64f32St4/MPd5Odbs0PAya+DIFYbzBCn6CbBKOrZA X-Google-Smtp-Source: AGHT+IGm+c27oE9nV1vTL6DqB17c0WIc/pNE/jU1ctzgiqcPDvRGxQ+m4LGav7LM74bm7qpn24bzHg== X-Received: by 2002:a17:90b:3606:b0:299:3657:4950 with SMTP id ml6-20020a17090b360600b0029936574950mr257715pjb.2.1708056544708; Thu, 15 Feb 2024 20:09:04 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:f28b:3925:777f:45d4]) by smtp.gmail.com with ESMTPSA id pt12-20020a17090b3d0c00b00298ff26e4c8sm2321393pjb.26.2024.02.15.20.08.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 20:09:04 -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 v2 2/3] mm/zswap: remove the memcpy if acomp is not sleepable Date: Fri, 16 Feb 2024 17:08:14 +1300 Message-Id: <20240216040815.114202-3-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240216040815.114202-1-21cnbao@gmail.com> References: <20240216040815.114202-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: CA7064001B X-Stat-Signature: c5ek1frmkcj4ifjj45dfhc7g6rzdnz3s X-HE-Tag: 1708056545-685993 X-HE-Meta: U2FsdGVkX18igVFEcaMrRj/9OiB2JKsz0+VjyfGqGGFEPmZGjMam4yvQEhJMptjsG+qGtY7u97HeK6+myGIbb4fY0gte3f8ibPo09BSJIbG4JbhKsuIHmnczwgjhxQ3SbCIuA9dwAA3w3cWFYzK2Mz9sS//6H5nsB7qleWrrLh7bAC9MaR7EZlfacYzGYKh7oHxnOxPl+LWXt7uCnuvpAf9a0NDlaWc71Hx95NxOiE5XmmY6QkEA2rRu0Lhgoga6GxFP1fG7Nh+gy9D3/9SvDDDIxFPoPZeiv787NzKv00iPTFKH3vMQobOwwcNXKz81ncYw1BNWsGzX0yJZAQCaJUQ3t+IxlLPhW9WFsMnDcryqtyX8jU/cKb5+16yBiJfaTio+ClpDtITmxIMSeyzFYG2+f4t9QeQ7DVSjCXQ4eWlhF2K/qdXGfwK2u4gpWfFU8UkRLT60r46WuWP5DWplVeZJTJ/m+Jgml5/HpXmvMc02yzS70hmEP3fdF1dZWWrVyFyhyZXDtG8gtQTMhhKGVgwtTTYfifYHjBycKAke1Ps+MG3uKQsJGgd8Eryh6kGYp/ddCr0d+4pSbaXv4TB1rk5ZpA+HSFdwjoP6FYsfhb8w8LFYRmXl1bHQm/vHLpS6An2YqO7tpo9PBwtGKIeq5SpyWdksdA8i1FOe0dsjDka0WqOigwTIMiiO1BR4yayPJhv+GCbTYvSTHgyCIYkMFDVGlz39VDnLgiS/dHjry6wGUp/TbWYaWlaS/gE6Zqn1F2CWZrRa8AETXYy1QFQmh5aK8TMVnH5XuReT43+RDLmv3bN+UkJ7Wm9SJ7QtdOmDTwqw1H2e+Ue1qBSIjLmlt/HQPg70S0QGuBwDb5PUEH5+P0W61QYU6mG161s5AaK1n2mKmLEfZj4EkP1HQWSHWcMMmtWTZhJ15uKCqYjurHY90+mtA8hD3ek1C25oT7kVLKRyNowPp6NRUKYgSCb mC58fYw/ i4s9+CKYf1Ocqnt1IwHsF5Cu2X2Uf9v8PclDEwohmj5jj3VyWxI1QIYB5J+fQIjG4lO+MPjEvNau0iOUXneH228jN8b5IExcIQVNX5eFNO97zgmoRLHIB605PkfJMUVwMGMDSGCZNhbYrJZIjYR7q4PNTSTL480OxXIB85ZGEOQp5x4Ps9ooJJFFdvm9PBeNJMDuGH+GdaF2CBRt0+fB3snDsh9usXlAlyG/sc9opqdpkKgQHRUnqIOJgrh94/BYTVfZIj4lZz3WQQMi5kLV8QKZD4F7Mq6Ehj0CUe+j35AGU7oWiWm8OTY+z6yBgllIhsZYZMO4RPfy0xUK/u6VYb+lOTmgLiZzKMIBH/jhgWeQHzqFtcNi5r/Gl4gN172rWYXjb/lUELUH9NQysyx/ZJy2G2UHDEtW9uxMQ0p9JzqQ3eHy0gu2dIVVJ3E4W9PuJQcSmKbcwRVrtPHg5B5gqA4yLC/82X9moYqelH6nU2KTSNH1NWkzTYZSX+TNyVrngjzF4E498pzkVfJaxg2jLUO/fzRj8pH5GyaRKeR5JIgqnrso3UxqEbXP8CEJcx5xl/wD5 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 Fri Feb 16 04:08:15 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: 13559553 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 57167C48BC4 for ; Fri, 16 Feb 2024 05:18:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7B7918D0007; Fri, 16 Feb 2024 00:18:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 767048D0001; Fri, 16 Feb 2024 00:18:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 62E448D0007; Fri, 16 Feb 2024 00:18:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 5355F8D0001 for ; Fri, 16 Feb 2024 00:18:17 -0500 (EST) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 17F644A01D for ; Fri, 16 Feb 2024 04:09:14 +0000 (UTC) X-FDA: 81796337028.06.043DE20 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf21.hostedemail.com (Postfix) with ESMTP id 6DB1E1C0028 for ; Fri, 16 Feb 2024 04:09:12 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ra0Iysq4; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.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=1708056552; 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=6XQrWKuCeFB3F5VDKYjMLhXFNrwWfztKdQJEdvSBY3231pbjji2+3QMgum33CYJi+pyATO F4Q5hCeZe9qdfeoJb8QPRywXty7WnZUjFUY/3NCTQy1SN5nnSA3hAM+nWkH9FsDtPbIF/T yYWMt3KZK8sX1Acw3poeaXo3QQDqKVI= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Ra0Iysq4; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf21.hostedemail.com: domain of 21cnbao@gmail.com designates 209.85.216.50 as permitted sender) smtp.mailfrom=21cnbao@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708056552; a=rsa-sha256; cv=none; b=OldkhAgmVYQSPeRcNAQzMbuK2jOyWDVKv2QTW8V2Z142co+4eckL6hwkRILYVKFJ7cztpM qUABMBw2zNQQQZZnFIe0vtMZ6n9rvh1SqPDvMbda61sz3edkcjHYb3zRA8VAgsK+TdYfyP 7hI1zZ/dX+Z7BBTLtehV0ukLApceisw= Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-296e22f85abso1300706a91.3 for ; Thu, 15 Feb 2024 20:09:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708056551; x=1708661351; 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=Ra0Iysq4tME34L3VwswNWlz9tngbk92gO5P8ugnvM7LtUDuJrqeyxiIJ7d9qLpyRu+ buDk9dPZvujBGgbWQe7oqP62yn8xz89hk6XR7dc377t18hTxaRZYRbOIX6CyvcJdtawL Zjl9+N+ztzHHneUxr9MTIvbJx/H73jtKjWmm1L4WOVnPRqjHIQRpMMK06Q9KeLe5m1Oc Pwt+pt2gVzJUkSlGQme31Vu1lHvV4OfAXbygdUvevX1xD0yS6pbDdeX3NhWRVUnznuCx 56dlwQmSkfiDK9trxDNiROmgoEOZ58LjMQyv6nBOoxotoPViPXu0DL+khE92zLndOBgW sMHQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708056551; x=1708661351; 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=fCP7hBR2j5jkTY+2YAZJDCaEog1GrXDtGWdEohqrAyZij0Bpdqh+y857O420TKwH+W Uf3nTjaQZ4lssCkXSqphq/gSt0hGGhyT4e8r/anWraHgWvX8GH+2M6p43vFZHBJDd3wB YgdsAgbJ5cw5uSQVTu8dhggZzqWUwtWXXvg4hrHIlUKBRCgzHMJ8zLqEivDIJWUkWtTG uHUURsECsFezit1z51qZxgVlFU8TRXnQhTUeZwubNLokR1rxVzQPy9H3l3m+Hl9HyXx3 ovamSKG+seoiWZmztE2/PwGdPZfGD2vDdFuBYqHavWnbtCCXNXPXWaw8OBH/3XGxWDq1 eZAw== X-Forwarded-Encrypted: i=1; AJvYcCWTxYuNZvWeLFHlmArHaVT8mpko2ftbA/lQ7kTRZe+Y9jR+PZW8BmNfdE7LP5J30pVnYQnnt1+BjFPn9nXVy5tvTrY= X-Gm-Message-State: AOJu0Yx2G3JRHHdnoGmyZ6sUH30lGjwumGvJ0nHSN7DStsHnx/PAsjV+ e+kZ7TqnIfk2wNn0xM6Nml5BJZNoJRpOj4tOYijtFtj5X1R0Hvm+ X-Google-Smtp-Source: AGHT+IGAI6evbaJJ5nvBvX/krSGwKcXuM/Fjm1hRJ4n+X39jOxzqtqrVSivqkrRIltKTg3jrBP8pEQ== X-Received: by 2002:a17:90a:eac1:b0:298:d1d3:9ef4 with SMTP id ev1-20020a17090aeac100b00298d1d39ef4mr3368864pjb.27.1708056551160; Thu, 15 Feb 2024 20:09:11 -0800 (PST) Received: from barry-desktop.hub ([2407:7000:8942:5500:f28b:3925:777f:45d4]) by smtp.gmail.com with ESMTPSA id pt12-20020a17090b3d0c00b00298ff26e4c8sm2321393pjb.26.2024.02.15.20.09.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Feb 2024 20:09:10 -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 v2 3/3] crypto: scompress: remove memcpy if sg_nents is 1 Date: Fri, 16 Feb 2024 17:08:15 +1300 Message-Id: <20240216040815.114202-4-21cnbao@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240216040815.114202-1-21cnbao@gmail.com> References: <20240216040815.114202-1-21cnbao@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6DB1E1C0028 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: tnu3wggk37ott7ei187pr83asx6kgyd8 X-HE-Tag: 1708056552-672159 X-HE-Meta: U2FsdGVkX1++OvzSnJAkqAgip0Wx3IzD/pqKsdeXN5IXUtNjiFJ2DOPa+cSqvtRONl3mqi+mRYXti0OMR0wXVXvyv5ALwGE0exB992Hsul65jA7DhEVgakq/iZnXIfAVNfyIwExUycfWDW9P4l8vaflXH1c20004ND68SnK8Zg57MEyHkp1Wokwhr9vlDH1dR3SHlhDXoIIRr6Q7p+inowYnoKQ6SbTBAYytudMtGnOyCEMZo+ruo+HekWsIwpHx08yQfVaIeSvosq/c6GrHGfOIeEDEH8W2aCC3GX0srK/s6BRYwhz6r0BLh03e2gT2bYGW/Rinq7d6ZYejNhdyrOT4NI/iedftnuHASoR2VDUnmVwOxvZ+n+pWTBTpdo0UP8aJz6oIP3566zX8axCtJ/RLbciKmrPLezYo/rBHqBn5JdGA9B6ihA3wB70dRZED1526Qw79C8Ff4aUs7+CveFvtggNLIA3m7ld7kvI1qHLREwFVRy9TOfdHDnLxUYyZXfmUsWtOlxKjaMvvFQOzrt0qgIUt2zISFLuxorwBnl96+B9Itbu4DeDdveko6s5hf3PgH356zRdix+JhYWKRaqVjCJLaXqlfqcNdGLFK8VgPv9pkkt6UWp0NE/yO6DJ38ffu57YUW0obm5SbXigY9BAK3NOjNl0mBKiWZEn5Cfvgz0g/+GYrTgo2wI+WD8pmJ8edkZMeiodCn/WAcQgoJs5IXFAiOiQZ12jAzGVbYGN1bJRQcr2CDdT6qJetpaV+qXGlzSEVohsUiQIuwnnRkKBT5dcjkRSqx9Ac/PnFEWen0munHH7eBkmvH73xfjVF6lbFmNMEvIkRjnskgViqHq3l1G8EOxSi5613kuEwCIgVum0pO4MUoUVeminPv4iZOQ9k+GkUUTqz4Ig2TABpg5MCZ07B87XfYC0zRDP/Do+T9OmbrDUxfchsRvw2gI5w3x/IEFVspEdpJb3HM7/ foS8ekOQ rbj9lelO9a76z7cldW0HTH2vn0mnNxqN6em40SyWCyJQGEfTZhT8HewG25dE99zp4mWlFoNoJItLCeRi0+F8PFfEct1Ugs3UOvlJS+1KwVb48sN+MPpXMY5DlIkOZxUQXtKPFLaC5955PJzmic5OUA6S/0YXozbAtr6gt 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; }