crypto: acomp - Add segmentation API for compression
Herbert Xu
maintainercover crypto: acomp - Add segmentation API for compression
This patch adds segmentation support for compression and provides a wrapper for existing algorithms so that they can accept a single segment while returning the compressed length or error through the dst SG list length.
Herbert Xu (2):
crypto: acomp - Add bit to indicate segmentation support
crypto: acomp - Add trivial segmentation wrapper
Kanchana P Sridhar (1):
crypto: acomp - Define a unit_size in struct acomp_req to enable
batching.
crypto/acompress.c | 25 ++++++++++++++++--- include/crypto/acompress.h | 37 +++++++++++++++++++++++++++++ include/crypto/algapi.h | 5 ++++ include/crypto/internal/acompress.h | 5 ++++ include/linux/crypto.h | 3 +++ 5 files changed, 72 insertions(+), 3 deletions(-)
Signature · 1 line
2.47.3
Herbert Xu
maintainerPATCH 1/3 crypto: acomp - Define a unit_size in struct acomp_req to enable batching.
From: Kanchana P Sridhar <[email protected]>
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 an struct sg_page_iter after determining the number of pages as @req->slen/@req->unit_size.
--- include/crypto/acompress.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
include/crypto/acompress.h +36 -0
@@ -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;
@@ -328,9 +330,43 @@ 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. +* +* As suggested by Herbert Xu, this is a new helper function that enables +* batching for zswap, IPComp, etc. +* +* Example usage model: +* +* A module like zswap that wants to use batch compression of @nr_pages with +* crypto_acomp must create 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. +* +* 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. +* +* This API must be called after acomp_request_set_callback(), +* which sets @req->unit_size to 0. +* +* @du would be PAGE_SIZE for zswap, it could be the MTU for IPsec. +* +* @req: asynchronous compress request +* @du: data unit size of the input 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 *
Signature · 1 line
2.47.3
Re: [PATCH 1/3] crypto: acomp - Define a unit_size in struct acomp_req to enable batching.
Quoted 13 lines · Herbert Xu
From: Kanchana P Sridhar <[email protected]>
We add a new @unit_size data member to struct
acomp_reqalong with a helper functionacomp_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_algcan 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.
Quoted 8 lines
In case of batch compression, the folio's pages for the batch can be retrieved from the @req->src scatterlist by using an struct
sg_page_iterafter determining the number of pages as @req->slen/@req->unit_size.Suggested-by Herbert Xu <[email protected]>Signed-off-by Kanchana P Sridhar <[email protected]>Signed-off-by Herbert Xu <[email protected]>---
A few comments below.
include/crypto/acompress.h struct acomp_req_chain { · line 82
Quoted 12 lines
include/crypto/acompress.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)include/crypto/acompress.h +1
-0@@ -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
NIT: use a tab after the colon for consistency with the other fields.
Quoted 14 lines
include/crypto/acompress.h +1
-0* @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;@@ -328,9 +330,43 @@ static inline void acomp_request_set_callback(struct acomp_req *req, { flgs &= ~CRYPTO_ACOMP_REQ_PRIVATE ;
include/crypto/acompress.h static inline void acomp_request_set_callback(struct acomp_req *req, · line 341
Quoted 10 lines
include/crypto/acompress.h +6
-0flgs |= 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. +* +* As suggested by Herbert Xu, this is a new helper function that enables +* batching for zswap, IPComp, etc.
This sentence should be removed. We shouldn't be mentioning on the documentation that this function is new or who suggested the change.
Instead, explain what batching actually means in this context: that it allows multiple independent compression (or decompression) operations to be submitted in a single request, where each segment is processed independently. It would also be helpful to clarify that each unit has the same size for source and destination, and that each segment must be physically contiguous, if that is the case.
include/crypto/acompress.h static inline void acomp_request_set_callback(struct acomp_req *req, · line 345
Quoted 4 lines
include/crypto/acompress.h +4
-0+* +* Example usage model: +* +* A module like zswap that wants to use batch compression of @nr_pages with
Pages or folios?
Also, @nr_pages is not a parameter of this function. Is the usage of @ correct?
include/crypto/acompress.h static inline void acomp_request_set_callback(struct acomp_req *req, · line 357
Quoted 12 lines
include/crypto/acompress.h +12
-0+* crypto_acomp must create 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. +* +* 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. +* +* This API must be called after acomp_request_set_callback(), +* which sets @req->unit_size to 0.
This mentions a constraint, but does not explain why. Explain why this restriction is needed.
Quoted 18 lines
include/crypto/acompress.h +12
-0+* +* @du would be PAGE_SIZE for zswap, it could be the MTU for IPsec. +* +* @req: asynchronous compress request +* @du: data unit size of the input 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 * Signature · 1 line
2.47.3
Thanks,
Signature · 1 line
Giovanni
RE: [PATCH 1/3] crypto: acomp - Define a unit_size in struct acomp_req to enable batching.
Quoted 29 lines
-----Original Message-----
From: Cabiddu, Giovanni <[email protected]>
Sent: Monday, December 29, 2025 3:07 AM
To: Herbert Xu <[email protected]>
Cc: Linux Crypto Mailing List <[email protected]>; [email protected]; [email protected]; [email protected]; Sridhar, Kanchana P <[email protected]>
Subject: Re: [PATCH 1/3] crypto: acomp - Define aunit_sizein structacomp_reqto enable batching.Quoted 17 lines · Herbert Xu
From: Kanchana P Sridhar <[email protected]>
We add a new @unit_size data member to struct
acomp_reqalong with a helper functionacomp_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_algcan 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 an struct
sg_page_iterafter determining the number of pages as @req->slen/@req->unit_size.
Quoted 6 lines
Quoted 4 lines
Suggested-by Herbert Xu <[email protected]>Signed-off-by Kanchana P Sridhar <[email protected]>Signed-off-by Herbert Xu <[email protected]>---
A few comments below.
Hi Giovanni,
Thanks for the code review comments.
Quoted 5 lines
Quoted 2 lines
include/crypto/acompress.h | 36++++++++++++++++++++++++++++++++++++
Quoted 2 lines
1 file changed, 36 insertions(+)
Quoted 10 lines
include/crypto/acompress.h struct acomp_req_chain { · line 82
Quoted 9 lines
include/crypto/acompress.h +1
-0@@ -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 NIT: use a tab after the colon for consistency with the other fields.
Sure.
Quoted 21 lines
include/crypto/acompress.h static inline void
Quoted 13 lines
include/crypto/acompress.h +1
-0* @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;@@ -328,9 +330,43 @@ static inline voidacomp_request_set_callback(struct
acomp_req*req,Quoted 7 lines
include/crypto/acompress.h +1
-0{ 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); }
Quoted 7 lines
include/crypto/acompress.h static inline void acomp_request_set_callback(struct acomp_req *req, · line 341
Quoted 5 lines
include/crypto/acompress.h +5
-0+/** +* acomp_request_set_unit_size() -- Sets the unit size for the request. +* +* As suggested by Herbert Xu, this is a new helper function that enables +* batching for zswap, IPComp, etc. This sentence should be removed. We shouldn't be mentioning on the documentation that this function is new or who suggested the change.
Sounds good.
Quoted 7 lines
Instead, explain what batching actually means in this context: that it allows multiple independent compression (or decompression) operations to be submitted in a single request, where each segment is processed independently. It would also be helpful to clarify that each unit has the same size for source and destination, and that each segment must be physically contiguous, if that is the case.
Ok, I will add the appropriate explanations in this context.
Thanks,
Kanchana
Quoted 50 lines
include/crypto/acompress.h static inline void acomp_request_set_callback(struct acomp_req *req,
Quoted 5 lines
include/crypto/acompress.h +4
-0+* +* Example usage model: +* +* A module like zswap that wants to use batch compression of @nr_pages with
Pages or folios?Also, @nr_pages is not a parameter of this function. Is the usage of
@correct?include/crypto/acompress.h static inline void · line 346
Quoted 1 line
include/crypto/acompress.h +1
-0+* crypto_acomp must create an output SG table for the batch, initialized to
include/crypto/acompress.h static inline void acomp_request_set_callback(struct acomp_req *req,
Quoted 7 lines
include/crypto/acompress.h +7
-0+* contain @nr_pages SG lists. Each scatterlist is mapped to the nth +* destination buffer for the batch. +* +* 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
include/crypto/acompress.h static inline void acomp_request_set_callback(struct acomp_req *req, · line 357
Quoted 4 lines
include/crypto/acompress.h +4
-0+* batch decompression respectively. +* +* This API must be called after acomp_request_set_callback(), +* which sets @req->unit_size to 0. This mentions a constraint, but does not explain why. Explain why this restriction is needed.
Quoted 16 lines
include/crypto/acompress.h +12
-1+* +* @du would be PAGE_SIZE for zswap, it could be the MTU for IPsec. +* +* @req: asynchronous compress request +* @du: data unit size of the input 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 * -- Quoted 2 lines
2.47.3
Thanks,
--
Giovanni
Herbert Xu
maintainerPATCH 2/3 crypto: acomp - Add bit to indicate segmentation support
In reply to Herbert XuAdd a bit to the crypto_alg flags to indicate support for segmentation. Also add a helper for acomp to test whether a given tfm supports segmentation.
--- include/crypto/algapi.h | 5 +++++ include/crypto/internal/acompress.h | 5 +++++ include/linux/crypto.h | 3 +++ 3 files changed, 13 insertions(+)
include/crypto/algapi.h +5 -0
@@ -280,6 +280,11 @@ static inline bool crypto_tfm_req_virt(struct crypto_tfm *tfm)return tfm->__crt_alg->cra_flags &CRYPTO_ALG_REQ_VIRT ; } +static inline bool crypto_tfm_req_seg (struct crypto_tfm *tfm) +{ +return tfm->__crt_alg->cra_flags &CRYPTO_ALG_REQ_SEG ; +} +static inline u32 crypto_request_flags (struct crypto_async_request *req) {return req->flags & ~CRYPTO_TFM_REQ_ON_STACK ;
include/crypto/internal/acompress.h +5 -0
@@ -188,6 +188,11 @@ static inline bool crypto_acomp_req_virt(struct crypto_acomp *tfm)return crypto_tfm_req_virt (&tfm->base); } +static inline bool crypto_acomp_req_seg (struct crypto_acomp *tfm) +{ +return crypto_tfm_req_seg (&tfm->base); +} +void crypto_acomp_free_streams (struct crypto_acomp_streams *s);int crypto_acomp_alloc_streams (struct crypto_acomp_streams *s);
include/linux/crypto.h +3 -0
@@ -139,6 +139,9 @@/* Set if the algorithm cannot have a fallback (e.g., phmac). */ #define CRYPTO_ALG_NO_FALLBACK 0x00080000 +/* Set if the algorithm supports segmentation. */ +#define CRYPTO_ALG_REQ_SEG 0x00100000 +/* The high bits 0xff000000 are reserved for type-specific flags. */ /*
Signature · 1 line
2.47.3
Herbert Xu
maintainerPATCH 3/3 crypto: acomp - Add trivial segmentation wrapper
In reply to Herbert XuAdd a trivial segmentation wrapper that only supports compression with a segment count of exactly one.
The reason is that the first user zswap will only allocate the extra memory if the underlying algorithm supports segmentation, and otherwise only one segment will be given at a time.
Having this wrapper means that the same calling convention can be used for all algorithms, regardless of segmentation support.
--- crypto/acompress.c | 25 ++++++++++++++++++++++--- include/crypto/acompress.h | 1 + 2 files changed, 23 insertions(+), 3 deletions(-)
crypto/acompress.c +22 -3
@@ -170,8 +170,13 @@ static void acomp_save_req(struct acomp_req *req, crypto_completion_t cplt) state->compl = req->base.complete; state->data = req->base.data; + state->unit_size = req->unit_size; + state->flags = req->base.flags & (CRYPTO_ACOMP_REQ_SRC_VIRT | +CRYPTO_ACOMP_REQ_DST_VIRT ); + req->base.complete = cplt; req->base.data = state; + req->unit_size =0 ; }static void acomp_restore_req (struct acomp_req *req)
@@ -180,6 +185,7 @@ static void acomp_restore_req(struct acomp_req *req) req->base.complete = state->compl; req->base.data = state->data; + req->unit_size = state->unit_size; }static void acomp_reqchain_virt (struct acomp_req *req)
@@ -198,9 +204,6 @@ static void acomp_virt_to_sg(struct acomp_req *req) {struct acomp_req_chain *state = &req->chain; - state->flags = req->base.flags & (CRYPTO_ACOMP_REQ_SRC_VIRT | -CRYPTO_ACOMP_REQ_DST_VIRT ); -if (acomp_request_src_isvirt (req)) {unsigned int slen = req->slen;const u8 *svirt = req->svirt;
@@ -248,6 +251,10 @@ static int acomp_reqchain_finish(struct acomp_req *req, int err) {acomp_reqchain_virt (req);acomp_restore_req (req); + +if (req->unit_size) + req->dst->length = err ?: req->dlen; +return err; }
@@ -272,6 +279,9 @@ static int acomp_do_req_chain(struct acomp_req *req, bool comp) {int err; +if (req->unit_size && req->slen > req->unit_size) +return -ENOSYS ; +acomp_save_req (req, acomp_reqchain_done); err =acomp_do_one_req (req, comp);
@@ -287,6 +297,13 @@ int crypto_acomp_compress(struct acomp_req *req)if (acomp_req_on_stack (req) &&acomp_is_async (tfm))return -EAGAIN ; +if (req->unit_size) { +if (!acomp_request_issg (req)) +return -EINVAL ; +if (crypto_acomp_req_seg (tfm)) +return crypto_acomp_reqtfm (req)->compress (req); +return acomp_do_req_chain (req, true); + }if (crypto_acomp_req_virt (tfm) ||acomp_request_issg (req))return crypto_acomp_reqtfm (req)->compress (req);return acomp_do_req_chain (req, true);
@@ -299,6 +316,8 @@ int crypto_acomp_decompress(struct acomp_req *req)if (acomp_req_on_stack (req) &&acomp_is_async (tfm))return -EAGAIN ; +if (req->unit_size) +return -ENOSYS ;if (crypto_acomp_req_virt (tfm) ||acomp_request_issg (req))return crypto_acomp_reqtfm (req)->decompress (req);return acomp_do_req_chain (req, false);
include/crypto/acompress.h +1 -0
@@ -67,6 +67,7 @@ struct acomp_req_chain {struct folio *dfolio; };u32 flags; +u32 unit_size; };/**
Signature · 1 line
2.47.3
RE: [PATCH 3/3] crypto: acomp - Add trivial segmentation wrapper
Quoted 89 lines
-----Original Message-----
From: Herbert Xu <[email protected]>
Sent: Thursday, December 25, 2025 4:38 PM
To: Linux Crypto Mailing List <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Sridhar, Kanchana P <[email protected]>
Subject: [PATCH 3/3] crypto: acomp - Add trivial segmentation wrapperAdd a trivial segmentation wrapper that only supports compression with a segment count of exactly one.
The reason is that the first user zswap will only allocate the extra memory if the underlying algorithm supports segmentation, and otherwise only one segment will be given at a time.
Having this wrapper means that the same calling convention can be used for all algorithms, regardless of segmentation support.
Signed-off-by Herbert Xu <[email protected]>--- crypto/acompress.c | 25 ++++++++++++++++++++++--- include/crypto/acompress.h | 1 + 2 files changed, 23 insertions(+), 3 deletions(-)crypto/acompress.c +5
-0@@ -170,8 +170,13 @@ static void acomp_save_req(struct acomp_req *req, crypto_completion_t cplt) state->compl = req->base.complete; state->data = req->base.data; + state->unit_size = req->unit_size; + state->flags = req->base.flags & (CRYPTO_ACOMP_REQ_SRC_VIRT | +CRYPTO_ACOMP_REQ_DST_VIRT ); + req->base.complete = cplt; req->base.data = state; + req->unit_size =0 ; }static void
acomp_restore_req(struct acomp_req *req)crypto/acompress.c +1
-0@@ -180,6 +185,7 @@ static void acomp_restore_req(struct acomp_req *req) req->base.complete = state->compl; req->base.data = state->data; + req->unit_size = state->unit_size; }static void
acomp_reqchain_virt(struct acomp_req *req)crypto/acompress.c +7
-3@@ -198,9 +204,6 @@ static void acomp_virt_to_sg(struct acomp_req *req) {struct acomp_req_chain *state = &req->chain; - state->flags = req->base.flags & (CRYPTO_ACOMP_REQ_SRC_VIRT | -CRYPTO_ACOMP_REQ_DST_VIRT ); -if (acomp_request_src_isvirt (req)) {unsigned int slen = req->slen;const u8 *svirt = req->svirt;@@ -248,6 +251,10 @@ static int acomp_reqchain_finish(struct acomp_req *req, int err) {acomp_reqchain_virt (req);acomp_restore_req (req); + +if (req->unit_size) + req->dst->length = err ?: req->dlen; +return err; }@@ -272,6 +279,9 @@ static int acomp_do_req_chain(struct acomp_req *req, bool comp) {int err; +if (req->unit_size && req->slen > req->unit_size) +return -ENOSYS ; +acomp_save_req (req, acomp_reqchain_done);crypto/acompress.c +0
-0err =acomp_do_one_req (req, comp);@@ -287,6 +297,13 @@ int crypto_acomp_compress(struct acomp_req *req)
crypto/acompress.c int crypto_acomp_compress(struct acomp_req · line 307
Quoted 10 lines
crypto/acompress.c +7
-0if (acomp_req_on_stack (req) &&acomp_is_async (tfm))return -EAGAIN ; +if (req->unit_size) { +if (!acomp_request_issg (req)) +return -EINVAL ; +if (crypto_acomp_req_seg (tfm)) +return crypto_acomp_reqtfm (req)->compress (req); +return acomp_do_req_chain (req, true); + }
Happy New Year to everyone!
Hi Herbert,
Thanks for the segmentation patches. I have integrated the changes with my latest v14 patch-set I have been working on that incorporates the rest of the comments. I had to re-organize the structure of crypto_acomp_compress() to make sure that performance does not regress as a result of the 3 additional conditionals introduced. I also had to inline acomp_do_req_chain() to not regress usemem/zstd performance with PMD folios due to the added computes.
crypto/acompress.c int crypto_acomp_decompress(struct acomp_req · line 321
Quoted 10 lines
crypto/acompress.c +0
-0if (crypto_acomp_req_virt (tfm) ||acomp_request_issg (req))return crypto_acomp_reqtfm (req)->compress (req);crypto/acompress.c +2
-0return acomp_do_req_chain (req, true);@@ -299,6 +316,8 @@ int crypto_acomp_decompress(struct acomp_req *req)if (acomp_req_on_stack (req) &&acomp_is_async (tfm))return -EAGAIN ; +if (req->unit_size) +return -ENOSYS ;
In order to be able to use the same zswap per-CPU acomp_req for compressions and decompressions, I kept crypto_acomp_decompress() unchanged and to not flag an error "if (req->unit_size)" for now. Besides, the added conditional impacts performance for the workloads that I have been using (usemem, kernel_compilation)
I wanted to share these updates and get your thoughts. If the above proposed changes from my integration sound Ok, can you please let me know if I can include your patches in v14, or if you would prefer the segmentation patch-set is accepted that I can then rebase to?
Thanks,
Kanchana
Quoted 17 lines
crypto/acompress.c +0
-0if (crypto_acomp_req_virt (tfm) ||acomp_request_issg (req))return crypto_acomp_reqtfm (req)->decompress (req);crypto/acompress.c +0
-0return acomp_do_req_chain (req, false);include/crypto/acompress.h +1
-1@@ -67,6 +67,7 @@ struct acomp_req_chain {struct folio *dfolio; };u32 flags; +u32 unit_size; };/** -- 2.47.3
RE: [PATCH 3/3] crypto: acomp - Add trivial segmentation wrapper
Quoted 144 lines
-----Original Message-----
From: Sridhar, Kanchana P <[email protected]>
Sent: Tuesday, January 6, 2026 8:27 PM
To: Herbert Xu <[email protected]>; Linux Crypto Mailing List <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Sridhar, Kanchana P <[email protected]>
Subject: RE: [PATCH 3/3] crypto: acomp - Add trivial segmentation wrappercrypto/acompress.c static void acomp_save_req(struct acomp_req
Quoted 30 lines
-----Original Message-----
From: Herbert Xu <[email protected]>
Sent: Thursday, December 25, 2025 4:38 PM
To: Linux Crypto Mailing List <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; Sridhar, Kanchana P <[email protected]>
Subject: [PATCH 3/3] crypto: acomp - Add trivial segmentation wrapperAdd a trivial segmentation wrapper that only supports compression with a segment count of exactly one.
The reason is that the first user zswap will only allocate the extra memory if the underlying algorithm supports segmentation, and otherwise only one segment will be given at a time.
Having this wrapper means that the same calling convention can be used for all algorithms, regardless of segmentation support.
Signed-off-by Herbert Xu <[email protected]>--- crypto/acompress.c | 25 ++++++++++++++++++++++--- include/crypto/acompress.h | 1 + 2 files changed, 23 insertions(+), 3 deletions(-)crypto/acompress.c +0
-0@@ -170,8 +170,13 @@ static void acomp_save_req(struct acomp_req*req,
crypto/acompress.c static void acomp_virt_to_sg(struct acomp_req
Quoted 24 lines
crypto/acompress.c +5
-0crypto_completion_t cplt) state->compl = req->base.complete; state->data = req->base.data; + state->unit_size = req->unit_size; + state->flags = req->base.flags & (CRYPTO_ACOMP_REQ_SRC_VIRT | +CRYPTO_ACOMP_REQ_DST_VIRT ); + req->base.complete = cplt; req->base.data = state; + req->unit_size =0 ; }static void
acomp_restore_req(struct acomp_req *req)crypto/acompress.c +1
-0@@ -180,6 +185,7 @@ static void acomp_restore_req(struct acomp_req *req) req->base.complete = state->compl; req->base.data = state->data; + req->unit_size = state->unit_size; }static void
acomp_reqchain_virt(struct acomp_req *req)crypto/acompress.c +0
-0@@ -198,9 +204,6 @@ static void acomp_virt_to_sg(struct acomp_req*req)
crypto/acompress.c static int acomp_reqchain_finish(struct
Quoted 10 lines
crypto/acompress.c +0
-3{struct acomp_req_chain *state = &req->chain; - state->flags = req->base.flags & (CRYPTO_ACOMP_REQ_SRC_VIRT | -CRYPTO_ACOMP_REQ_DST_VIRT ); -if (acomp_request_src_isvirt (req)) {unsigned int slen = req->slen;const u8 *svirt = req->svirt;@@ -248,6 +251,10 @@ static int acomp_reqchain_finish(struct
acomp_reqQuoted 24 lines
crypto/acompress.c +7
-0*req, int err) {acomp_reqchain_virt (req);acomp_restore_req (req); + +if (req->unit_size) + req->dst->length = err ?: req->dlen; +return err; }@@ -272,6 +279,9 @@ static int acomp_do_req_chain(struct acomp_req *req, bool comp) {int err; +if (req->unit_size && req->slen > req->unit_size) +return -ENOSYS ; +acomp_save_req (req, acomp_reqchain_done);crypto/acompress.c +0
-0err =acomp_do_one_req (req, comp);@@ -287,6 +297,13 @@ int crypto_acomp_compress(struct acomp_req *req)crypto/acompress.c int crypto_acomp_compress(struct acomp_req · line 307
Quoted 10 lines
crypto/acompress.c +7
-0if (acomp_req_on_stack (req) &&acomp_is_async (tfm))return -EAGAIN ; +if (req->unit_size) { +if (!acomp_request_issg (req)) +return -EINVAL ; +if (crypto_acomp_req_seg (tfm)) +return crypto_acomp_reqtfm (req)->compress (req); +return acomp_do_req_chain (req, true); + }Happy New Year to everyone!
Hi Herbert,
Thanks for the segmentation patches. I have integrated the changes with my latest v14 patch-set I have been working on that incorporates the rest of the comments. I had to re-organize the structure of
crypto_acomp_compress()to make sure that performance does not regress as a result of the 3 additional conditionals introduced. I also had to inlineacomp_do_req_chain()to not regress usemem/zstd performance with PMD folios due to the added computes.crypto/acompress.c int crypto_acomp_decompress(struct acomp_req · line 321
Quoted 10 lines
crypto/acompress.c +0
-0if (crypto_acomp_req_virt (tfm) ||acomp_request_issg (req))return crypto_acomp_reqtfm (req)->compress (req);crypto/acompress.c +2
-0return acomp_do_req_chain (req, true);@@ -299,6 +316,8 @@ int crypto_acomp_decompress(struct acomp_req *req)if (acomp_req_on_stack (req) &&acomp_is_async (tfm))return -EAGAIN ; +if (req->unit_size) +return -ENOSYS ;In order to be able to use the same zswap per-CPU
acomp_reqfor compressions
and decompressions, I keptcrypto_acomp_decompress()unchanged and to not flag an error "if (req->unit_size)" for now. Besides, the added conditional impacts performance for the workloads that I have been using (usemem,kernel_compilation)
Quoted 4 lines
I wanted to share these updates and get your thoughts. If the above proposed changes from my integration sound Ok, can you please let me know if I can include your patches in v14, or if you would prefer the segmentation patch-set is accepted that I can then rebase to?
Hi Herbert,
Just wanted to follow up and get your suggestions on whether I should go ahead with incorporating the segmentation API patches into v14 of my zswap compression batching patch series, with the changes I had to make, as described earlier? I would appreciate your letting me know.
Thanks,
Kanchana
Quoted 21 lines
Thanks,
KanchanaQuoted 17 lines
crypto/acompress.c +0
-0if (crypto_acomp_req_virt (tfm) ||acomp_request_issg (req))return crypto_acomp_reqtfm (req)->decompress (req);crypto/acompress.c +0
-0return acomp_do_req_chain (req, false);include/crypto/acompress.h +1
-1@@ -67,6 +67,7 @@ struct acomp_req_chain {struct folio *dfolio; };u32 flags; +u32 unit_size; };/** -- 2.47.3
Herbert Xu
maintainerRe: [PATCH 3/3] crypto: acomp - Add trivial segmentation wrapper
Quoted 5 lines · Kanchana P
Just wanted to follow up and get your suggestions on whether I should go ahead with incorporating the segmentation API patches into v14 of my zswap compression batching patch series, with the changes I had to make, as described earlier? I would appreciate your letting me know.
Yes let's go ahead with your changes. Thanks,
Signature · 3 lines
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
RE: [PATCH 3/3] crypto: acomp - Add trivial segmentation wrapper
Quoted 12 lines
-----Original Message-----
From: Herbert Xu <[email protected]>
Sent: Tuesday, January 13, 2026 9:06 PM
To: Sridhar, Kanchana P <[email protected]>
Cc: Linux Crypto Mailing List <[email protected]>; [email protected]; [email protected]; [email protected]; Feghali, Wajdi K <[email protected]>
Subject: Re: [PATCH 3/3] crypto: acomp - Add trivial segmentation wrapperQuoted 1 line · Kanchana P
Quoted 8 lines
Quoted 2 lines
Just wanted to follow up and get your suggestions on whether I should go ahead with incorporating the segmentation API patches into v14 of my
zswap
Quoted 1 line
compression batching patch series, with the changes I had to make, as
described
Quoted 1 line
earlier? I would appreciate your letting me know.
Yes let's go ahead with your changes. Thanks,
Thanks Herbert, this sounds good.
Best regards,
Kanchana
Quoted 4 lines
--
Email: Herbert Xu <[email protected]> Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt