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: 204599 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp102110dyb; Thu, 22 Feb 2024 00:12:25 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCXgO2B+Un6l11wKp7JhjiyX+FK9eGIOeP0wzxg1PQr9IFhZidmWATzzkqL35jcDW/jixFHKfmv33GCfu/W+K4oTdxLRVw== X-Google-Smtp-Source: AGHT+IFyLM5qozzhnmI6U6RruEji/kQi6gAVmrEIGaUIjUt3HJF1NNcnIF5GjoBHISDjNCYvtGGf X-Received: by 2002:a50:fb83:0:b0:563:d16b:a04f with SMTP id e3-20020a50fb83000000b00563d16ba04fmr10330302edq.42.1708589545660; Thu, 22 Feb 2024 00:12:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708589545; cv=pass; d=google.com; s=arc-20160816; b=l/MnTPXP20GjcGrw/M2iAny/TAB5bdKrrAq/kMqihp1OFrRnAJSbRv6avEsccXKEup WcRu+R1y0Q20cdhQ1Iyb76jJR8FkhE9rSrWQUhlULWqsJpSz/aSR+QoQxAtofTm/yE6d NAixBq4jyQKaKA0xnhf3yRredQKtdAWlgC5AQeFo+s7WvDK9TC0ORx2T6q9YIXztTaQb TF/xVlJVuOcKRrHE8DE914oo5bVoY/rfinVvfj4XgYO6nLXSFuRNVM03+nuAEEHKNfBl E58JW+l4SIUkr15a//7p6DxYdvrwV89tI18vf/x2Wr1pzKKv0r8COK0alZeRc51UvE3J NZVg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ejiG5wp8wHYtqv4OVHF7H3n1cMrEsgDccZLLuZArdnY=; fh=9NWjjnmQyu+QI/UmRQGJd3oYFEkmF+bUXiAtmP7/JGo=; b=oqMYu1nUdLy2sw5AD00WDRAXnugQk/7Qs26/KcivFI834ZN+DSILERazbhjaxxCu/k cBVU/BBpYXswDmPjJaFCK7biUEIMDtw7KA668MEt45+YT4B+nE5OHit3B2suW1bkXNHR MfQgbe2/paAnfTdG267yLP6bspHj1JhDM4UdQiS6BFvp9mJQ2qcHo0XlxhTinpgoR/xA ZLr4MCnjCX8QCmaKvWJiRSLzfZXnh6aEZEtrSLQirS5rhOX1mGDp8JNcv6Iy1i/9Cclc 8uhlZkWmWi/mdSwPJHc0ZkAShi6n9JDxylQNzgOsuGC5jCQVH4sKsjFJ1UnvjPNazz3o nrhg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GICgMRGl; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-76067-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76067-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id m22-20020a509996000000b005647dbc3a64si3527624edb.352.2024.02.22.00.12.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 00:12:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76067-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=GICgMRGl; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-76067-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76067-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 464861F22076 for ; Thu, 22 Feb 2024 08:12:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3FDDB1BC47; Thu, 22 Feb 2024 08:12:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="GICgMRGl" Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 618B017BBE; Thu, 22 Feb 2024 08:12:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708589522; cv=none; b=GVAksJOlZBBDRsu6DDENgUIiQDq/jYr4wWcvNLgIcsjr9v4AOC9ZstA8oS7BUC8EkWQGan3WvvCUhEW+G6IPCgs20Vr/pvh9Ty+zsCnJFsq9rfMTRGmcMDTKjXiqgzjLMRKJKH5wjVcHW5bIonzrl8CMoSSX3LihLV6Ra1nuhjM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708589522; c=relaxed/simple; bh=9Ps2NP75no4OnAmlUhTQGFRfVnHYMA1QQnKhCrM+BXI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=W8DkW7xfrqvIYnE+RUfBWaq9dMEVTxnnLEpK18hEKiyfFZzHJ2WPP1W5Q4bvRwKr6nTQBRBklR14TcUH6UUA1S4ewzqpruV/iEZiTdC/uXme7lR/ajURFdHYK79yJT8huPoo1llVyiSEKRpR8Ll0EqAa/CUWsHvbqhYIbHQr2hU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=GICgMRGl; arc=none smtp.client-ip=209.85.210.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6e08dd0fa0bso553164b3a.1; 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=vger.kernel.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=GICgMRGlA36/ZKtybmiZ7HQYlybINrhs6ITok6hvbY9/TY6X+Vf42Ka1DBdTudzR0a ZM26BC3kzGje7UDhs5OGiNkvPqbvX5G5MaKVj5PIUGEUWtan1iuTppfuo1DSCH1DXNEF 6FLaJrOvwTJShwSOQsANFw96Hb7DxoveDyXh0I8S0Bg1dLFDaDhJN9TIgU1Ri1KTcOEb 3J5Y9yXdOxLOEUEhKPqw96dVpapHdXMNlb6JtMywlxInr4HTn98ZJTmVFef7HJb87g97 pAmE5wWDIZByeFRfTNqFOO1g4lPAy4caH3R74FjJXkSpcW7REMcp/esR/5wmIO23knWS K5+A== 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=nu/j+vl7ybddJJzl7SscaZzE0uf+y3fjwAeRFitT0H0blGmCI1xJgBsNPtPBqNHMHh yELLux6Of3jX/bKWJJxHB4FSPO2thicB1lcIr+mc/1MCz2+tdAYVHyQQiM925AVHqiX+ pS6s8HxJpg1GsUKxUaBvyxDSps7SN5mhhsGpXjttrrh+zhordzICZmYWx9yqp7DMXj6E 55JnlFPrfvAM42X39Oq2EHUDaqdTABthXBDNmSZrtmJNzVu23kQodIrRO4UepuksYAiM +V+Y0gFIXxccKcZ4A3nZWH9fY3VyHGm7o1yzVVw5gx49s6957/mJmTOhCaFTlEN5XGQG 21Lg== X-Forwarded-Encrypted: i=1; AJvYcCVtjlNHbe15cyV12Q1+blK8wccToNQlZaqKoYD2KCaPTXyW25DEnjYkj/VioEof+7e8sf8O7j+c50H3vBmb96qyDUIEyTOhD/rVhVQY3IQaWfTsDt99qIE9xPQkQG82l8PvgB/USWLApQXA X-Gm-Message-State: AOJu0YzUg8Vy869HzQxOyIn2N8y2ZLQCljsmzvld8cm0UKh9zOvo6N6N IDg5ILuqaa4+nHHnBrVfwl4oZGiotfqVdgApp50I2bNXrnav1j5N 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791585991721350807 X-GMAIL-MSGID: 1791585991721350807 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: 204600 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:aa16:b0:108:e6aa:91d0 with SMTP id by22csp102195dyb; Thu, 22 Feb 2024 00:12:39 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWurifz/6sgHWkJV8XWHL0UrWZcyMn4YBhDYPFmi87FGf6C9WwFw2fZrzMPsHEhXl60I0pv9kdUj61kzliIF8ZWViccUA== X-Google-Smtp-Source: AGHT+IEUZCAZ/umlShsfQlBevRNjLWGL5dp+X3QMCEA7xvJM0w40zGPYG1CMYDVj1GxrTIYZqu79 X-Received: by 2002:a37:c44b:0:b0:785:a111:bbe2 with SMTP id h11-20020a37c44b000000b00785a111bbe2mr23423104qkm.41.1708589559606; Thu, 22 Feb 2024 00:12:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708589559; cv=pass; d=google.com; s=arc-20160816; b=UntcTuNMdhZb38SbCnoAZsiJlCClWMy39EAqAh5pY6qimxNhevuxhs1Jf53mLVTlez oJj+tEiguIFBQetO0rWLs8B6Vx18pG52Nlh0CbHJoQPwMqaTgdtcCCErzHpwtOrtRpJ4 MfnVXVpUEQL9GwJcdAp5xfmz8OzPxuNCvg05uv/LMTnywfjFr8mDjymoTqAp2msw6nS9 TY1J4m29X/KicNbiXY2grm17LCPqeJ/J5d9G6pFJ+m1FmQ48uSb9zkd5Skq9HfSAG2dQ IdrAM1zTaxeisiiA3N1y9BfnAJ/udqCyK0qA/h2Ex+6LWqnuOvIa77EG14QuDQgWt92u fqdQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=Jyzbw4yb6Txj6TvozTLsczGvcpX/acfEaP+bFGtpG1E=; fh=CwYWIbXqILBspnFfUHn41MtdfY8eqZNo7Bli4pAX73U=; b=dr6FK9Jdl/DrfPB8Jg8m7LCED9UcwRYelDvTjNNVrgP3w8dNhD5+dkfj/UIsQPH6QV 11xYOLaJP+sQUUeVJpRDEFoWKNOpX4j1dJg3eWclbyNTeY/K/8iRVP60Y/CTLJZBlbzj 2ZLWV+RiSKO45OiKJIj1xolex5eOZZ3J/OaVXlCqKRqj2xGoYbQVRg5nwk6EqfyZ61Vc SrUWNemWYpjvSMTAgJysWVB/3W1iD0d8+sOKdI6E4NGk7McYC0XKjD0cmRuPx07UHQx2 Z+mluOxyh1nV4+8W9y5AeLnVAnewb9+uqgC0nw5ktJgBs2gN5dDN9Y8cF7y5Gjee7GqV L+ZA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FRwFqxMY; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-76068-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76068-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id op36-20020a05620a536400b007878204c68bsi3706663qkn.662.2024.02.22.00.12.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 00:12:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-76068-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=FRwFqxMY; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-76068-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-76068-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 5D0821C23354 for ; Thu, 22 Feb 2024 08:12:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 10581175B5; Thu, 22 Feb 2024 08:12:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FRwFqxMY" Received: from mail-pf1-f170.google.com (mail-pf1-f170.google.com [209.85.210.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1A2C20310; Thu, 22 Feb 2024 08:12:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708589529; cv=none; b=TK/6SdnBakjM4lDPiEBxIZBgnbZU1eocOX3r1fROJ6Xn8lh7aaQXoocMfDGyk0rpj5zrFe+tZMi84BINWwwEzi/8F6UGrJ/EurMuT0ErD7nbK34W2SDEWL7D5j3p3lbJp8oE40AX1NNpS1+mlZeAduNZuUkPUZtRV3T4v42ltB0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708589529; c=relaxed/simple; bh=OhUr3xHewTNQYlcnCfLYnZEEBSimq47w7Mls+ifxF5A=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UsositIwS6r/r1xKcXvLvfLZBP95ApN4IAQZH3D/MzbA9PKfWaQ8QWP5DHayRER/52PiTKnDI4Bng5LMX7sYGVP/Kneu59GAtBCDj8F+K0X++ixsIzIjZiyfV5dgZ34UTBWL0FKohQ7ucaGGPMTR60rKjrJNlL8/2LB7Rv4MeTM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=FRwFqxMY; arc=none smtp.client-ip=209.85.210.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pf1-f170.google.com with SMTP id d2e1a72fcca58-6e32a92e0fdso2016697b3a.0; 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=vger.kernel.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=FRwFqxMYdefYSx9szuexuu301Ii+irwD8Qm4JaSm8nwQihwkogJY4Jers+GZn3DHe9 htvJliHSU/dJrDidgFkcfAppK0RdCVwtVPQHdijQH7vsg9Lw9gdiP5egxhQF1wAkkkD0 sSVaT7WgDpeD+aAB7+trxyrag8/BLaQ9iyt3T18DwsZ4h5eqIzMr9DI1T4JNwWTNpYOx Gua2deDGqu9rKS1GshKuXjRCsHOcyTHe1gABKeC/IMEJkScaTcapKjJFOmAILPqsRZ1b fUG4qtDkQibIipuDk5OYld4T9YiVSLi4HJ32solybSUDAVKl/jew23ON0SFE6LxBS1NX Xn5A== 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=wuJyjdV0D0m7ZwFyl6dAsApjjXK4XRU1ZHo3CxMzUVf+Mk1WSz9q4yxTDs6MhKteKs shVcO8lRgKzx33rdHOTHjomPqjW81Nm6R9EpJyQ9H9AHwytsRD50v2D5QSp266xhMppK 1+W4WCvbBVa7WEzG+TUsVrT+0mKqDPCd8XUlNR/ccblIfXlphi88LXWd5ERGqEUhfIbo KlbKdhIZpwdtq8FB31ij/H5d6omihfl1+s4iYwV4hRaLWaB6+7W46ZYDAE3NlKjohjkm 3qjaU6j+uD/pKSO63w68WseAFPW1fcAZnt/wXjNrINgXzP4u4eSaNEeDif88kt6/dkNz uiiw== X-Forwarded-Encrypted: i=1; AJvYcCXK5K3PxoPk60d/bc4xcGX3L0c9QtKd3TYR6bIuGZKpTd2XDEn+suM4Z2Ih7q8DqfeUoj1xqQd3dYs20IJGJXF/WGQ90bx6XoKBYfM9nzAS5kxpI5uHbYRuiB3SAdRL/euNRIJ54LF4MA9z X-Gm-Message-State: AOJu0YyiuU+J4ugNj4h2SH895XW3oZgJgd10Qi4HfX7/j9k7trRs6P1q 2FdvZdC6OnvqqkmEN0ZquNIb4WkVkZZ6kF3Amj4WgFbL77tv9Sqc 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1791586006013011236 X-GMAIL-MSGID: 1791586006013011236 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); }