From: Nick Terrell Date: Tue, 20 Mar 2018 01:56:39 +0000 (-0700) Subject: Fix window size for 1 worker + flushing X-Git-Tag: v1.3.4~1^2~14^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d19f803a3b18d46acf565e99214d33c9fbbb13a0;p=thirdparty%2Fzstd.git Fix window size for 1 worker + flushing --- diff --git a/lib/compress/zstdmt_compress.c b/lib/compress/zstdmt_compress.c index b0d97c70a..975e4149c 100644 --- a/lib/compress/zstdmt_compress.c +++ b/lib/compress/zstdmt_compress.c @@ -1278,11 +1278,16 @@ size_t ZSTDMT_initCStream_internal( { /* If ldm is enabled we need windowSize space. */ size_t const windowSize = mtctx->params.ldmParams.enableLdm ? (1U << mtctx->params.cParams.windowLog) : 0; - /* Two buffers of slack, plus extra space for the overlap */ - size_t const nbWorkers = MAX(mtctx->params.nbWorkers, 1); - size_t const nbSlackBuffers = MIN(nbWorkers, 2) + (mtctx->targetPrefixSize > 0); + /* Two buffers of slack, plus extra space for the overlap + * This is the minimum slack that LDM works with. One extra because + * flush might waste up to targetSectionSize-1 bytes. Another extra + * for the overlap (if > 0), then one to fill which doesn't overlap + * with the LDM window. + */ + size_t const nbSlackBuffers = 2 + (mtctx->targetPrefixSize > 0); size_t const slackSize = mtctx->targetSectionSize * nbSlackBuffers; /* Compute the total size, and always have enough slack */ + size_t const nbWorkers = MAX(mtctx->params.nbWorkers, 1); size_t const sectionsSize = mtctx->targetSectionSize * nbWorkers; size_t const capacity = MAX(windowSize, sectionsSize) + slackSize; if (mtctx->roundBuff.capacity < capacity) {