From: Paul Cruz Date: Tue, 25 Jul 2017 17:32:14 +0000 (-0700) Subject: created independent function for controlling how completion relates to compression... X-Git-Tag: v1.3.1^2~13^2^2~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=85d7c919f6b85ef4deb82bc7e4c2cdbfc49b2e10;p=thirdparty%2Fzstd.git created independent function for controlling how completion relates to compression level change --- diff --git a/contrib/adaptive-compression/adapt.c b/contrib/adaptive-compression/adapt.c index 32f54e67b..87082be46 100644 --- a/contrib/adaptive-compression/adapt.c +++ b/contrib/adaptive-compression/adapt.c @@ -311,6 +311,19 @@ static void waitUntilAllJobsCompleted(adaptCCtx* ctx) pthread_mutex_unlock(&ctx->allJobsCompleted_mutex.pMutex); } +static unsigned convertCompletionToChange(double completion) +{ + if (completion < 0.05) { + return 2; + } + else if (completion < 0.5) { + return 1; + } + else { + return 0; + } +} + /* * Compression level is changed depending on which part of the compression process is lagging * Currently, three theads exist for job creation, compression, and file writing respectively. @@ -357,7 +370,7 @@ static void adaptCompressionLevel(adaptCCtx* ctx) /* create or write waiting on compression */ /* use whichever one waited less because it was slower */ double const completion = MAX(createWaitCompressionCompletion, writeWaitCompressionCompletion); - unsigned const change = (unsigned)((1-completion) * MAX_COMPRESSION_LEVEL_CHANGE); + unsigned const change = convertCompletionToChange(completion); unsigned const boundChange = MIN(change, ctx->compressionLevel - 1); if (ctx->convergenceCounter > CONVERGENCE_LOWER_BOUND && boundChange != 0) { /* reset convergence counter, might have been a spike */ @@ -373,7 +386,7 @@ static void adaptCompressionLevel(adaptCCtx* ctx) else if (1-compressWaitWriteCompletion > threshold) { /* compress waiting on write */ double const completion = compressWaitWriteCompletion; - unsigned const change = (unsigned)((1-completion) * MAX_COMPRESSION_LEVEL_CHANGE); + unsigned const change = convertCompletionToChange(completion); unsigned const boundChange = MIN(change, ZSTD_maxCLevel() - ctx->compressionLevel); if (ctx->convergenceCounter > CONVERGENCE_LOWER_BOUND && boundChange != 0) { ctx->convergenceCounter = 0; @@ -389,7 +402,7 @@ static void adaptCompressionLevel(adaptCCtx* ctx) /* compress waiting on create*/ /* use compressWaitCreateCompletion */ double const completion = compressWaitCreateCompletion; - unsigned const change = (unsigned)((1-completion) * MAX_COMPRESSION_LEVEL_CHANGE); + unsigned const change = convertCompletionToChange(completion); unsigned const boundChange = MIN(change, ZSTD_maxCLevel() - ctx->compressionLevel); if (ctx->convergenceCounter > CONVERGENCE_LOWER_BOUND && boundChange != 0) { ctx->convergenceCounter = 0;