lib/zstd/compress/zstd_compress.c
Source file repositories/reference/linux-study-clean/lib/zstd/compress/zstd_compress.c
File Facts
- System
- Linux kernel
- Corpus path
lib/zstd/compress/zstd_compress.c- Extension
.c- Size
- 337333 bytes
- Lines
- 7635
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
../common/allocations.h../common/zstd_deps.h../common/mem.h../common/error_private.hhist.h../common/fse.h../common/huf.hzstd_compress_internal.hzstd_compress_sequences.hzstd_compress_literals.hzstd_fast.hzstd_double_fast.hzstd_lazy.hzstd_opt.hzstd_ldm.hzstd_compress_superblock.h../common/bits.hzstd_preSplit.himmintrin.hclevels.h
Detected Declarations
struct ZSTD_CDict_sfunction Copyrightfunction ZSTD_createCCtxfunction ZSTD_initCCtxfunction ZSTD_createCCtx_advancedfunction ZSTD_initStaticCCtxfunction ZSTD_clearAllDictsfunction ZSTD_sizeof_localDictfunction ZSTD_freeCCtxContentfunction ZSTD_freeCCtxfunction ZSTD_sizeof_mtctxfunction ZSTD_sizeof_CCtxfunction ZSTD_sizeof_CStreamfunction ZSTD_getSeqStorefunction ZSTD_rowMatchFinderSupportedfunction ZSTD_rowMatchFinderUsedfunction ZSTD_resolveRowMatchFinderModefunction ZSTD_resolveBlockSplitterModefunction ZSTD_allocateChainTablefunction matchingfunction ZSTD_resolveExternalSequenceValidationfunction ZSTD_resolveMaxBlockSizefunction ZSTD_resolveExternalRepcodeSearchfunction ZSTD_CDictIndicesAreTaggedfunction ZSTD_makeCCtxParamsFromCParamsfunction ZSTD_createCCtxParams_advancedfunction ZSTD_createCCtxParamsfunction ZSTD_freeCCtxParamsfunction ZSTD_CCtxParams_resetfunction ZSTD_CCtxParams_initfunction ZSTD_CCtxParams_init_internalfunction ZSTD_CCtxParams_init_advancedfunction ZSTD_CCtxParams_setZstdParamsfunction ZSTD_cParam_getBoundsfunction ZSTD_cParam_clampBoundsfunction ZSTD_isUpdateAuthorizedfunction ZSTD_CCtx_setParameterfunction ZSTD_CCtxParams_setParameterfunction ZSTD_CCtx_getParameterfunction ZSTD_CCtxParams_getParameterfunction ZSTD_CCtx_setParametersUsingCCtxParamsfunction ZSTD_CCtx_setCParamsfunction ZSTD_CCtx_setFParamsfunction ZSTD_CCtx_setParamsfunction ZSTD_CCtx_setPledgedSrcSizefunction ZSTD_initLocalDictfunction ZSTD_CCtx_loadDictionary_advancedfunction ZSTD_CCtx_loadDictionary_byReference
Annotated Snippet
struct ZSTD_CDict_s {
const void* dictContent;
size_t dictContentSize;
ZSTD_dictContentType_e dictContentType; /* The dictContentType the CDict was created with */
U32* entropyWorkspace; /* entropy workspace of HUF_WORKSPACE_SIZE bytes */
ZSTD_cwksp workspace;
ZSTD_MatchState_t matchState;
ZSTD_compressedBlockState_t cBlockState;
ZSTD_customMem customMem;
U32 dictID;
int compressionLevel; /* 0 indicates that advanced API was used to select CDict params */
ZSTD_ParamSwitch_e useRowMatchFinder; /* Indicates whether the CDict was created with params that would use
* row-based matchfinder. Unless the cdict is reloaded, we will use
* the same greedy/lazy matchfinder at compression time.
*/
}; /* typedef'd to ZSTD_CDict within "zstd.h" */
ZSTD_CCtx* ZSTD_createCCtx(void)
{
return ZSTD_createCCtx_advanced(ZSTD_defaultCMem);
}
static void ZSTD_initCCtx(ZSTD_CCtx* cctx, ZSTD_customMem memManager)
{
assert(cctx != NULL);
ZSTD_memset(cctx, 0, sizeof(*cctx));
cctx->customMem = memManager;
cctx->bmi2 = ZSTD_cpuSupportsBmi2();
{ size_t const err = ZSTD_CCtx_reset(cctx, ZSTD_reset_parameters);
assert(!ZSTD_isError(err));
(void)err;
}
}
ZSTD_CCtx* ZSTD_createCCtx_advanced(ZSTD_customMem customMem)
{
ZSTD_STATIC_ASSERT(zcss_init==0);
ZSTD_STATIC_ASSERT(ZSTD_CONTENTSIZE_UNKNOWN==(0ULL - 1));
if ((!customMem.customAlloc) ^ (!customMem.customFree)) return NULL;
{ ZSTD_CCtx* const cctx = (ZSTD_CCtx*)ZSTD_customMalloc(sizeof(ZSTD_CCtx), customMem);
if (!cctx) return NULL;
ZSTD_initCCtx(cctx, customMem);
return cctx;
}
}
ZSTD_CCtx* ZSTD_initStaticCCtx(void* workspace, size_t workspaceSize)
{
ZSTD_cwksp ws;
ZSTD_CCtx* cctx;
if (workspaceSize <= sizeof(ZSTD_CCtx)) return NULL; /* minimum size */
if ((size_t)workspace & 7) return NULL; /* must be 8-aligned */
ZSTD_cwksp_init(&ws, workspace, workspaceSize, ZSTD_cwksp_static_alloc);
cctx = (ZSTD_CCtx*)ZSTD_cwksp_reserve_object(&ws, sizeof(ZSTD_CCtx));
if (cctx == NULL) return NULL;
ZSTD_memset(cctx, 0, sizeof(ZSTD_CCtx));
ZSTD_cwksp_move(&cctx->workspace, &ws);
cctx->staticSize = workspaceSize;
/* statically sized space. tmpWorkspace never moves (but prev/next block swap places) */
if (!ZSTD_cwksp_check_available(&cctx->workspace, TMP_WORKSPACE_SIZE + 2 * sizeof(ZSTD_compressedBlockState_t))) return NULL;
cctx->blockState.prevCBlock = (ZSTD_compressedBlockState_t*)ZSTD_cwksp_reserve_object(&cctx->workspace, sizeof(ZSTD_compressedBlockState_t));
cctx->blockState.nextCBlock = (ZSTD_compressedBlockState_t*)ZSTD_cwksp_reserve_object(&cctx->workspace, sizeof(ZSTD_compressedBlockState_t));
cctx->tmpWorkspace = ZSTD_cwksp_reserve_object(&cctx->workspace, TMP_WORKSPACE_SIZE);
cctx->tmpWkspSize = TMP_WORKSPACE_SIZE;
cctx->bmi2 = ZSTD_cpuid_bmi2(ZSTD_cpuid());
return cctx;
}
/*
* Clears and frees all of the dictionaries in the CCtx.
*/
static void ZSTD_clearAllDicts(ZSTD_CCtx* cctx)
{
ZSTD_customFree(cctx->localDict.dictBuffer, cctx->customMem);
ZSTD_freeCDict(cctx->localDict.cdict);
ZSTD_memset(&cctx->localDict, 0, sizeof(cctx->localDict));
ZSTD_memset(&cctx->prefixDict, 0, sizeof(cctx->prefixDict));
cctx->cdict = NULL;
}
static size_t ZSTD_sizeof_localDict(ZSTD_localDict dict)
{
size_t const bufferSize = dict.dictBuffer != NULL ? dict.dictSize : 0;
size_t const cdictSize = ZSTD_sizeof_CDict(dict.cdict);
return bufferSize + cdictSize;
}
Annotation
- Immediate include surface: `../common/allocations.h`, `../common/zstd_deps.h`, `../common/mem.h`, `../common/error_private.h`, `hist.h`, `../common/fse.h`, `../common/huf.h`, `zstd_compress_internal.h`.
- Detected declarations: `struct ZSTD_CDict_s`, `function Copyright`, `function ZSTD_createCCtx`, `function ZSTD_initCCtx`, `function ZSTD_createCCtx_advanced`, `function ZSTD_initStaticCCtx`, `function ZSTD_clearAllDicts`, `function ZSTD_sizeof_localDict`, `function ZSTD_freeCCtxContent`, `function ZSTD_freeCCtx`.
- 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.