Track Usable Table Space in Compression Workspace
This commit is contained in:
@@ -133,6 +133,7 @@ typedef struct {
|
|||||||
|
|
||||||
void* objectEnd;
|
void* objectEnd;
|
||||||
void* tableEnd;
|
void* tableEnd;
|
||||||
|
void* tableValidEnd;
|
||||||
void* allocStart;
|
void* allocStart;
|
||||||
|
|
||||||
int allocFailed;
|
int allocFailed;
|
||||||
@@ -161,6 +162,7 @@ MEM_STATIC void ZSTD_cwksp_internal_advance_phase(
|
|||||||
if (phase > ws->phase) {
|
if (phase > ws->phase) {
|
||||||
if (ws->phase < ZSTD_cwksp_alloc_buffers &&
|
if (ws->phase < ZSTD_cwksp_alloc_buffers &&
|
||||||
phase >= ZSTD_cwksp_alloc_buffers) {
|
phase >= ZSTD_cwksp_alloc_buffers) {
|
||||||
|
ws->tableValidEnd = ws->objectEnd;
|
||||||
}
|
}
|
||||||
if (ws->phase < ZSTD_cwksp_alloc_aligned &&
|
if (ws->phase < ZSTD_cwksp_alloc_aligned &&
|
||||||
phase >= ZSTD_cwksp_alloc_aligned) {
|
phase >= ZSTD_cwksp_alloc_aligned) {
|
||||||
@@ -193,6 +195,9 @@ MEM_STATIC void* ZSTD_cwksp_reserve_internal(
|
|||||||
ws->allocFailed = 1;
|
ws->allocFailed = 1;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
if (alloc < ws->tableValidEnd) {
|
||||||
|
ws->tableValidEnd = alloc;
|
||||||
|
}
|
||||||
ws->allocStart = alloc;
|
ws->allocStart = alloc;
|
||||||
return alloc;
|
return alloc;
|
||||||
}
|
}
|
||||||
@@ -256,9 +261,39 @@ MEM_STATIC void* ZSTD_cwksp_reserve_object(ZSTD_cwksp* ws, size_t bytes) {
|
|||||||
}
|
}
|
||||||
ws->objectEnd = end;
|
ws->objectEnd = end;
|
||||||
ws->tableEnd = end;
|
ws->tableEnd = end;
|
||||||
|
ws->tableValidEnd = end;
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MEM_STATIC void ZSTD_cwksp_mark_tables_dirty(ZSTD_cwksp* ws) {
|
||||||
|
DEBUGLOG(4, "cwksp: ZSTD_cwksp_mark_tables_dirty");
|
||||||
|
assert(ws->tableValidEnd >= ws->objectEnd);
|
||||||
|
assert(ws->tableValidEnd <= ws->allocStart);
|
||||||
|
ws->tableValidEnd = ws->objectEnd;
|
||||||
|
}
|
||||||
|
|
||||||
|
MEM_STATIC void ZSTD_cwksp_mark_tables_clean(ZSTD_cwksp* ws) {
|
||||||
|
DEBUGLOG(4, "cwksp: ZSTD_cwksp_mark_tables_clean");
|
||||||
|
assert(ws->tableValidEnd >= ws->objectEnd);
|
||||||
|
assert(ws->tableValidEnd <= ws->allocStart);
|
||||||
|
if (ws->tableValidEnd < ws->tableEnd) {
|
||||||
|
ws->tableValidEnd = ws->tableEnd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Zero the part of the allocated tables not already marked clean.
|
||||||
|
*/
|
||||||
|
MEM_STATIC void ZSTD_cwksp_clean_tables(ZSTD_cwksp* ws) {
|
||||||
|
DEBUGLOG(4, "cwksp: ZSTD_cwksp_clean_tables");
|
||||||
|
assert(ws->tableValidEnd >= ws->objectEnd);
|
||||||
|
assert(ws->tableValidEnd <= ws->allocStart);
|
||||||
|
if (ws->tableValidEnd < ws->tableEnd) {
|
||||||
|
memset(ws->tableValidEnd, 0, (BYTE*)ws->tableEnd - (BYTE*)ws->tableValidEnd);
|
||||||
|
}
|
||||||
|
ZSTD_cwksp_mark_tables_clean(ws);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invalidates table allocations.
|
* Invalidates table allocations.
|
||||||
* All other allocations remain valid.
|
* All other allocations remain valid.
|
||||||
@@ -293,6 +328,7 @@ MEM_STATIC void ZSTD_cwksp_init(ZSTD_cwksp* ws, void* start, size_t size) {
|
|||||||
ws->workspace = start;
|
ws->workspace = start;
|
||||||
ws->workspaceEnd = (BYTE*)start + size;
|
ws->workspaceEnd = (BYTE*)start + size;
|
||||||
ws->objectEnd = ws->workspace;
|
ws->objectEnd = ws->workspace;
|
||||||
|
ws->tableValidEnd = ws->objectEnd;
|
||||||
ws->phase = ZSTD_cwksp_alloc_objects;
|
ws->phase = ZSTD_cwksp_alloc_objects;
|
||||||
ZSTD_cwksp_clear(ws);
|
ZSTD_cwksp_clear(ws);
|
||||||
ws->workspaceOversizedDuration = 0;
|
ws->workspaceOversizedDuration = 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user