Limit 7-Zip to Specific CPU Core Affinity
7-Zip does not feature a native internal switch to set CPU core
affinity masks directly, but its processes can easily be constrained to
specific processor cores using standard operating system tools. While
7-Zip includes built-in controls to limit thread counts, binding
compression workloads to predetermined logical or physical cores
requires executing the process through utilities like Windows Command
Prompt, PowerShell, Task Manager, or Linux taskset.
Thread Count vs. CPU Affinity in 7-Zip
7-Zip natively includes the -mmt switch (or the "CPU
threads" field in the graphical interface) to control how many
simultaneous threads the compression engine spawns. However, this
parameter only defines thread quantity, leaving the operating system's
scheduler free to migrate those threads across any available CPU core.
To enforce a specific affinity mask, external process-level management
is required.
Method
1: Using the Windows Command Line (start /affinity)
The most common way to automate affinity masks for
7z.exe is the Windows start command, which
accepts an affinity mask in hexadecimal format.
To calculate the mask, convert the desired binary core selection to hexadecimal:
- Core 0 only: Binary
0001= Hex1 - Cores 0 and 1: Binary
0011= Hex3 - Cores 2 and 3: Binary
1100= HexC - Cores 4 through 7: Binary
11110000= HexF0
Launch 7-Zip bound to Cores 0 and 1 with this syntax:
start /affinity 3 "" "C:\Program Files\7-Zip\7z.exe" a -mmt=2 archive.7z "C:\SourceFolder"Setting -mmt to match the number of allocated cores
avoids excessive context switching among threads restricted to the
defined mask.
Method 2: Using Windows Task Manager
For running tasks or GUI compression jobs:
- Open Task Manager
(
Ctrl + Shift + Esc). - Navigate to the Details tab.
- Locate
7z.exeor7zG.exe. - Right-click the process and select Set affinity.
- Check only the CPU cores you wish to allocate to the task and click OK.
Method 3: Using PowerShell
PowerShell can launch 7-Zip and immediately assign an affinity mask using a decimal representation of the core mask:
$process = Start-Process -FilePath "C:\Program Files\7-Zip\7z.exe" -ArgumentList "a archive.7z C:\SourceFolder" -PassThru
$process.ProcessorAffinity = [IntPtr]3In this example, 3 corresponds to binary
0011, assigning the process strictly to CPU 0 and CPU
1.
Method 4: Using Linux
(taskset)
If running p7zip or the official 7-Zip Linux binary, use
the taskset command to constrain core usage by list or
mask:
taskset -c 0,1 7zz a -mmt=2 archive.7z /path/to/folderThis ensures the 7-Zip process and all child threads remain restricted to CPU 0 and CPU 1 for the duration of the archive operation.