Re-Implement Workspace Shrinking when Oversized

This commit is contained in:
W. Felix Handte 2019-08-22 16:09:00 -04:00
parent e8cc137477
commit 901bba4ca6
3 changed files with 43 additions and 34 deletions

View File

@ -1451,7 +1451,8 @@ static size_t ZSTD_resetCCtx_internal(ZSTD_CCtx* zc,
zc->seqStore.maxNbSeq, zc->seqStore.maxNbLit,
zbuff, pledgedSrcSize) ) {
DEBUGLOG(4, "ZSTD_equivalentParams()==1 -> consider continue mode");
if (ZSTD_cwksp_bump_oversized_duration(&zc->workspace) <= ZSTD_WORKSPACETOOLARGE_MAXDURATION) {
ZSTD_cwksp_bump_oversized_duration(&zc->workspace, 0);
if (!ZSTD_cwksp_check_wasteful(&zc->workspace, 0)) {
DEBUGLOG(4, "continue mode confirmed (wLog1=%u, blockSize1=%zu)",
zc->appliedParams.cParams.windowLog, zc->blockSize);
if (ZSTD_indexTooCloseToMax(zc->blockState.matchState.window)) {

View File

@ -124,18 +124,6 @@ void* ZSTD_cwksp_reserve_object(ZSTD_cwksp* ws, size_t bytes) {
return start;
}
// TODO
int ZSTD_cwksp_bump_oversized_duration(ZSTD_cwksp* ws) {
(void)ws;
// if (((BYTE*)ws->allocEnd - (BYTE*)ws->workspace) * ZSTD_WORKSPACETOOLARGE_FACTOR < (BYTE*)ws->workspaceEnd - (BYTE*)ws->workspace) {
// ws->workspaceOversizedDuration++;
// } else {
// ws->workspaceOversizedDuration = 0;
// }
// return ws->workspaceOversizedDuration;
return 0;
}
/**
* Invalidates table allocations.
* All other allocations remain valid.
@ -150,7 +138,6 @@ void ZSTD_cwksp_clear_tables(ZSTD_cwksp* ws) {
*/
void ZSTD_cwksp_clear(ZSTD_cwksp* ws) {
DEBUGLOG(3, "wksp: clearing!");
ZSTD_cwksp_bump_oversized_duration(ws);
ws->tableEnd = ws->objectEnd;
ws->allocStart = ws->workspaceEnd;
ws->allocFailed = 0;
@ -186,18 +173,6 @@ void ZSTD_cwksp_free(ZSTD_cwksp* ws, ZSTD_customMem customMem) {
ZSTD_cwksp_clear(ws);
}
size_t ZSTD_cwksp_available_space(ZSTD_cwksp* ws) {
return (size_t)((BYTE*)ws->allocStart - (BYTE*)ws->tableEnd);
}
int ZSTD_cwksp_check_available(ZSTD_cwksp* ws, size_t minFree) {
return ZSTD_cwksp_available_space(ws) >= minFree;
}
int ZSTD_cwksp_check_wasteful(ZSTD_cwksp* ws, size_t minFree) {
return ZSTD_cwksp_check_available(ws, minFree * ZSTD_WORKSPACETOOLARGE_FACTOR) && ws->workspaceOversizedDuration > ZSTD_WORKSPACETOOLARGE_MAXDURATION;
}
size_t ZSTD_cwksp_sizeof(const ZSTD_cwksp* ws) {
return (BYTE*)ws->workspaceEnd - (BYTE*)ws->workspace;
}
@ -206,6 +181,33 @@ int ZSTD_cwksp_reserve_failed(const ZSTD_cwksp* ws) {
return ws->allocFailed;
}
size_t ZSTD_cwksp_available_space(ZSTD_cwksp* ws) {
return (size_t)((BYTE*)ws->allocStart - (BYTE*)ws->tableEnd);
}
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;
}
}
int ZSTD_cwksp_check_available(ZSTD_cwksp* ws, size_t additionalNeededSpace) {
return ZSTD_cwksp_available_space(ws) >= additionalNeededSpace;
}
int ZSTD_cwksp_check_too_large(ZSTD_cwksp* ws, size_t additionalNeededSpace) {
return ZSTD_cwksp_check_available(
ws, additionalNeededSpace * ZSTD_WORKSPACETOOLARGE_FACTOR);
}
int ZSTD_cwksp_check_wasteful(ZSTD_cwksp* ws, size_t additionalNeededSpace) {
return ZSTD_cwksp_check_too_large(ws, additionalNeededSpace)
&& ws->workspaceOversizedDuration > ZSTD_WORKSPACETOOLARGE_MAXDURATION;
}
#if defined (__cplusplus)
}
#endif

View File

@ -159,8 +159,6 @@ void* ZSTD_cwksp_reserve_table(ZSTD_cwksp* ws, size_t bytes);
*/
void* ZSTD_cwksp_reserve_object(ZSTD_cwksp* ws, size_t bytes);
int ZSTD_cwksp_bump_oversized_duration(ZSTD_cwksp* ws);
/**
* Invalidates table allocations.
* All other allocations remain valid.
@ -179,16 +177,24 @@ size_t ZSTD_cwksp_create(ZSTD_cwksp* ws, size_t size, ZSTD_customMem customMem);
void ZSTD_cwksp_free(ZSTD_cwksp* ws, ZSTD_customMem customMem);
size_t ZSTD_cwksp_available_space(ZSTD_cwksp* ws);
int ZSTD_cwksp_check_available(ZSTD_cwksp* ws, size_t minFree);
int ZSTD_cwksp_check_wasteful(ZSTD_cwksp* ws, size_t minFree);
size_t ZSTD_cwksp_sizeof(const ZSTD_cwksp* ws);
int ZSTD_cwksp_reserve_failed(const ZSTD_cwksp* ws);
/*-*************************************
* Functions Checking Free Space
***************************************/
size_t ZSTD_cwksp_available_space(ZSTD_cwksp* ws);
int ZSTD_cwksp_check_available(ZSTD_cwksp* ws, size_t additionalNeededSpace);
int ZSTD_cwksp_check_too_large(ZSTD_cwksp* ws, size_t additionalNeededSpace);
int ZSTD_cwksp_check_wasteful(ZSTD_cwksp* ws, size_t additionalNeededSpace);
void ZSTD_cwksp_bump_oversized_duration(ZSTD_cwksp* ws, size_t additionalNeededSpace);
#if defined (__cplusplus)
}
#endif