From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.45 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796103449; b=42rxhGJFlU9dT6P55dd0eyf06QvvC1eoQSC4lAqQxsSF0SAudxCVX0IWufps0Y0uUAOV IAO0UiCws8Sj6OpaNC3BIhZzMZ4j6X1a1BKZRq58Lq8og9yn07FgfJFAvS7N42sLlgnlp vKjdinQ08IuGZRFaPItnAAzsijM7OscawaRdN+GMdW+VjI1JYJ8RDHPxvq+T//g29B7iA rFsWvEO8zlNFIM0nW62lVCsIf3frhOR1K2W5o8GuDQANxoHQDRqAZjwbWvj5cnInxUYMF cj2HPNlrqbmjcU6JS/H/XjHHwBElzrKZ/I2+O/7sqfJiAeMORsT9MRI5fKcnNcHI5aA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796103449; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References: MIME-Version:Content-Transfer-Encoding; bh=VGN79CrVj/5MA78Rxo0gdF+3UeZKHl0uPZOQLvC51jY=; b=vwUBAtqfSkr7EqI9hC9GHwW2Z4GGVnqDZZE3KhKhdPZBkbBnygjBhr8ZEM67kjJNrNAz l/tV6CUk67wgBUJe0JQ8Vab5Ncb3Q+Pa3xnunFIdbWl1cbXyea8E4rmBvob73X68f3K5C kO0ez4hRkSo9VtEl/uqH7AJMWiOP0vC/ymkjfgPVfZ6v47onnNBnBDS3hjZi6DNMpP1eH xvp6Hh7YINXmHoQm6dpuW4F/Ahy9jTa/YP+yzLl7nCLY3rlXXVw5P7gcK7JHgQ3LZ+2h8 wXZrNEBkSclrEWI9JewuzJel9q7mC1uNVgp/sWjckhjbAGdeAyjnlaeUaBuR9Ifcphg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=MWzpAMpT; arc=none smtp.remote-ip=74.125.82.45 Received: from mail-dl1-f45.google.com (mail-dl1-f45.google.com [74.125.82.45]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D7E9606A33F for ; Tue, 1 Dec 2026 05:37:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 7D7E9606A33F 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=MWzpAMpT Received: by mail-dl1-f45.google.com with SMTP id a92af1059eb24-15dd124bbe7so19211306c88.1 for ; Mon, 30 Nov 2026 21:37:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796103449; x=1796708249; 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:content-type; bh=VGN79CrVj/5MA78Rxo0gdF+3UeZKHl0uPZOQLvC51jY=; b=MWzpAMpTPfYEg4bys6efzF7HLiagQcXpFWXAgtR6VR+xFNGwcqmwRoSTydTitytSP0 jbr6pK8U9UqNyI0gGvq7jAaAa8D3wMzI0R8X+Y3nHm/yuE6py7sMp3m+scy1SpGG2sdx ztMNZrX1mnyk/iIoi+07Q6S8n6sSlXI0JmzkIbAE0Mno5PpMYAAtcrkiS2sYBtTfnK8S 1gKmQ+byji3El+eKsd3mZzl5+3bAPZtjsM5mwOwq9sYZl9Kqro41U6cVN4j/EY5shbUe Z8Y+64eqIruFcqA3ibaJmJ4DS8xyp7pSMRnAdWsdgOxXSgKIzrmm6haZp5nH+qd9i43N EvKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796103449; x=1796708249; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=VGN79CrVj/5MA78Rxo0gdF+3UeZKHl0uPZOQLvC51jY=; b=JLH9pNdyduSMo8pUwGCY43znJeea+1glJ7JJko+2qb/5v5hl6pFqVKXnwW7y9KVmSh 3xN8G2+4exXnxnCdTZlQ8mMQYgiy3xPaAyKOe1jOvkdMobBBoZDRrGWUx1QpDDGIdfLo cin1ipZJSB2dgfLi7ShRu5JPn9D/jIz/in6ikL7quz2PR93GFacX2sTxxJPTnc6Hu4U/ 9NnlVPBMwn9tNTTzJP6y7m2CPr8X6uTp89qOctIDR18P51yu2QsRsh8m26G+t2saZEwl 7/sXSpA0EZcLSTCQOD2q7es+OTWvelIkBwTbsROfa4qn7N7o7SE7QLGRQlLkow4N5CAb 5f9g== X-Forwarded-Encrypted: i=1; AL+hErHsiEdywx+RlMuoCNvbJydTzXGV6BN8sYtDJTVPFA/ZxiQmAL2fIB8tA6JTScKehKlQxIZEtn5RP/BxWes=@vger.kernel.org X-Gm-Message-State: APuU4Z8VdlY0UX/TE/pHDQbLu5qiAF/T2WJFebQ/vXPDvW+D2xgSMqZq jGDHCVNI6ShhlAf59W4MJcNLn3bTEsWQ/VCiFGXE39+p48LE+hypLmO5 X-Gm-Gg: AZFdTZffFcM7yLjPLDJLY2RDx+6biiJ9u6JvVf2UdIVKQBbb+QqNYZ15kXV0h99g0hM Nx3Lv6lsp1ZdTQedCRWTJDjQHsL1ecRFYaFaiVQW4ghC9MAMhNJSX/9PQRCIkexBQllWuvCxp8W S8NkJ23lZNSg1fpzMe63nMGr957nKmSkjEgffBkuRx06gxvCcdRMOm1J2WdDo+Z/kBplXlX4dOf QmkLUyaa9p0D7ewlMFFxCj1tbrt//MYc0+0ZGMuh2eRs74wBI1xOH17zlq0KjgenO1K5+qKFlym fYUGIiYt7e2XbkvCE5ZhpNUrBXm4Wms6O4HpBX/++K2RmXcNy8QV/9phTaeefGKqlSO9ccF2+rm Kdoxf7wEjVHXdafLnwyhUuQ0eaiJu/UnFYz4wp9joSy26yzN/xOZbkwqq3muAQcjjMbcF730CUC 9wUJaXGURrTCTQ5AAxhYMHYkVMdgtVwmNm0khpeCNCPH+4oNjNGoLAcVAOexbYUNHzZm6XETaMR C7FrP9WzDg/szI8dnzwhofS+lmilScUyZOebnmfvRq34T5cRBzzjDrpUvLQaDED+HjeDiLZo05J gMn5P3V0yq1okvuB/bUJt6gTDHVlevawvaYba2ASFg== X-Received: by 2002:a05:701b:2087:20b0:1b4:fa58:9d8 with SMTP id a92af1059eb24-1b5568e76a5mr35037035c88.20.1796103448508; Mon, 30 Nov 2026 21:37:28 -0800 (PST) Received: from penguin.lxd ([12.187.136.98]) by smtp.gmail.com with ESMTPSA id a92af1059eb24-1b5566c3052sm81183292c88.1.2026.11.30.21.37.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 21:37:27 -0800 (PST) From: "Kanchana P. Sridhar" To: hannes@cmpxchg.org, yosry@kernel.org, nphamcs@gmail.com, chengming.zhou@linux.dev, akpm@linux-foundation.org, linux-mm@kvack.org, herbert@gondor.apana.org.au, davem@davemloft.net, linux-crypto@vger.kernel.org, kanchanapsridhar2026@gmail.com, linux-kernel@vger.kernel.org Cc: rientjes@google.com, willy@infradead.org, senozhatsky@chromium.org Subject: [PATCH v5 4/9] crypto: acomp - Add API to get a compression algorithm's batch-size. Date: Mon, 30 Nov 2026 21:37:06 -0800 Message-Id: <20261201053711.8090-5-kanchanapsridhar2026@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20261201053711.8090-1-kanchanapsridhar2026@gmail.com> References: <20261201053711.8090-1-kanchanapsridhar2026@gmail.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit This commit adds a @batch_size data member to struct acomp_alg. An acomp_alg compression algorithm that supports batching of compressions and decompressions must provide a @batch_size greater than 1, representing the maximum batch-size that the compressor supports, so that kernel users of crypto_acomp, such as zswap, can allocate resources for submitting multiple compress/decompress jobs that can be batched, and invoke batching of [de]compressions. The new crypto_acomp_batch_size() API queries the crypto_acomp's acomp_alg for the batch-size. If the acomp_alg has registered a @batch_size greater than 1, this is returned. If not, a default of "1" is returned. zswap can invoke crypto_acomp_batch_size() to query the maximum number of requests that can be batch [de]compressed. Based on this, zswap can use the minimum of any zswap-specific upper limits for batch-size and the compressor's max @batch_size, to allocate batching resources. This enables zswap to compress/decompress multiple pages as a batch to improve swapout/swapin performance and memory savings. Signed-off-by: Kanchana P Sridhar Signed-off-by: Kanchana P. Sridhar --- crypto/acompress.c | 14 ++++++++++++++ include/crypto/acompress.h | 12 ++++++++++++ include/crypto/internal/acompress.h | 3 +++ 3 files changed, 29 insertions(+) diff --git a/crypto/acompress.c b/crypto/acompress.c index fb9672ebbe69..39be26891818 100644 --- a/crypto/acompress.c +++ b/crypto/acompress.c @@ -338,6 +338,20 @@ int crypto_acomp_decompress(struct acomp_req *req) } EXPORT_SYMBOL_GPL(crypto_acomp_decompress); +unsigned int crypto_acomp_batch_size(struct crypto_acomp *tfm) +{ + if (acomp_is_async(tfm) && + (crypto_comp_alg_common(tfm)->base.cra_type == &crypto_acomp_type)) { + struct acomp_alg *alg = crypto_acomp_alg(tfm); + + if (alg && alg->batch_size > 1) + return alg->batch_size; + } + + return 1; +} +EXPORT_SYMBOL_GPL(crypto_acomp_batch_size); + void comp_prepare_alg(struct comp_alg_common *alg) { struct crypto_alg *base = &alg->base; diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h index 93fa02ce818b..3ce4704dc879 100644 --- a/include/crypto/acompress.h +++ b/include/crypto/acompress.h @@ -593,6 +593,18 @@ int crypto_acomp_compress(struct acomp_req *req); */ int crypto_acomp_decompress(struct acomp_req *req); +/** + * crypto_acomp_batch_size() -- Get the algorithm's batch size + * + * Function returns the algorithm's batch size for batching operations + * + * @tfm: ACOMPRESS tfm handle allocated with crypto_alloc_acomp() + * + * Return: @tfm's acomp_alg's @batch_size, if it has defined a + * @batch_size greater than 1; else return 1. + */ +unsigned int crypto_acomp_batch_size(struct crypto_acomp *tfm); + static inline struct acomp_req *acomp_request_on_stack_init( char *buf, struct crypto_acomp *tfm) { diff --git a/include/crypto/internal/acompress.h b/include/crypto/internal/acompress.h index 0c0d3fc8a9fc..2d4d302d1b3f 100644 --- a/include/crypto/internal/acompress.h +++ b/include/crypto/internal/acompress.h @@ -28,6 +28,8 @@ * * @compress: Function performs a compress operation * @decompress: Function performs a de-compress operation + * @batch_size: Maximum batch-size for batching compress/decompress + * operations. * @init: Initialize the cryptographic transformation object. * This function is used to initialize the cryptographic * transformation object. This function is called only once at @@ -47,6 +49,7 @@ struct acomp_alg { int (*compress)(struct acomp_req *req); int (*decompress)(struct acomp_req *req); + unsigned int batch_size; int (*init)(struct crypto_acomp *tfm); void (*exit)(struct crypto_acomp *tfm); -- 2.39.5