How to disable or enable hyper threading on my Linux server

In my last article I had shared steps to limit CPU count on your multi core Linux system and to assign a service to a specific CPU core in CentOS / RHEL 7

Hyper threading uses processor resources more efficiently, enabling multiple threads to run on each

core. As a performance feature, it also increases processor throughput, improving overall performance on threaded software. A single physical CPU core with hyper-threading appears as two logical CPUs to an operating system.

Use below link to check the status of hyper threading on your Linux server

The recommended way to disable HT is by disabling in the BIOS, if possible but this can also be done via operating system using the below steps.

Disable HT on runtime for individual logical CPUs

Before starting let's check the lscpu stat

# lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                32
On-line CPU(s) list:   0-31
Thread(s) per core:    2
Core(s) per socket:    8
Socket(s):             2

Here it shows that there are 2 threads per core so we know most likely hyper threading is enabled

The following files will show all of the logical CPU's and their HT pair relationships

# grep -H . /sys/devices/system/cpu/cpu*/topology/thread_siblings_list

To determine which CPUs should be disabled, the threads running on the same CPU core have to be identified. The files /sys/devices/system/cpu/cpuN/topology/thread_siblings_list where N is the CPU socket number. This file will contain the logical (HT) CPU numbers for each physical socket.

# grep -H . /sys/devices/system/cpu/cpu*/topology/thread_siblings_list | sort -n -t ',' -k 2 -u

This means that CPU0 and CPU16 are threads on the same core. The same for 1 and 17 and so on. Individual, logical HT CPUs could be turned off as needed for a specific application that is bound to a physical core.

Or the following script would disable all of them, from logical CPU 16 through 31

# cat /tmp/
for i in {12..23}; do
   echo "Disabling logical HT core $i."
   echo 0 > /sys/devices/system/cpu/cpu${i}/online;

To disable individual logical CPU use the below command and replace <cpu_id> with the id from (16..31)

echo 0 > /sys/devices/system/cpu/<cpu_id>/online

To re-enable the HT

# cat /tmp/
for i in {12..23}; do
   echo "Enabling logical HT core $i."
   echo 1 > /sys/devices/system/cpu/cpu${i}/online;

Disable HT permanently

For Linux Variants with GRUB 
for example in SuSE Enterprise Linux 11

# vim /boot/grub/menu.lst
# Modified by YaST2. Last modification on Wed Nov  8 00:37:57 CET 2017
default 0
timeout 8
##YaST - activate

###Don't change this comment - YaST2 identifier: Original name: linux###
title SUSE Linux Enterprise Server 11 SP4 - 3.0.101-71.1.10543.0.PTF
    root (hd0,4)
    kernel /vmlinuz root=/dev/md1 console=ttyS0,115200 console=tty0  splash=silent crashkernel= showopts panic=1 numa=off noht
    initrd /initrd

Lastly reboot the server to activate the changes.

For Linux Variants with GRUB2
To disable hyper threading permanently append 'noht' under 'GRUB_CMDLINE_LINUX' in '/etc/sysconfig/grub' file as shown below

GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_CMDLINE_LINUX="novga panic=1 numa=off crashkernel=auto noht rhgb quiet console=tty0"

Next regenerate the grub2 configuration file using

# grub2-mkconfig -o /boot/grub2/grub.cfg
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-514.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-514.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-a311757619b943238cda551a0f1b2743
Found initrd image: /boot/initramfs-0-rescue-a311757619b943238cda551a0f1b2743.img

Lastly reboot the server to activate the changes.

IMPORTANT NOTE: In some cases the hyper threading is controlled via the BIOS of the hardware so you must also disable HT in the BIOS, disabling alone from the OS will not work

I hope the article is useful.