Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[linux] Expose ZSTD_compressSequences*() in the kernel #4260

Merged
merged 1 commit into from
Jan 27, 2025

Conversation

gcabiddu
Copy link
Contributor

Make the functions ZSTD_compressSequences(), ZSTD_compressSequencesAndLiterals() and ZSTD_CCtx_setParameter() available in kernel space.
These will be used in future by the Intel QAT driver.

Note that:

  • ZSTD_compressSequencesAndLiterals() is sufficient for QAT. We could just expose that function and not ZSTD_compressSequences().
  • In order for the kernel to compile in contrib/linux-kernel/mem.h, #include <asm/unaligned.h> should be replaced with #include <linux/unaligned.h>. I haven't made that change yet as it was causing some regressions in the tests.

@Cyan4973
Copy link
Contributor

Looks good to me,
cc @terrelln since it's kernel mode specifically

@terrelln
Copy link
Contributor

In order for the kernel to compile in contrib/linux-kernel/mem.h, #include <asm/unaligned.h> should be replaced with #include <linux/unaligned.h>. I haven't made that change yet as it was causing some regressions in the tests.

You should be able to fix the tests by moving this file:

https://github.com/facebook/zstd/blob/dev/contrib/linux-kernel/test/include/asm/unaligned.h

Into this directory:

https://github.com/facebook/zstd/tree/dev/contrib/linux-kernel/test/include/linux

This include directory fakes the Linux headers that Zstd depends on.

*
* Return: Zero or an error, which can be checked using zstd_is_error().
*/
size_t zstd_cctx_set_param(zstd_cctx *cctx, ZSTD_cParameter param, int value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: We could also add a typedef for zstd_cparameter to give it a kernel-style name.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a typedef for ZSTD_cParameter but I didn't add the documentation as the elements of the enum follow the ZSTD coding standard. Shall I redefine all parameters, or at least the one I need, using the kernel style?

In my driver I will have something like:

zstd_cctx_set_param(ctx, ZSTD_c_blockDelimiters, ZSTD_sf_explicitBlockDelimiters);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could go either way. I don't think we absolutely need to, given that we don't have many users of this API.

@gcabiddu gcabiddu force-pushed the compress_sequences_kernel branch from a34fd5a to f7c11d9 Compare January 23, 2025 12:04
*
* Return: Zero or an error, which can be checked using zstd_is_error().
*/
size_t zstd_cctx_set_param(zstd_cctx *cctx, ZSTD_cParameter param, int value);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a typedef for ZSTD_cParameter but I didn't add the documentation as the elements of the enum follow the ZSTD coding standard. Shall I redefine all parameters, or at least the one I need, using the kernel style?

In my driver I will have something like:

zstd_cctx_set_param(ctx, ZSTD_c_blockDelimiters, ZSTD_sf_explicitBlockDelimiters);

* Return: The compressed size or an error, which can be checked using
* zstd_is_error().
*/
size_t zstd_compress_sequences(zstd_cctx *cctx, void* dst, size_t dst_capacity,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall we keep this even if it might end up not being used in the kernel?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't need it, and don't expect to need it, we can remove it. If we need to add it later we can.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @terrelln. I updated the PR.

Who usually marks the comments as resolved? The submitter or the maintainer? Thanks.

@gcabiddu
Copy link
Contributor Author

In order for the kernel to compile in contrib/linux-kernel/mem.h, #include <asm/unaligned.h> should be replaced with #include <linux/unaligned.h>. I haven't made that change yet as it was causing some regressions in the tests.

You should be able to fix the tests by moving this file:

https://github.com/facebook/zstd/blob/dev/contrib/linux-kernel/test/include/asm/unaligned.h

Into this directory:

https://github.com/facebook/zstd/tree/dev/contrib/linux-kernel/test/include/linux

This include directory fakes the Linux headers that Zstd depends on.

Thanks @terrelln - I sorted it by moving that include as you suggested.

const zstd_sequence *in_seqs, size_t in_seqs_size,
const void* src, size_t src_size)
{
return ZSTD_compressSequences(cctx, dst, dst_capacity, in_seqs,
Copy link
Contributor

@pps83 pps83 Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spaces instead of tabs and everywhere else

Copy link
Contributor Author

@gcabiddu gcabiddu Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code will be ported to the kernel automatically. The kernel coding stiles uses tabs instead of spaces:
https://www.kernel.org/doc/html/latest/process/coding-style.html#indentation

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, sorry, didn't notice it was in contrib.

Make the function ZSTD_compressSequencesAndLiterals() available in kernel
space. This will be used by Intel QAT driver.

Additionally, (1) expose the function ZSTD_CCtx_setParameter(), which is
required to set parameters before calling ZSTD_compressSequencesAndLiterals(),
(2) update the build process to include `compress/zstd_preSplit.o` and
(3) replace `asm/unaligned.h` with `linux/unaligned.h`.

Signed-off-by: Giovanni Cabiddu <[email protected]>
@gcabiddu gcabiddu force-pushed the compress_sequences_kernel branch from f7c11d9 to 92be4be Compare January 27, 2025 15:39
@Cyan4973 Cyan4973 merged commit 1d088ba into facebook:dev Jan 27, 2025
96 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants