feat(compress): move CCtx table copies into Rust

Pass CCtx match-table locations and source sizing metadata through the Rust
copy bridge. Rust now selects the table sizes after the source-stage guard,
loads destination tables after reset has allocated them, and performs the
hash, chain, and hash3 copies between the existing workspace dirty/clean
callbacks.

Test Plan:
- ulimit -v 41943040 && CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/Cargo.toml --all-targets -- -D warnings
- ulimit -v 41943040 && make -j1
- ulimit -v 41943040 && CARGO_BUILD_JOBS=1 cargo test --manifest-path rust/Cargo.toml
- ulimit -v 41943040 && make -j1 -C tests test-zstream ZSTREAM_TESTTIME=-T2s
- ulimit -v 41943040 && make -j1 -C tests test-fuzzer FUZZERTEST=-T3s FUZZER_FLAGS=--no-big-tests
This commit is contained in:
2026-07-19 23:18:19 +02:00
parent 46dd25a122
commit 21970bdea5
2 changed files with 193 additions and 47 deletions
+31 -30
View File
@@ -462,8 +462,6 @@ typedef size_t (*ZSTD_rust_copyCCtxReset_f)(
const ZSTD_frameParameters* fParams,
U64 pledgedSrcSize, int zbuff);
typedef void (*ZSTD_rust_copyCCtxMarkTables_f)(void* context);
typedef void (*ZSTD_rust_copyCCtxCopyTables_f)(
void* context, const void* srcCCtx);
typedef struct {
void* callbackContext;
const void* srcCCtx;
@@ -474,8 +472,18 @@ typedef struct {
const void* sourceCustomMem;
ZSTD_rust_copyCCtxReset_f reset;
ZSTD_rust_copyCCtxMarkTables_f markTablesDirty;
ZSTD_rust_copyCCtxCopyTables_f copyTables;
ZSTD_rust_copyCCtxMarkTables_f markTablesClean;
U32** destinationHashTable;
const U32* sourceHashTable;
const U32* sourceHashLog;
U32** destinationChainTable;
const U32* sourceChainTable;
const U32* sourceChainLog;
U32** destinationHashTable3;
const U32* sourceHashTable3;
const U32* sourceHashLog3;
const int* sourceStrategy;
const int* sourceUseRowMatchFinder;
void* destinationWindow;
const void* sourceWindow;
U32* destinationNextToUpdate;
@@ -533,7 +541,7 @@ typedef char ZSTD_rust_copy_cctx_internal_state_layout[
== 3 * sizeof(void*) + sizeof(U64)
&& offsetof(ZSTD_rust_copyCCtxInternalState, zbuff)
== 3 * sizeof(void*) + sizeof(U64)
+ 19 * sizeof(void*)
+ 29 * sizeof(void*)
&& sizeof(ZSTD_rust_copyCCtxInternalState)
== ((offsetof(ZSTD_rust_copyCCtxInternalState, zbuff)
+ sizeof(int) + sizeof(void*) - 1) / sizeof(void*))
@@ -4782,31 +4790,6 @@ static void ZSTD_rust_copyCCtx_mark_tables_dirty(void* context)
ZSTD_cwksp_mark_tables_dirty(&dst->workspace);
}
static void ZSTD_rust_copyCCtx_copy_tables(
void* context, const void* srcCCtx)
{
ZSTD_CCtx* const dst = (ZSTD_CCtx*)context;
const ZSTD_CCtx* const src = (const ZSTD_CCtx*)srcCCtx;
size_t const chainSize = ZSTD_allocateChainTable(
src->appliedParams.cParams.strategy,
src->appliedParams.useRowMatchFinder,
0 /* forDDSDict */)
? ((size_t)1 << src->appliedParams.cParams.chainLog)
: 0;
size_t const hSize = (size_t)1 << src->appliedParams.cParams.hashLog;
U32 const h3log = src->blockState.matchState.hashLog3;
size_t const h3Size = h3log ? ((size_t)1 << h3log) : 0;
ZSTD_memcpy(dst->blockState.matchState.hashTable,
src->blockState.matchState.hashTable,
hSize * sizeof(U32));
ZSTD_memcpy(dst->blockState.matchState.chainTable,
src->blockState.matchState.chainTable,
chainSize * sizeof(U32));
ZSTD_memcpy(dst->blockState.matchState.hashTable3,
src->blockState.matchState.hashTable3,
h3Size * sizeof(U32));
}
static void ZSTD_rust_copyCCtx_mark_tables_clean(void* context)
{
ZSTD_CCtx* const dst = (ZSTD_CCtx*)context;
@@ -4819,7 +4802,15 @@ static size_t ZSTD_rust_copyCCtx_internal_callback(
U64 pledgedSrcSize, int zbuff)
{
ZSTD_rust_copyCCtxInternalState state;
ZSTD_CCtx* const dst = (ZSTD_CCtx*)context;
const ZSTD_CCtx* const src = (const ZSTD_CCtx*)srcCCtx;
int const sourceStage = (int)((const ZSTD_CCtx*)srcCCtx)->stage;
U32 const sourceHashLog = src->appliedParams.cParams.hashLog;
U32 const sourceChainLog = src->appliedParams.cParams.chainLog;
U32 const sourceHashLog3 = src->blockState.matchState.hashLog3;
int const sourceStrategy = (int)src->appliedParams.cParams.strategy;
int const sourceUseRowMatchFinder =
(int)src->appliedParams.useRowMatchFinder;
state.callbackContext = context;
state.srcCCtx = srcCCtx;
state.fParams = fParams;
@@ -4831,8 +4822,18 @@ static size_t ZSTD_rust_copyCCtx_internal_callback(
&((const ZSTD_CCtx*)srcCCtx)->customMem;
state.reset = ZSTD_rust_copyCCtx_reset;
state.markTablesDirty = ZSTD_rust_copyCCtx_mark_tables_dirty;
state.copyTables = ZSTD_rust_copyCCtx_copy_tables;
state.markTablesClean = ZSTD_rust_copyCCtx_mark_tables_clean;
state.destinationHashTable = &dst->blockState.matchState.hashTable;
state.sourceHashTable = src->blockState.matchState.hashTable;
state.sourceHashLog = &sourceHashLog;
state.destinationChainTable = &dst->blockState.matchState.chainTable;
state.sourceChainTable = src->blockState.matchState.chainTable;
state.sourceChainLog = &sourceChainLog;
state.destinationHashTable3 = &dst->blockState.matchState.hashTable3;
state.sourceHashTable3 = src->blockState.matchState.hashTable3;
state.sourceHashLog3 = &sourceHashLog3;
state.sourceStrategy = &sourceStrategy;
state.sourceUseRowMatchFinder = &sourceUseRowMatchFinder;
state.destinationWindow =
&((ZSTD_CCtx*)context)->blockState.matchState.window;
state.sourceWindow =