feat(compress): move workspace resize policy to Rust
The CCtx reset orchestration already runs in Rust, but its C workspace adapter still decided when capacity was too small or wasteful and maintained the oversized-duration counter through C-only predicates. Move those factor, threshold, overflow, and duration-update rules into Rust. C now supplies only private workspace metrics and retains low-level allocation, reservation, and layout operations. Remove the obsolete C predicates so the workspace resize decision has one Rust-owned implementation and remains covered at its boundary conditions. Test Plan: - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo check --manifest-path rust/Cargo.toml --tests - ulimit -v 41943040; CARGO_BUILD_JOBS=1 cargo clippy --manifest-path rust/cli/Cargo.toml --all-targets -- -D warnings - ulimit -v 41943040; CARGO_BUILD_JOBS=1 make -j1 - ulimit -v 41943040; CARGO_BUILD_JOBS=1 make -j1 -C tests invalidDictionaries - ulimit -v 41943040; make -j1 -C tests test
This commit is contained in:
@@ -2166,6 +2166,13 @@ typedef void (*ZSTD_rust_resetCCtxWorkspacePrepare_f)(
|
||||
size_t blockSize, int* workspaceTooSmall, int* workspaceWasteful);
|
||||
typedef void (*ZSTD_rust_resetCCtxTailPrepare_f)(
|
||||
void* context, size_t blockSize, int indexResetPolicy);
|
||||
void ZSTD_rust_workspaceResizeFlags(
|
||||
size_t workspaceSize, size_t availableSpace,
|
||||
int workspaceOversizedDuration, size_t neededSpace,
|
||||
int* workspaceTooSmall, int* workspaceWasteful);
|
||||
void ZSTD_rust_workspaceBumpOversizedDuration(
|
||||
size_t availableSpace, size_t additionalNeededSpace,
|
||||
int* workspaceOversizedDuration);
|
||||
typedef struct {
|
||||
void* callbackContext;
|
||||
int ldmEnable;
|
||||
@@ -5270,7 +5277,9 @@ static void ZSTD_rust_resetCCtxWorkspace_bumpOversizedDuration(void* opaque)
|
||||
{
|
||||
ZSTD_rust_resetCCtxStorageContext* const context =
|
||||
(ZSTD_rust_resetCCtxStorageContext*)opaque;
|
||||
ZSTD_cwksp_bump_oversized_duration(context->ws, 0);
|
||||
ZSTD_rust_workspaceBumpOversizedDuration(
|
||||
ZSTD_cwksp_available_space(context->ws), 0,
|
||||
&context->ws->workspaceOversizedDuration);
|
||||
}
|
||||
|
||||
static void ZSTD_rust_resetCCtxWorkspace_free(void* opaque)
|
||||
@@ -5321,8 +5330,10 @@ static void ZSTD_rust_resetCCtxWorkspace_prepare(
|
||||
ZSTD_rust_resetCCtxTailContext* const context =
|
||||
(ZSTD_rust_resetCCtxTailContext*)opaque;
|
||||
ZSTD_cwksp* const ws = context->ws;
|
||||
*workspaceTooSmall = ZSTD_cwksp_sizeof(ws) < neededSpace;
|
||||
*workspaceWasteful = ZSTD_cwksp_check_wasteful(ws, neededSpace);
|
||||
ZSTD_rust_workspaceResizeFlags(
|
||||
ZSTD_cwksp_sizeof(ws), ZSTD_cwksp_available_space(ws),
|
||||
ws->workspaceOversizedDuration, neededSpace,
|
||||
workspaceTooSmall, workspaceWasteful);
|
||||
DEBUGLOG(4, "Need %zu B workspace", neededSpace);
|
||||
DEBUGLOG(4, "windowSize: %zu - blockSize: %zu",
|
||||
windowSize, blockSize);
|
||||
|
||||
@@ -743,23 +743,4 @@ MEM_STATIC int ZSTD_cwksp_check_available(ZSTD_cwksp* ws, size_t additionalNeede
|
||||
return ZSTD_cwksp_available_space(ws) >= additionalNeededSpace;
|
||||
}
|
||||
|
||||
MEM_STATIC int ZSTD_cwksp_check_too_large(ZSTD_cwksp* ws, size_t additionalNeededSpace) {
|
||||
return ZSTD_cwksp_check_available(
|
||||
ws, additionalNeededSpace * ZSTD_WORKSPACETOOLARGE_FACTOR);
|
||||
}
|
||||
|
||||
MEM_STATIC int ZSTD_cwksp_check_wasteful(ZSTD_cwksp* ws, size_t additionalNeededSpace) {
|
||||
return ZSTD_cwksp_check_too_large(ws, additionalNeededSpace)
|
||||
&& ws->workspaceOversizedDuration > ZSTD_WORKSPACETOOLARGE_MAXDURATION;
|
||||
}
|
||||
|
||||
MEM_STATIC void ZSTD_cwksp_bump_oversized_duration(
|
||||
ZSTD_cwksp* ws, size_t additionalNeededSpace) {
|
||||
if (ZSTD_cwksp_check_too_large(ws, additionalNeededSpace)) {
|
||||
ws->workspaceOversizedDuration++;
|
||||
} else {
|
||||
ws->workspaceOversizedDuration = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* ZSTD_CWKSP_H */
|
||||
|
||||
Reference in New Issue
Block a user