From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.51 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796103445; b=sNEmKLoK6wmq3B5K2VI+BoKxPFZMIMdXOPcFJ2Radvwz++QMbXMtc0vGPdKfD086FL9q iqQFtwYuRgd11XuTXAv2M5kyuwupPzmiSIc+s8K7MFr8l8RJq6golUIyALMrEPRctSfAT +SO8un0rss0vFcm2eACvKLS1Y5i0Ws3WgwcyjOtJXeEJ5aQtCr5IFF6HDU/c7Iz0d0zbV 6QGvZ1UJx4K3Uz0zliIuuwyeInmTn6HVZibRNahh9yRw7hojkaL3SGe6MIacDlYMy67ZP zI4JvIbNuMdZpYDVlvTDuC+IelvzbcJl+VwM6zObeOYJ/hxbykya3yOSN2r7y7Of97A== 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=z3nYRHmLPXvm4LVFRd3qNDRxMy1oYj+Jow1JYA6BoCmnn4Tipq9OlvFWfZDTcjp2WZwX R6uMaVRoff0ojBeNTo0UThlzNi6OKDJdz51cSFTyHHaHdXIFr/sB5ztN5l53JvOdOZZBh DGdAtTR4XcRreNlUA/BgkZLBsJ08smEI6RN2wVNzYvgc5KqwV46Q8PQ/JHNuspDCpuwhA Q7tmBJDNegYu/BFiCKXgkipLbB+hz5SopY295aAEpveOEWKkreEfDVbsANhF6ajxGoqgN geJycH85i1WX72s09glZjiNmwTGw/bpTUJh1+VSTXv1+EZBJz/zjCWJQU0PNh3JzQ4g== 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.51 Received: from mail-dl1-f51.google.com (mail-dl1-f51.google.com [74.125.82.51]) (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 A3DA0606A325 for ; Tue, 1 Dec 2026 05:37:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org A3DA0606A325 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-f51.google.com with SMTP id a92af1059eb24-1b546061d58so1650319c88.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=qXLbNAhh/DQ2m0VaYE5yvi8UZ1DfPiYTc1JC9mVWQW0a2HSlFIeoVwCrR8NM/gUgNo nlXmu+0oVwmws0a51xNnyVsc1RdkEJE7lT2U5gML0fn/KX1qRPH37npH91UlsoV7MCCx alWRd6E+qKFl9M9Cia5KGEjJX/w/mSr1L7z4OFptSKznKWLVVYyPnFy7ehthBXA12me9 iK1CbTAjKLSVEPvLJbgvoOn322wi4+M7esSoIFe/Bmc7eASkDd45brkwGhzPnIChjU1d sfbU9A+ECu1Gb6mItmbOdm7RZnRrbmnP7egRw639qUTQw3QR9RClTejxm7ilCOxk5pEN HfpA== X-Forwarded-Encrypted: i=1; AL+hErGesn80kpd9cDEO7cy4kbypKALRvAs3HgfGBX8hV5pJZuU6Xv1QU+bbjOu0chjF27GPGa4eyNi18B07eto=@vger.kernel.org X-Gm-Message-State: APuU4Z8H7Hdecj8UmdhJ4Btgfo7W5ZT5LoQO6dBxPFRXLf+Y/Z4dSgA5 26dfdmZz9kYfA5tp2/3ex0XUhTUBz34r5+KvxVsGnOKTaHy+v8vE4gjn X-Gm-Gg: AZFdTZfnUSj+BbBEg74EE3BOaEuDw++93REZfMitaj+Qj3ak+O68Jo6NT0UK9b8fdBc vpQmNvixwHfHXdi/WcyDuOQIobJpiMZrZyl6oIgSFWNDUo8LvemwjLEkrRSlcpjG5usa0HQmboM S5TlZOc1R0UcM+4iEE9N4FfUiVQ/uRZZDMwlV5xMasRoJzw7dtr+ez+XgutXFmCMoNNRDOZLfKU KT86A2Q9uRoB24aPOOiUZV2Ld59808Lzbu0EqGnuA0oTsUNV+bvHqyG/xIGbmYkasII2iQW865U xlQ1wIStj7h3XazY3vmHhTS7EIansMUGSh2qN15EgDiacd6g2sWHluBjNuxTG/pEAu/YA5/OmK3 qTAHRvrK93fJwzhk1vjwt9FShQQ4s3d4kCZSASvfDc5E6QqONk5/bA75WZasvbHrCpGnp5WMVWF UH0TmegGDjrUMt/u6dYOjIw6w49JskfCgd5Tx6ZMdJMiZ5iQeA4JIyPfyKCNLw8lteAGCI9j8Nk 27HE5O9U2ZVHY/7CHN4OloSDOgJ7zIqoDWFAx2o1cmE/MRtb9u3OYijv6pLZdxid1P/UnNFK1B+ qrJDkxybKluMO70mUYle42+8rhyLySngCz6iBYpEkA== 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-crypto@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