diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2022-04-11 22:20:49 +0300 |
---|---|---|
committer | Lasse Collin <lasse.collin@tukaani.org> | 2022-04-12 00:04:30 +0300 |
commit | cad299008cf73ec566f0662a9cf2b94f86a99659 (patch) | |
tree | 0d86b2942ddf001ce24fb74154c30e9b79381e62 /src/xz/coder.c | |
parent | liblzma: Threaded decoder: Improve setting of pending_error. (diff) | |
download | xz-cad299008cf73ec566f0662a9cf2b94f86a99659.tar.xz |
xz: Add --memlimit-mt-decompress along with a default limit value.
--memlimit-mt-decompress allows specifying the limit for
multithreaded decompression. This matches memlimit_threading in
liblzma. This limit can only affect the number of threads being
used; it will never prevent xz from decompressing a file. The
old --memlimit-decompress option is still used at the same time.
If the value of --memlimit-decompress (the default value or
one specified by the user) is less than the value of
--memlimit-mt-decompress , then --memlimit-mt-decompress is
reduced to match --memlimit-decompress.
Man page wasn't updated yet.
Diffstat (limited to 'src/xz/coder.c')
-rw-r--r-- | src/xz/coder.c | 34 |
1 files changed, 11 insertions, 23 deletions
diff --git a/src/xz/coder.c b/src/xz/coder.c index dc70f1cc..b5f7c392 100644 --- a/src/xz/coder.c +++ b/src/xz/coder.c @@ -524,32 +524,20 @@ coder_init(file_pair *pair) mt_options.flags = flags; mt_options.threads = hardware_threads_get(); - - // TODO: Support --memlimit-threading=LIMIT. mt_options.memlimit_stop = hardware_memlimit_get(MODE_DECOMPRESS); + + // If single-threaded mode was requested, set the + // memlimit for threading to zero. This forces the + // decoder to use single-threaded mode which matches + // the behavior of lzma_stream_decoder(). + // + // Otherwise use the limit for threaded decompression + // which has a sane default (users are still free to + // make it insanely high though). mt_options.memlimit_threading - = mt_options.memlimit_stop; - - if (mt_options.threads == 1) { - // Single-threaded mode was requested. Force - // the decoder to use minimal memory, matching - // the behavior of lzma_stream_decoder(). - mt_options.memlimit_threading = 0; - - } else if (mt_options.memlimit_threading - == UINT64_MAX) { - // TODO: Support --memlimit-threading=LIMIT. - // - // If lzma_physmem() fails, it returns 0 and - // we end up with a single thread. - // - // NOTE: It is assential that we never end up - // with an effectively infinite value in - // memlimit_threading! - mt_options.memlimit_threading - = lzma_physmem() / 4; - } + = mt_options.threads == 1 + ? 0 : hardware_memlimit_mtdec_get(); ret = lzma_stream_decoder_mt(&strm, &mt_options); # else |