How Do You Disable Hyperthreading in Linux?

Problem scenario
You are running Linux with a multi-core CPU and motherboard. You want to turn off simultaneous multithreading (because in some use cases the performance can improve or you are concerned about security). What should you do?

Possible Solution #1
If you want to be able to turn it back on without rebooting, you could have a crontab job run a script at reboot. You can run "nproc" before and after you do this. The number should change before and after your turn off hyperthreading.

Often the file to change is this: /sys/devices/system/cpu/smt/control
(Both Red Hat and Debian derivative use this file.) The value should be "off" if you want to disable hyperthreading.

For alternatives, see this posting: https://serverfault.com/questions/235825/disable-hyperthreading-from-within-linux-no-access-to-bios

Possible Solution #2
Go to the BIOS or EFI. The pre-boot menus will have a way to disable hyperthreading. (We are very skeptical of a BIOS/EFI out there that does not allow you to disable it.) The benefit of this is that if a hacker gains access to your OS, they will generally not be able to turn on SMT/hyperthreading. We find this way to be more secure. Sometimes crontab jobs get deleted or users with crontab jobs get deleted or directories with initialization scripts get deleted.

Leave a comment

Your email address will not be published. Required fields are marked *