How to Disable Multithreading and Adjust EC2 CPU Cores?
Amazon Elastic Compute Cloud allows you to customize the virtual central processing unit configuration of an instance during launch or while the instance is stopped. Through the Optimize CPU feature, you can specify the exact number of physical CPU cores to remain active and choose whether to disable simultaneous multithreading, such as Intel Hyper-Threading. Adjusting these CPU options helps reduce per-core software licensing costs for commercial databases and enterprise applications while also optimizing performance for high-performance computing workloads that benefit from dedicated single-threaded core execution.
Understanding Amazon EC2 CPU Options
Most general-purpose, compute-optimized, and memory-optimized Amazon EC2 instance types map two virtual CPUs (vCPUs) to a single physical processor core through simultaneous multithreading (SMT). You can define custom CPU options using two main parameters:
- CoreCount: The number of physical CPU cores allocated to the instance.
- ThreadsPerCore: The number of threads active on each physical core. Setting this value to \(1\) disables simultaneous multithreading, whereas setting it to \(2\) retains the default multithreaded behavior.
The total number of active vCPUs available to the guest operating system is determined by the following equation:
\[\text{Total vCPUs} = \text{CoreCount} \times \text{ThreadsPerCore}\]
For example, an m5.4xlarge instance provides \(16\) vCPUs by default, consisting of \(8\) physical cores with \(2\) threads per core (\(8 \times 2 = 16\)). If you set
CoreCount to \(4\) and
ThreadsPerCore to \(1\),
the instance launches with \(4\) active
vCPUs mapped to \(4\) physical cores
with multithreading disabled (\(4 \times 1 =
4\)).
Rules and Limitations
Before modifying CPU options on an EC2 instance, verify that your workload and instance type meet the following requirements:
- Instance Pricing: Specifying custom CPU options does not change the hourly price of the EC2 instance. You still pay the standard rate for the base instance size, though your third-party software licensing costs may decrease.
- Supported Instance Types: Most current-generation
Nitro-based and Xen-based instance families support custom CPU options,
with the exception of burstable performance instances (
t2,t3,t3a,t4g) and instances that already run a single thread per core by default, such as AWS Graviton (c6g,m6g,r6g) and AMD EPYC (m6a,c6a) single-threaded configurations. - Modification Timing: You can set CPU options during initial instance launch or modify them later on an existing instance after stopping it.
Configuring CPU Options via the AWS Management Console
You can configure CPU core counts and multithreading directly in the Amazon EC2 launch wizard when creating a new instance:
- Open the Amazon EC2 console and select Launch instances.
- Choose your Amazon Machine Image (AMI) and select a supported Instance type.
- Scroll down to expand the Advanced details section at the bottom of the configuration page.
- Locate the Specify CPU options setting.
- Set the Number of cores to your desired physical core count.
- To disable multithreading, change Threads per core from \(2\) to \(1\).
- Complete the remaining configuration steps and choose Launch instance.
Configuring CPU Options via the AWS CLI
You can automate custom CPU configurations using the
--cpu-options parameter in the AWS Command Line Interface
(AWS CLI).
Launching a New Instance with Custom CPU Options
Use the run-instances command with the
CoreCount and ThreadsPerCore attributes. The
following example launches an r5.4xlarge instance with
\(4\) physical cores and multithreading
disabled:
aws ec2 run-instances \
--image-id ami-0abcdef1234567890 \
--instance-type r5.4xlarge \
--cpu-options "CoreCount=4,ThreadsPerCore=1" \
--key-name my-key-pair \
--subnet-id subnet-0123456789abcdef0Modifying CPU Options on an Existing Instance
If you already have a running EC2 instance on a modern Nitro-based platform, you can change its CPU options by stopping the instance, modifying the attributes, and starting it again:
# 1. Stop the running EC2 instance
aws ec2 stop-instances --instance-ids i-1234567890abcdef0
# 2. Wait for the instance to enter the stopped state
aws ec2 wait instance-stopped --instance-ids i-1234567890abcdef0
# 3. Modify the CPU options
aws ec2 modify-instance-cpu-options \
--instance-id i-1234567890abcdef0 \
--core-count 4 \
--threads-per-core 1
# 4. Restart the instance
aws ec2 start-instances --instance-ids i-1234567890abcdef0Verifying the Configuration
Once your EC2 instance is running, you can verify the active CPU topology either through the AWS CLI or from within the operating system.
To verify using the AWS CLI, run the describe-instances
command and query the CpuOptions output:
aws ec2 describe-instances \
--instance-ids i-1234567890abcdef0 \
--query "Reservations[].Instances[].CpuOptions"This command returns a JSON object confirming the active core and thread settings:
[
{
"CoreCount": 4,
"ThreadsPerCore": 1
}
]To verify from inside a Linux guest operating system, connect to the
instance via SSH and run lscpu:
lscpu | grep -E "CPU\(s\):|Thread|Core"When simultaneous multithreading is disabled
(ThreadsPerCore=1), the Thread(s) per core
field displays 1, and the total CPU(s) value
matches the exact number of physical cores configured.