From 7db552676ebad975e81726d486e6530b35267cae Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Sat, 19 Aug 2017 15:07:54 -0700 Subject: [PATCH] reduced pool queue to 0 to save memory fixed : pool performance when jobs are fires fast and queueSize==0 --- lib/common/pool.c | 13 ++++--------- lib/compress/zstdmt_compress.c | 2 +- lib/legacy/zstd_legacy.h | 4 ++++ 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/common/pool.c b/lib/common/pool.c index bcea21ca..a227044f 100644 --- a/lib/common/pool.c +++ b/lib/common/pool.c @@ -76,17 +76,13 @@ static void* POOL_thread(void* opaque) { return opaque; } /* Pop a job off the queue */ - { - POOL_job const job = ctx->queue[ctx->queueHead]; + { POOL_job const job = ctx->queue[ctx->queueHead]; ctx->queueHead = (ctx->queueHead + 1) % ctx->queueSize; ctx->numThreadsBusy++; ctx->queueEmpty = ctx->queueHead == ctx->queueTail; /* Unlock the mutex, signal a pusher, and run the job */ pthread_mutex_unlock(&ctx->queueMutex); - - if (ctx->queueSize > 1) { - pthread_cond_signal(&ctx->queuePushCond); - } + pthread_cond_signal(&ctx->queuePushCond); job.function(job.opaque); @@ -96,9 +92,8 @@ static void* POOL_thread(void* opaque) { ctx->numThreadsBusy--; pthread_mutex_unlock(&ctx->queueMutex); pthread_cond_signal(&ctx->queuePushCond); - } - } - } + } } + } /* for (;;) */ /* Unreachable */ } diff --git a/lib/compress/zstdmt_compress.c b/lib/compress/zstdmt_compress.c index 02bb7c59..8564bc43 100644 --- a/lib/compress/zstdmt_compress.c +++ b/lib/compress/zstdmt_compress.c @@ -426,7 +426,7 @@ ZSTDMT_CCtx* ZSTDMT_createCCtx_advanced(unsigned nbThreads, ZSTD_customMem cMem) mtctx->allJobsCompleted = 1; mtctx->sectionSize = 0; mtctx->overlapLog = ZSTDMT_OVERLAPLOG_DEFAULT; - mtctx->factory = POOL_create(nbThreads, 1); + mtctx->factory = POOL_create(nbThreads, 0); mtctx->jobs = ZSTDMT_allocJobsTable(&nbJobs, cMem); mtctx->jobIDMask = nbJobs - 1; mtctx->bufPool = ZSTDMT_createBufferPool(nbThreads, cMem); diff --git a/lib/legacy/zstd_legacy.h b/lib/legacy/zstd_legacy.h index 6342192e..1126e246 100644 --- a/lib/legacy/zstd_legacy.h +++ b/lib/legacy/zstd_legacy.h @@ -123,6 +123,7 @@ MEM_STATIC size_t ZSTD_decompressLegacy( const void* dict,size_t dictSize) { U32 const version = ZSTD_isLegacy(src, compressedSize); + (void)dst; (void)dstCapacity; (void)dict; (void)dictSize; /* unused when ZSTD_LEGACY_SUPPORT >= 8 */ switch(version) { #if (ZSTD_LEGACY_SUPPORT <= 1) @@ -223,6 +224,7 @@ MEM_STATIC size_t ZSTD_freeLegacyStreamContext(void* legacyContext, U32 version) case 1 : case 2 : case 3 : + (void)legacyContext; return ERROR(version_unsupported); #if (ZSTD_LEGACY_SUPPORT <= 4) case 4 : return ZBUFFv04_freeDCtx((ZBUFFv04_DCtx*)legacyContext); @@ -250,6 +252,7 @@ MEM_STATIC size_t ZSTD_initLegacyStream(void** legacyContext, U32 prevVersion, U case 1 : case 2 : case 3 : + (void)dict; (void)dictSize; return 0; #if (ZSTD_LEGACY_SUPPORT <= 4) case 4 : @@ -306,6 +309,7 @@ MEM_STATIC size_t ZSTD_decompressLegacyStream(void* legacyContext, U32 version, case 1 : case 2 : case 3 : + (void)legacyContext; (void)output; (void)input; return ERROR(version_unsupported); #if (ZSTD_LEGACY_SUPPORT <= 4) case 4 :