From 75689838e4e3fd1657315cc1d0afc383bb8e0375 Mon Sep 17 00:00:00 2001 From: Yann Collet Date: Fri, 9 Feb 2018 15:53:27 -0800 Subject: [PATCH] specify new command --single-thread --- programs/fileio.c | 2 +- programs/zstd.1.md | 10 ++++++++-- programs/zstdcli.c | 19 ++++++++++--------- tests/playTests.sh | 1 + 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/programs/fileio.c b/programs/fileio.c index 0cc807a11..d344b8f69 100644 --- a/programs/fileio.c +++ b/programs/fileio.c @@ -461,7 +461,7 @@ static cRess_t FIO_createCResources(const char* dictFileName, int cLevel, CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_p_compressionStrategy, (U32)comprParams->strategy) ); /* multi-threading */ #ifdef ZSTD_MULTITHREAD - DISPLAYLEVEL(5,"set nb threads = %u \n", g_nbWorkers); + DISPLAYLEVEL(5,"set nb workers = %u \n", g_nbWorkers); CHECK( ZSTD_CCtx_setParameter(ress.cctx, ZSTD_p_nbWorkers, g_nbWorkers) ); #endif /* dictionary */ diff --git a/programs/zstd.1.md b/programs/zstd.1.md index 4d9ec2fce..c970c5cbb 100644 --- a/programs/zstd.1.md +++ b/programs/zstd.1.md @@ -116,10 +116,16 @@ the last one takes effect. Note: If `windowLog` is set to larger than 27, `--long=windowLog` or `--memory=windowSize` needs to be passed to the decompressor. * `-T#`, `--threads=#`: - Compress using `#` threads (default: 1). + Compress using `#` working threads (default: 1). If `#` is 0, attempt to detect and use the number of physical CPU cores. - In all cases, the nb of threads is capped to ZSTDMT_NBTHREADS_MAX==256. + In all cases, the nb of threads is capped to ZSTDMT_NBTHREADS_MAX==200. This modifier does nothing if `zstd` is compiled without multithread support. +* `--single-thread`: + Does not spawn a thread for compression, use caller thread instead. + This is the only available mode when multithread support is disabled. + In this mode, compression is serialized with I/O. + (This is different from `-T1`, which spawns 1 compression thread in parallel of I/O). + Single-thread mode also features lower memory usage. * `-D file`: use `file` as Dictionary to compress or decompress FILE(s) * `--nodictID`: diff --git a/programs/zstdcli.c b/programs/zstdcli.c index 015dc5e4c..6d7957c80 100644 --- a/programs/zstdcli.c +++ b/programs/zstdcli.c @@ -135,7 +135,7 @@ static int usage_advanced(const char* programName) DISPLAY( "--ultra : enable levels beyond %i, up to %i (requires more memory)\n", ZSTDCLI_CLEVEL_MAX, ZSTD_maxCLevel()); DISPLAY( "--long[=#] : enable long distance matching with given window log (default: %u)\n", g_defaultMaxWindowLog); #ifdef ZSTD_MULTITHREAD - DISPLAY( " -T# : use # threads for compression (default: 1) \n"); + DISPLAY( " -T# : spawns # compression threads (default: 1) \n"); DISPLAY( " -B# : select size of each job (default: 0==automatic) \n"); #endif DISPLAY( "--no-dictID : don't write dictID into header (dictionary compression)\n"); @@ -366,21 +366,21 @@ typedef enum { zom_compress, zom_decompress, zom_test, zom_bench, zom_train, zom int main(int argCount, const char* argv[]) { int argNb, - forceStdout=0, followLinks=0, + forceStdout=0, + lastCommand = 0, + ldmFlag = 0, main_pause=0, - nextEntryIsDictionary=0, - operationResult=0, + nbWorkers = 1, nextArgumentIsOutFileName=0, nextArgumentIsMaxDict=0, nextArgumentIsDictID=0, nextArgumentsAreFiles=0, - ultra=0, - lastCommand = 0, - nbWorkers = 1, - setRealTimePrio = 0, + nextEntryIsDictionary=0, + operationResult=0, separateFiles = 0, - ldmFlag = 0; + setRealTimePrio = 0, + ultra=0; unsigned bench_nbSeconds = 3; /* would be better if this value was synchronized from bench */ size_t blockSize = 0; zstd_operation_mode operation = zom_compress; @@ -481,6 +481,7 @@ int main(int argCount, const char* argv[]) if (!strcmp(argument, "--keep")) { FIO_setRemoveSrcFile(0); continue; } if (!strcmp(argument, "--rm")) { FIO_setRemoveSrcFile(1); continue; } if (!strcmp(argument, "--priority=rt")) { setRealTimePrio = 1; continue; } + if (!strcmp(argument, "--single-thread")) { nbWorkers = 0; continue; } #ifdef ZSTD_GZCOMPRESS if (!strcmp(argument, "--format=gzip")) { suffix = GZ_EXTENSION; FIO_setCompressionType(FIO_gzipCompression); continue; } #endif diff --git a/tests/playTests.sh b/tests/playTests.sh index 0e12ec8e7..258c9c75b 100755 --- a/tests/playTests.sh +++ b/tests/playTests.sh @@ -634,6 +634,7 @@ roundTripTest -g518K "19 --long" fileRoundTripTest -g5M "3 --long" +roundTripTest -g96K "5 --single-thread" if [ -n "$hasMT" ] then $ECHO "\n===> zstdmt round-trip tests "