mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/next/linux-next.git
synced 2024-12-29 17:22:07 +00:00
98988fc8e9
Import upstream zstd v1.5.5 to expose upstream's QAT integration.
Import from upstream commit 58b3ef79 [0]. This is one commit before the
tag v1.5.5-kernel [1], which is signed with upstream's signing key. The
next patch in the series imports from v1.5.5-kernel, and is included in
the series, rather than just importing directly from v1.5.5-kernel,
because it is a non-trivial patch applied to improve the kernel's
decompression speed. This commit contains 3 backported patches on top of
v1.5.5: Two from the Linux copy of zstd, and one from upstream's `dev`
branch.
In addition to keeping the kernel's copy of zstd up to date, this update
was requested by Intel to expose upstream zstd's external match provider
API to the kernel, which allows QAT to accelerate the LZ match finding
stage.
This commit was generated by:
export ZSTD=/path/to/repo/zstd/
export LINUX=/path/to/repo/linux/
cd "$ZSTD/contrib/linux-kernel"
git checkout v1.5.5-kernel~
make import LINUX="$LINUX"
I tested and benchmarked this commit on x86-64 with gcc-13.2.1 on an
Intel i9-9900K by running my benchmark scripts that benchmark zstd's
performance in btrfs and squashfs compressed filesystems. This commit
improves compression speed, especially for higher compression levels,
and regresses decompression speed. But the decompression speed
regression is addressed by the next patch in the series.
Component, Level, C. time delta, size delta, D. time delta
Btrfs , 1, -1.9%, +0.0%, +9.5%
Btrfs , 3, -5.6%, +0.0%, +7.4%
Btrfs , 5, -4.9%, +0.0%, +5.0%
Btrfs , 7, -5.7%, +0.0%, +5.2%
Btrfs , 9, -5.7%, +0.0%, +4.0%
Squashfs , 1, N/A, 0.0%, +11.6%
I also boot tested with a zstd compressed kernel on i386 and aarch64.
Link: 58b3ef79eb
Link: https://github.com/facebook/zstd/tree/v1.5.5-kernel
Signed-off-by: Nick Terrell <terrelln@fb.com>
113 lines
4.3 KiB
C
113 lines
4.3 KiB
C
/* SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause */
|
|
/*
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under both the BSD-style license (found in the
|
|
* LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
* in the COPYING file in the root directory of this source tree).
|
|
* You may select, at your option, one of the above-listed licenses.
|
|
*/
|
|
|
|
#ifndef ZSTD_LDM_H
|
|
#define ZSTD_LDM_H
|
|
|
|
|
|
#include "zstd_compress_internal.h" /* ldmParams_t, U32 */
|
|
#include <linux/zstd.h> /* ZSTD_CCtx, size_t */
|
|
|
|
/*-*************************************
|
|
* Long distance matching
|
|
***************************************/
|
|
|
|
#define ZSTD_LDM_DEFAULT_WINDOW_LOG ZSTD_WINDOWLOG_LIMIT_DEFAULT
|
|
|
|
void ZSTD_ldm_fillHashTable(
|
|
ldmState_t* state, const BYTE* ip,
|
|
const BYTE* iend, ldmParams_t const* params);
|
|
|
|
/*
|
|
* ZSTD_ldm_generateSequences():
|
|
*
|
|
* Generates the sequences using the long distance match finder.
|
|
* Generates long range matching sequences in `sequences`, which parse a prefix
|
|
* of the source. `sequences` must be large enough to store every sequence,
|
|
* which can be checked with `ZSTD_ldm_getMaxNbSeq()`.
|
|
* @returns 0 or an error code.
|
|
*
|
|
* NOTE: The user must have called ZSTD_window_update() for all of the input
|
|
* they have, even if they pass it to ZSTD_ldm_generateSequences() in chunks.
|
|
* NOTE: This function returns an error if it runs out of space to store
|
|
* sequences.
|
|
*/
|
|
size_t ZSTD_ldm_generateSequences(
|
|
ldmState_t* ldms, rawSeqStore_t* sequences,
|
|
ldmParams_t const* params, void const* src, size_t srcSize);
|
|
|
|
/*
|
|
* ZSTD_ldm_blockCompress():
|
|
*
|
|
* Compresses a block using the predefined sequences, along with a secondary
|
|
* block compressor. The literals section of every sequence is passed to the
|
|
* secondary block compressor, and those sequences are interspersed with the
|
|
* predefined sequences. Returns the length of the last literals.
|
|
* Updates `rawSeqStore.pos` to indicate how many sequences have been consumed.
|
|
* `rawSeqStore.seq` may also be updated to split the last sequence between two
|
|
* blocks.
|
|
* @return The length of the last literals.
|
|
*
|
|
* NOTE: The source must be at most the maximum block size, but the predefined
|
|
* sequences can be any size, and may be longer than the block. In the case that
|
|
* they are longer than the block, the last sequences may need to be split into
|
|
* two. We handle that case correctly, and update `rawSeqStore` appropriately.
|
|
* NOTE: This function does not return any errors.
|
|
*/
|
|
size_t ZSTD_ldm_blockCompress(rawSeqStore_t* rawSeqStore,
|
|
ZSTD_matchState_t* ms, seqStore_t* seqStore, U32 rep[ZSTD_REP_NUM],
|
|
ZSTD_paramSwitch_e useRowMatchFinder,
|
|
void const* src, size_t srcSize);
|
|
|
|
/*
|
|
* ZSTD_ldm_skipSequences():
|
|
*
|
|
* Skip past `srcSize` bytes worth of sequences in `rawSeqStore`.
|
|
* Avoids emitting matches less than `minMatch` bytes.
|
|
* Must be called for data that is not passed to ZSTD_ldm_blockCompress().
|
|
*/
|
|
void ZSTD_ldm_skipSequences(rawSeqStore_t* rawSeqStore, size_t srcSize,
|
|
U32 const minMatch);
|
|
|
|
/* ZSTD_ldm_skipRawSeqStoreBytes():
|
|
* Moves forward in rawSeqStore by nbBytes, updating fields 'pos' and 'posInSequence'.
|
|
* Not to be used in conjunction with ZSTD_ldm_skipSequences().
|
|
* Must be called for data with is not passed to ZSTD_ldm_blockCompress().
|
|
*/
|
|
void ZSTD_ldm_skipRawSeqStoreBytes(rawSeqStore_t* rawSeqStore, size_t nbBytes);
|
|
|
|
/* ZSTD_ldm_getTableSize() :
|
|
* Estimate the space needed for long distance matching tables or 0 if LDM is
|
|
* disabled.
|
|
*/
|
|
size_t ZSTD_ldm_getTableSize(ldmParams_t params);
|
|
|
|
/* ZSTD_ldm_getSeqSpace() :
|
|
* Return an upper bound on the number of sequences that can be produced by
|
|
* the long distance matcher, or 0 if LDM is disabled.
|
|
*/
|
|
size_t ZSTD_ldm_getMaxNbSeq(ldmParams_t params, size_t maxChunkSize);
|
|
|
|
/* ZSTD_ldm_adjustParameters() :
|
|
* If the params->hashRateLog is not set, set it to its default value based on
|
|
* windowLog and params->hashLog.
|
|
*
|
|
* Ensures that params->bucketSizeLog is <= params->hashLog (setting it to
|
|
* params->hashLog if it is not).
|
|
*
|
|
* Ensures that the minMatchLength >= targetLength during optimal parsing.
|
|
*/
|
|
void ZSTD_ldm_adjustParameters(ldmParams_t* params,
|
|
ZSTD_compressionParameters const* cParams);
|
|
|
|
|
|
#endif /* ZSTD_FAST_H */
|