Method 1: maxcpus
Using maxcpus parameter : Add kernel parameter maxcpus=N in /boot/grub2/grub.cfg.
It is not possible to disable CPU0 on Red Hat Enterprise Linux systems.
n=0 is a special case, it is equivalent to "nosmp", which also disables the IO APIC.
Provide the CPU count which you want to use in your system by using maxcpus variable under 'GRUB_CMDLINE_LINUX' in "/etc/sysconfig/grub" as shown below I am limiting the CPU count to 6
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="novga panic=1 numa=off crashkernel=auto noht rhgb quiet console=tty0 maxcpus=6"
GRUB_DISABLE_RECOVERY="true"
Next regenerate the grub2 configuration file using
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-693.5.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.5.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-1334797d644549a8aa195f756eaab1e1
Found initrd image: /boot/initramfs-0-rescue-1334797d644549a8aa195f756eaab1e1.img
done
Validate your changes
linux16 /vmlinuz-3.10.0-693.5.2.el7.x86_64 root=/dev/mapper/os-root ro novga panic=1 numa=off crashkernel=auto rhgb quiet console=tty0 maxcpus=6
linux16 /vmlinuz-0-rescue-1334797d644549a8aa195f756eaab1e1 root=/dev/mapper/os-root ro novga panic=1 numa=off crashkernel=auto rhgb quiet console=tty0 maxcpus=6
Due to a known BUG in systemd kernel adds an udev rule that automatically sets CPUs to "online" state after they appear in the system hence that must be disabled for maxcpus to work
This rule can be disabled using the below command in /usr/lib/udev/rules.d/40-redhat.rules file
Here we are commenting out below line which enables CPU during the reboot of the system
Next rebuild the initramfs
Next reboot the blade to make the changes affect and validate the number of cpus once the node comes up
BOOT_IMAGE=/vmlinuz-3.10.0-693.5.2.el7.x86_64 root=/dev/mapper/os-root ro novga panic=1 numa=off crashkernel=auto rhgb quiet console=tty0 maxcpus=6
6
NUMA node(s): 1
NUMA node0 CPU(s): 0-5
As you see now we have only 6 cpu cores.
Method 2: nr_cpus
Using nr_cpus parameter : Add kernel parameter nr_cpus=N in /boot/grub2/grub.cfg
It is not possible to disable CPU0 on Red Hat Enterprise Linux systems.
Provide the CPU count which you want to use in your system by using maxcpus variable under GRUB_CMDLINE_LINUX in "/etc/sysconfig/grub" as shown below I am limiting the CPU count to 5
GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT="console"
GRUB_CMDLINE_LINUX="novga panic=1 numa=off crashkernel=auto rhgb quiet console=tty0 nr_cpus=5"
GRUB_DISABLE_RECOVERY="true"
Next regenerate the grub2 configuration file using
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.10.0-693.5.2.el7.x86_64
Found initrd image: /boot/initramfs-3.10.0-693.5.2.el7.x86_64.img
Found linux image: /boot/vmlinuz-0-rescue-1be8540dbd0449f4b6c1a94f585eb350
Found initrd image: /boot/initramfs-0-rescue-1be8540dbd0449f4b6c1a94f585eb350.img
done
Validate your changes
linux16 /vmlinuz-3.10.0-693.5.2.el7.x86_64 root=/dev/mapper/os-root ro novga panic=1 numa=off crashkernel=auto noht rhgb quiet console=tty0 nr_cpus=5
linux16 /vmlinuz-0-rescue-1be8540dbd0449f4b6c1a94f585eb350 root=/dev/mapper/os-root ro novga panic=1 numa=off crashkernel=auto rhgb quiet console=tty0 nr_cpus=5
Before going for reboot lets check the available cores
16
Next reboot the server to activate the changes
Once the system comes up validate the cpu count active on the system
processor : 0
processor : 1
processor : 2
processor : 3
processor : 4
Method 3
Manually disable individual CPU using "/sys/devices/system/cpu/cpu<id>/online" file
I hope the article was useful.