lib/zstd/compress/zstd_cwksp.h
Source file repositories/reference/linux-study-clean/lib/zstd/compress/zstd_cwksp.h
File Facts
- System
- Linux kernel
- Corpus path
lib/zstd/compress/zstd_cwksp.h- Extension
.h- Size
- 24222 bytes
- Lines
- 658
- Domain
- Kernel Services
- Bucket
- lib
- Inferred role
- Kernel Services: implementation source
- Status
- source implementation candidate
Why This File Exists
Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
- Shared kernel service surface used by multiple subsystems, including helpers, cryptography, virtualization support, and async I/O infrastructure.
Dependency Surface
../common/allocations.h../common/zstd_internal.h../common/portability_macros.h../common/compiler.h
Detected Declarations
function ZSTD_cwksp_assert_internal_consistencyfunction ZSTD_cwksp_alignfunction ZSTD_cwksp_alloc_sizefunction ZSTD_cwksp_aligned_alloc_sizefunction ZSTD_cwksp_aligned64_alloc_sizefunction purposesfunction ZSTD_cwksp_bytes_to_align_ptrfunction ZSTD_cwksp_initialAllocStartfunction wkspfunction ZSTD_cwksp_internal_advance_phasefunction ZSTD_cwksp_owns_bufferfunction ZSTD_cwksp_reserve_internalfunction ZSTD_cwksp_reserve_bufferfunction ZSTD_CWKSP_ALIGNMENT_BYTESfunction ZSTD_CWKSP_ALIGNMENT_BYTESfunction memsetfunction ZSTD_cwksp_reserve_object_alignedfunction ZSTD_cwksp_mark_tables_dirtyfunction ZSTD_cwksp_mark_tables_cleanfunction ZSTD_cwksp_clean_tablesfunction ZSTD_cwksp_clear_tablesfunction ZSTD_cwksp_clearfunction ZSTD_cwksp_sizeoffunction ZSTD_cwksp_usedfunction ignoredfunction ZSTD_cwksp_createfunction ZSTD_cwksp_freefunction statefunction ZSTD_cwksp_reserve_failedfunction ZSTD_cwksp_estimated_space_within_boundsfunction ZSTD_cwksp_available_spacefunction ZSTD_cwksp_check_availablefunction ZSTD_cwksp_check_too_largefunction ZSTD_cwksp_check_wastefulfunction ZSTD_cwksp_bump_oversized_duration
Annotated Snippet
MEM_STATIC void ZSTD_cwksp_assert_internal_consistency(ZSTD_cwksp* ws) {
(void)ws;
assert(ws->workspace <= ws->objectEnd);
assert(ws->objectEnd <= ws->tableEnd);
assert(ws->objectEnd <= ws->tableValidEnd);
assert(ws->tableEnd <= ws->allocStart);
assert(ws->tableValidEnd <= ws->allocStart);
assert(ws->allocStart <= ws->workspaceEnd);
assert(ws->initOnceStart <= ZSTD_cwksp_initialAllocStart(ws));
assert(ws->workspace <= ws->initOnceStart);
}
/*
* Align must be a power of 2.
*/
MEM_STATIC size_t ZSTD_cwksp_align(size_t size, size_t align) {
size_t const mask = align - 1;
assert(ZSTD_isPower2(align));
return (size + mask) & ~mask;
}
/*
* Use this to determine how much space in the workspace we will consume to
* allocate this object. (Normally it should be exactly the size of the object,
* but under special conditions, like ASAN, where we pad each object, it might
* be larger.)
*
* Since tables aren't currently redzoned, you don't need to call through this
* to figure out how much space you need for the matchState tables. Everything
* else is though.
*
* Do not use for sizing aligned buffers. Instead, use ZSTD_cwksp_aligned64_alloc_size().
*/
MEM_STATIC size_t ZSTD_cwksp_alloc_size(size_t size) {
if (size == 0)
return 0;
return size;
}
MEM_STATIC size_t ZSTD_cwksp_aligned_alloc_size(size_t size, size_t alignment) {
return ZSTD_cwksp_alloc_size(ZSTD_cwksp_align(size, alignment));
}
/*
* Returns an adjusted alloc size that is the nearest larger multiple of 64 bytes.
* Used to determine the number of bytes required for a given "aligned".
*/
MEM_STATIC size_t ZSTD_cwksp_aligned64_alloc_size(size_t size) {
return ZSTD_cwksp_aligned_alloc_size(size, ZSTD_CWKSP_ALIGNMENT_BYTES);
}
/*
* Returns the amount of additional space the cwksp must allocate
* for internal purposes (currently only alignment).
*/
MEM_STATIC size_t ZSTD_cwksp_slack_space_required(void) {
/* For alignment, the wksp will always allocate an additional 2*ZSTD_CWKSP_ALIGNMENT_BYTES
* bytes to align the beginning of tables section and end of buffers;
*/
size_t const slackSpace = ZSTD_CWKSP_ALIGNMENT_BYTES * 2;
return slackSpace;
}
/*
* Return the number of additional bytes required to align a pointer to the given number of bytes.
* alignBytes must be a power of two.
*/
MEM_STATIC size_t ZSTD_cwksp_bytes_to_align_ptr(void* ptr, const size_t alignBytes) {
size_t const alignBytesMask = alignBytes - 1;
size_t const bytes = (alignBytes - ((size_t)ptr & (alignBytesMask))) & alignBytesMask;
assert(ZSTD_isPower2(alignBytes));
assert(bytes < alignBytes);
return bytes;
}
/*
* Returns the initial value for allocStart which is used to determine the position from
* which we can allocate from the end of the workspace.
*/
MEM_STATIC void* ZSTD_cwksp_initialAllocStart(ZSTD_cwksp* ws)
{
char* endPtr = (char*)ws->workspaceEnd;
assert(ZSTD_isPower2(ZSTD_CWKSP_ALIGNMENT_BYTES));
endPtr = endPtr - ((size_t)endPtr % ZSTD_CWKSP_ALIGNMENT_BYTES);
return (void*)endPtr;
}
/*
* Internal function. Do not use directly.
Annotation
- Immediate include surface: `../common/allocations.h`, `../common/zstd_internal.h`, `../common/portability_macros.h`, `../common/compiler.h`.
- Detected declarations: `function ZSTD_cwksp_assert_internal_consistency`, `function ZSTD_cwksp_align`, `function ZSTD_cwksp_alloc_size`, `function ZSTD_cwksp_aligned_alloc_size`, `function ZSTD_cwksp_aligned64_alloc_size`, `function purposes`, `function ZSTD_cwksp_bytes_to_align_ptr`, `function ZSTD_cwksp_initialAllocStart`, `function wksp`, `function ZSTD_cwksp_internal_advance_phase`.
- Atlas domain: Kernel Services / lib.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.