How to Set CPU Threads in 7-Zip CLI
This article explains how to control CPU thread allocation in the 7-Zip command-line interface (CLI). By using the multithreading switch, you can specify exactly how many processor cores 7-Zip utilizes, allowing you to maximize compression speed or limit resource consumption to keep your system responsive during background tasks.
The CPU Thread Switch: -mmt
The switch used to control CPU thread allocation in the 7-Zip CLI is
-mmt.
This parameter tells the 7-Zip compression engine how many
simultaneous threads to create. It can be written as
-mmt{N}, where {N} is the number of threads,
or combined with boolean values to turn multithreading on or off.
Syntax and Parameters
-mmt=onor-mmt: Enables multithreading using the default number of threads detected for your CPU.-mmt=off: Disables multithreading entirely, forcing 7-Zip to run on a single thread.-mmt={N}: Sets the thread count to a specific number N (e.g.,-mmt=4limits execution to 4 threads).
Note: The equals sign (=) is optional. For example,
-mmt4 and -mmt=4 function identically.
Command Examples
1. Limit Compression to 4 Threads
To compress a directory using four specific threads:
7z a -mmt=4 archive.7z /path/to/files2. Maximize Performance
To utilize all available CPU threads (for example, on an 8-core, 16-thread processor):
7z a -mmt=16 archive.7z /path/to/files3. Run in the Background (Single Thread)
To ensure 7-Zip does not impact other running applications, restrict it to a single CPU core:
7z a -mmt=off archive.7z /path/to/filesImportant Considerations
- Compression Algorithm Support: Multithreading behavior depends heavily on the compression algorithm. LZMA2 handles high thread counts exceptionally well, whereas the older LZMA format only supports up to 2 threads for compression. Formats like BZip2 also scale well with multithreading.
- Memory Usage: Increasing the thread count increases the amount of RAM required for the operation, particularly when using large dictionary sizes.
- Decompression Limitations: For
.7zarchives, decompression is typically single-threaded unless using algorithms like BZip2 or chunks compressed independently under specific LZMA2 configurations.