From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.53 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796103445; b=u6ozE62My0oJYymU0DfNa9hASuIBmjwnOrTcmk5x4lPJAxbFNCHrUCY6qsT6DpuFSYFl r67SWOr19ZFtzVwkXnprRMTcDmfUvxrBQ60Ca0ubgK6TkT7sAHIvYBsR0+DlJi+rrxyzP xLTkQEBXMCXbQu8kJ8vkT0++fxaz97mRa0CrH+uvz6Y71Dn2sx0RbUQMdfBeATc5r3PNW QONVele65Bofe0+A3ORH4iQx39Po3mwzMSS87lwXOsYNkVwmOckpsZLypBKoY3JfeoCwX 8o34G0SaE8oxl4tGIOrYMOKiAsy5t+skwyvQfPsvKdFkNmIrPEKgHmuoJPoziz0AztA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796103445; 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=EegI3cdZx1bFhbbZNqPr4wp9LvzQ63sG0Fl3CUuMJsg=; b=aZdZkKfmTKI4V9b8zm522yytzn+umgmi4AAhLLqrsStnaqY/2Khx5xOnzTwEBs3UKWDO 0vbBR2fVT4cV+MoWxZZ7O75XLYHygovpQ4M45seoaEWMzemCEkrltpV1Rl+MbSMTJcrPd +f3XqfhpLkJhhamINbJaQUo8/SB3ZCmGOfC27pNo9DLVxEB2e5ZgQOP218TNnUwDJqbo3 PbHAwY1vO5OlhnULmq25UySMFjY9TxIshFNOWtcDO+56z9QrKvHsPZeJ7HYhxUvpUvW5c Voh9PO49e8dRzgDwnaVRW2Rdt+bhTUcoazq53rNmoHtrGsjWSqsn7EEAXZO4FFqfgZg== 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=FYOpTPqe; arc=none smtp.remote-ip=74.125.82.53 Received: from mail-dl1-f53.google.com (mail-dl1-f53.google.com [74.125.82.53]) (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 AEA3A606A327 for ; Tue, 1 Dec 2026 05:37:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org AEA3A606A327 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=FYOpTPqe Received: by mail-dl1-f53.google.com with SMTP id a92af1059eb24-1b546061d58so1650318c88.1 for ; Mon, 30 Nov 2026 21:37:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796103444; x=1796708244; 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=EegI3cdZx1bFhbbZNqPr4wp9LvzQ63sG0Fl3CUuMJsg=; b=FYOpTPqeZSV66vhgLbEDzm9dG2PYLPb/SOqOSU7by39xceoT4PPTQZFiPSoWmOhp1V YVpwieaPUEjzAT4UzcE96d1p45DJn3rsSpIgwHUMZsNwh28shfuZWy/+tsQRzDbT56W0 EiQuCYg4ZsUaFmbFO9dM7ruFugzYM+1mWhVwrbRxhY0HPq9cibBSPF8ADY1prIif48nU UWXnChAXa3tvRR9vDKrJixWQmEMD+80YIw9irAgXT59/Wm0V28jx7WsGFOSa2SHj7k/R FMwI0EY60I8Ybcbb18BSoBGAkMkBS/C4SLo1YcC1zIqOpSlrud8c+fT1X+tSWl2/GbaJ bmsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796103444; x=1796708244; 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=EegI3cdZx1bFhbbZNqPr4wp9LvzQ63sG0Fl3CUuMJsg=; b=dNAJ1s7PFL/8F1DniLKKnO7iouLX9sEpkCs49KGAPl36Z2W6w8FzmfjSmrROHtR0H7 2m084OE55X68JH/IYF+K/ZvbefbVuIm3rtdxLqnpXpDOdxKo4DZo8MqElAbK/p3pCxue m/iK8o83WiJNhmDB3xPmJuoTiDhRSXaoRivURoA4QsKX9hWC8YjJ0UEBrebX4VpvitP0 gqQcLHoXlrclQz+MWrhsk6+HcOPb0EJMibX29hqurNVd4ces7xsqfjIxLI7hNWg0C1rj N9VhT1t78jU0ldIsXXXxio+1q+hLLEimgROquDRKU0RNx1iWSzU9uRF6cqiEaAOwx3eL pzeQ== X-Forwarded-Encrypted: i=1; AL+hErGveMoV0+4LDYVaXZuDfkBFzdo1wx6ksGJJasPjNSulT/1CI0uXehpL/pPd3WWzVULa85e9AhOgArIe1rE=@vger.kernel.org X-Gm-Message-State: APuU4Z+Rpc88z+0e83gZbxO5nnq3DvFwjfM5OGlm6uLJOp20cDA8fa4m GVPXQ5NDVxkYnC7pMdXQB3iq6e5KFjux84lBa7OR3SerpIKSDx0lJK/k X-Gm-Gg: AZFdTZdAIWq8n8PuJnJV2CTbl3NBxKv/QbvLJK0KHyu7n3afGpAIhKr7iZ3Vz9s02DV TZxAhi/x57u8D11lO8PEv5aktFQtxIRmUQTuhGpYNDaH+6Csle9CyGiQ82xJZDnZSUQ/o9u8rWH 6u9pM0AIhLyH/GyGNHl1O630grHNzYnWF6sVlJRdahs7sKFT+LfeZzt8HVrhSq/ucmsPQismhlU JIvcejzdebu4FjsYxF3iRnl/xzn6zGP3aEBJGynH67Uzny8ShYRwkH4hj3r0SewsX9tKm+wcmbm A0QwN9oMie95Z7PoBaM+FXC81DQUMNlSzfZxZ2mx0cbyaA3hQKKF3Z/udx38sGVM+qkw6nivIcc L9JGM+HuFJCFh40TLqYXjGTmpEl90lHROZBr0reCXZCQ/K/1T8cheHGZoSjZaiPGt+YyurnbdNj 9NEPoQS0rQiFna2Nc48JgR0NGUGFkfFmOHH5xTQ/Axj3ij1uTPlwOeLRRbBjdx3hW8qMPuSn8jg +FQuEYlaCt3+3l6IB2fPZKQrUhzGFAJ0QDNlM71IOrTgMrTGbFkmrXTNO9PjTs0cVLav11C/zMC RKJrYRr6Lz4qKPegzQOMpGv4bNJ7jb2iJFPPYPfEMg== X-Received: by 2002:a05:701b:2902:b0:1b5:8a69:cc65 with SMTP id a92af1059eb24-1b58a69efddmr16829785c88.4.1796103443746; Mon, 30 Nov 2026 21:37:23 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 21:37:23 -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 1/9] crypto: acomp - Define a unit_size in struct acomp_req to enable batching. mm: zswap: Set the unit size for zswap to PAGE_SIZE. Date: Mon, 30 Nov 2026 21:37:03 -0800 Message-Id: <20261201053711.8090-2-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 We add a new @unit_size data member to struct acomp_req along with a helper function acomp_request_set_unit_size() for kernel modules to set the unit size to use while breaking down the request's src/dst scatterlists. An acomp_alg can implement batching by using the @req->unit_size to break down the SG lists passed in via @req->dst and/or @req->src, to submit individual @req->slen/@req->unit_size compress jobs or @req->dlen/@req->unit_size decompress jobs, for batch compression and batch decompression respectively. In case of batch compression, the folio's pages for the batch can be retrieved from the @req->src scatterlist by using a struct sg_page_iter after determining the number of pages as @req->slen/@req->unit_size. Please note that acomp_request_set_callback() sets the @req->unit_size to 0. In zswap_acomp_req_init(), after the call to zswap_set_acomp_req_callback(), we set the unit size for zswap to PAGE_SIZE. acomp_request_set_unit_size(areq->req, PAGE_SIZE); Suggested-by: Herbert Xu Co-developed-by: Herbert Xu Signed-off-by: Herbert Xu Signed-off-by: Kanchana P Sridhar Signed-off-by: Kanchana P. Sridhar --- include/crypto/acompress.h | 49 ++++++++++++++++++++++++++++++++++++++ mm/zswap.c | 6 +++++ 2 files changed, 55 insertions(+) diff --git a/include/crypto/acompress.h b/include/crypto/acompress.h index 5d5358dfab73..6462fc46f4ec 100644 --- a/include/crypto/acompress.h +++ b/include/crypto/acompress.h @@ -79,6 +79,7 @@ struct acomp_req_chain { * @dvirt: Destination virtual address * @slen: Size of the input buffer * @dlen: Size of the output buffer and number of bytes produced + * @unit_size: Unit size for the request for use in batching * @chain: Private API code data, do not use * @__ctx: Start of private context data */ @@ -94,6 +95,7 @@ struct acomp_req { }; unsigned int slen; unsigned int dlen; + unsigned int unit_size; struct acomp_req_chain chain; @@ -329,9 +331,56 @@ static inline void acomp_request_set_callback(struct acomp_req *req, { flgs &= ~CRYPTO_ACOMP_REQ_PRIVATE; flgs |= req->base.flags & CRYPTO_ACOMP_REQ_PRIVATE; + req->unit_size = 0; crypto_request_set_callback(&req->base, flgs, cmpl, data); } +/** + * acomp_request_set_unit_size() -- Sets the unit size for the request. + * + * This is a helper function that enables batching for zswap, IPComp, etc. + * It allows multiple independent compression (or decompression) operations to + * be submitted in a single request's SG lists, where each SG list ("segment") + * is processed independently. The unit size helps derive segments from a + * single request. crypto_acomp does not expect the segments to be related in + * any way. + * + * Example usage model: + * + * A module such as zswap that's configured to use a batching compressor, can + * accomplish batch compression of "nr_pages" with crypto_acomp by creating an + * output SG table for the batch, initialized to contain "nr_pages" SG + * lists. Each scatterlist is mapped to the nth destination buffer for the + * batch. Depending on whether the @req is used for batch compress/decompress, + * zswap must set the @req's source/destination length to be + * "nr_pages * @req->unit_size" respectively. + * + * An acomp_alg can implement batch compression by using the @req->unit_size + * to break down the SG lists passed in via @req->dst to submit individual + * "@req->slen/@req->unit_size" compress jobs to be processed as a batch. + * + * Similarly, zswap can implement batch decompression by passing an + * SG table with "nr_pages" SG lists via @req->src to process + * "@req->dlen/@req->unit_size" decompress jobs as a batch. + * + * This API must be called after acomp_request_set_callback(), + * which sets @req->unit_size to 0. This makes it easy for users of + * crypto_acomp to rely on a default of not opting in to batching. + * Users such as zswap opt in to batching by defining @req->unit_size + * to a non-zero value for use by acomp_algs supporting batching. + * + * @du would be PAGE_SIZE for zswap, it could be the MTU for IPsec. + * + * @req: asynchronous compress/decompress request + * @du: data unit size of the input/output buffer scatterlist. + */ +static inline void acomp_request_set_unit_size(struct acomp_req *req, + unsigned int du) +{ + req->unit_size = du; +} + + /** * acomp_request_set_params() -- Sets request parameters * diff --git a/mm/zswap.c b/mm/zswap.c index 6a66b898ab47..9ee20b576eff 100644 --- a/mm/zswap.c +++ b/mm/zswap.c @@ -829,6 +829,12 @@ static int zswap_acomp_req_init(struct zswap_acomp_req *areq, crypto_init_wait(&areq->wait); zswap_set_acomp_req_callback(areq->req, &areq->wait); + /* + * This should be called after acomp_request_set_callback(), + * which initializes req->unit_size to 0. + */ + acomp_request_set_unit_size(areq->req, PAGE_SIZE); + mutex_init(&areq->mutex); return 0; } -- 2.39.5