Merge pull request #957 from facebook/nbThreads
zstdmt via compress_generic: reduce opportunity to free/create mtctx
This commit is contained in:
commit
aa0c09bdc9
@ -2851,7 +2851,9 @@ size_t ZSTD_compress_generic (ZSTD_CCtx* cctx,
|
|||||||
if ((cctx->pledgedSrcSizePlusOne-1) <= ZSTDMT_JOBSIZE_MIN)
|
if ((cctx->pledgedSrcSizePlusOne-1) <= ZSTDMT_JOBSIZE_MIN)
|
||||||
params.nbThreads = 1; /* do not invoke multi-threading when src size is too small */
|
params.nbThreads = 1; /* do not invoke multi-threading when src size is too small */
|
||||||
if (params.nbThreads > 1) {
|
if (params.nbThreads > 1) {
|
||||||
if (cctx->mtctx == NULL || cctx->appliedParams.nbThreads != params.nbThreads) {
|
if (cctx->mtctx == NULL || (params.nbThreads != ZSTDMT_getNbThreads(cctx->mtctx))) {
|
||||||
|
DEBUGLOG(4, "ZSTD_compress_generic: creating new mtctx for nbThreads=%u (previous: %u)",
|
||||||
|
params.nbThreads, ZSTDMT_getNbThreads(cctx->mtctx));
|
||||||
ZSTDMT_freeCCtx(cctx->mtctx);
|
ZSTDMT_freeCCtx(cctx->mtctx);
|
||||||
cctx->mtctx = ZSTDMT_createCCtx_advanced(params.nbThreads, cctx->customMem);
|
cctx->mtctx = ZSTDMT_createCCtx_advanced(params.nbThreads, cctx->customMem);
|
||||||
if (cctx->mtctx == NULL) return ERROR(memory_allocation);
|
if (cctx->mtctx == NULL) return ERROR(memory_allocation);
|
||||||
|
@ -459,6 +459,15 @@ size_t ZSTDMT_CCtxParam_setNbThreads(ZSTD_CCtx_params* params, unsigned nbThread
|
|||||||
return nbThreads;
|
return nbThreads;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ZSTDMT_getNbThreads():
|
||||||
|
* @return nb threads currently active in mtctx.
|
||||||
|
* mtctx must be valid */
|
||||||
|
size_t ZSTDMT_getNbThreads(const ZSTDMT_CCtx* mtctx)
|
||||||
|
{
|
||||||
|
assert(mtctx != NULL);
|
||||||
|
return mtctx->params.nbThreads;
|
||||||
|
}
|
||||||
|
|
||||||
ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbThreads, ZSTD_customMem cMem)
|
ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbThreads, ZSTD_customMem cMem)
|
||||||
{
|
{
|
||||||
ZSTDMT_CCtx* mtctx;
|
ZSTDMT_CCtx* mtctx;
|
||||||
|
@ -114,9 +114,14 @@ size_t ZSTDMT_CCtxParam_setMTCtxParameter(ZSTD_CCtx_params* params, ZSTDMT_param
|
|||||||
|
|
||||||
/* ZSTDMT_CCtxParam_setNbThreads()
|
/* ZSTDMT_CCtxParam_setNbThreads()
|
||||||
* Set nbThreads, and clamp it correctly,
|
* Set nbThreads, and clamp it correctly,
|
||||||
* but also reset jobSize and overlapLog */
|
* also reset jobSize and overlapLog */
|
||||||
size_t ZSTDMT_CCtxParam_setNbThreads(ZSTD_CCtx_params* params, unsigned nbThreads);
|
size_t ZSTDMT_CCtxParam_setNbThreads(ZSTD_CCtx_params* params, unsigned nbThreads);
|
||||||
|
|
||||||
|
/* ZSTDMT_getNbThreads():
|
||||||
|
* @return nb threads currently active in mtctx.
|
||||||
|
* mtctx must be valid */
|
||||||
|
size_t ZSTDMT_getNbThreads(const ZSTDMT_CCtx* mtctx);
|
||||||
|
|
||||||
/*! ZSTDMT_initCStream_internal() :
|
/*! ZSTDMT_initCStream_internal() :
|
||||||
* Private use only. Init streaming operation.
|
* Private use only. Init streaming operation.
|
||||||
* expects params to be valid.
|
* expects params to be valid.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user