How to Disable CPU Cores in Linux (How to Reduce Energy Consumption on a Server)

| F.A.Q.Support

How to Disable CPU Cores in Linux (How to Reduce Energy Consumption on a Server)

Disabling CPU cores can be beneficial if you want to optimize power consumption or troubleshoot performance issues. Fortunately, Linux provides methods for managing CPU cores, allowing efficient resource control. To disable CPU cores in Linux, you can use several methods. Depending on whether you want to do it temporarily (until the next reboot) or permanently, you can choose the appropriate method.

Jak wyłączyć rdzenie CPU w Linuksie (jak ograniczyć zużycie energii przez procesor?)

Temporary Disabling of CPU Cores

Before disabling CPU cores, we should first check which cores are available. You can check the available cores in the system using the command ls /sys/devices/system/cpu/

$ ls /sys/devices/system/cpu/
cpu0  cpu10  cpu12  cpu14  cpu2  cpu4  cpu6  cpu8 
cpu1  cpu11  cpu13  cpu15  cpu3  cpu5  cpu7  cpu9 ...

You will see a list like cpu0, cpu1, etc. — each corresponding to a single processor core.

Alternatively, you can use the lscpu command:

$ lscpu
Architecture:            x86_64
 CPU op-mode(s):        32-bit, 64-bit
 Address sizes:         39 bits physical, 48 bits virtual
 Byte Order:            Little Endian
CPU(s):                  16
 On-line CPU(s) list:   0,13-15
Off-line CPU(s) list:  1-12

Temporary Disabling of CPU Cores

Using the echo command with /sys/devices/system/cpu:

You can temporarily disable a CPU core by setting its status to "offline." For example, to disable CPU core 1:

echo "0" > /sys/devices/system/cpu/cpu1/online

To re-enable the core, set its status to "online":

echo "1" > /sys/devices/system/cpu/cpu1/online

Alternatively, we can iterate over a range of CPU cores using a loop:

for x in /sys/devices/system/cpu/cpu[1-2]*/online; do
  echo 0 > "$x"
done

This script will disable CPU cores cpu1 and cpu2.

Permanent Disabling of CPU Cores

Adding an Option to GRUB:

You can modify the GRUB bootloader settings to disable cores on every system startup. To do this:

Edit the GRUB configuration file, usually located at /etc/default/grub:

sudo nano /etc/default/grub

Find the line starting with GRUB_CMDLINE_LINUX_DEFAULT and add the option maxcpus=N, where N is the number of active cores you want (e.g., maxcpus=2 to use only two cores):

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash maxcpus=2"

Save the file and update the GRUB configuration:

sudo update-grub

Restart the system to apply the changes.

Note:

Disabling CPU cores may lead to decreased system performance. Use these methods cautiously, especially on production systems.

Related pages:

  1. How to Change CPU Performance on Linux? (Scaling Governor) (Tuning)
  2. How to install Java on Linux to use IPMI KVM Supermicro? How to open launch.jnlp? How to open jviewer.jnlp? (IPMI Troubleshooting)
  3. Smartmontools - SMART data analysis tool for HDD, SSD, NVMe drives
  4. Erasing data from disk (dd, hdparm, shred) - How to erase data from disk?
  5. Automatic power-on after a power outage on the Supermicro X13SCH-LN4F motherboard