Imagine an enterprise having to correctly add dimension to all their systems right from the start. In my experience, this is very difficult. You will either under-dimension it, and your customers will complain about performance at some point, or you will over-dimension it, and then the machine will sit there, idling about, which is not optimal either. This is the reason hardware vendors have come up with hot-add and hot-remove resources.
This allows a system to have its CPUs, memory, and/or disks to be upgraded/downgraded without the need for a shutdown. A KVM implements a similar functionality for its guests. This post outlines the steps to reduce or limit the CPUs in a CentOS/RHEL 5,6 systems. There are 2 ways in which you can reduce the CPUs :
- Online/Temporary (without reboot)
- Persistent (requires a reboot)
Online/Temporary (without reboot)
1. Count the number of CPUs currently present in the system:
# grep "processor" /proc/cpuinfo processor : 0 processor : 1 processor : 2 processor : 3
As you can see, we have 4 CPUs present on the system currently.
2. For the example of this post, we will disable the 2 CPUs (cpu3 and cpu2).
# echo 0 > /sys/devices/system/cpu/cpu3/online # echo 0 > /sys/devices/system/cpu/cpu2/online
3. Verify the count of CPUs again. You can see only 2 CPUs present now.
# grep "processor" /proc/cpuinfo processor : 0 processor : 1
4. To re-enable the 2 CPUs back, execute the below commands:
# echo 1 > /sys/devices/system/cpu/cpu3/online # echo 1 > /sys/devices/system/cpu/cpu2/online
Persistent (requires reboot)
For permanent changes, you can use any of the 2 methods mentioned below:
1. Using maxcpus parameter
Add kernel parameter maxcpus=N in /etc/grub.conf. Please take a backup of the grub configuration before doing the changes.
# vi /etc/grub.conf
linux16 /vmlinuz-3.8.13-55.1.6.el7uek.x86_64 root=/dev/mapper/ol-root ro crashkernel=auto rd.lvm.lv=ol/root rd.lvm.lv=ol/swap
rhgb quiet maxcpus=N
initrd16 /initramfs-3.8.13-55.1.6.el7uek.x86_64.img
2. Using nr_cpus parameter
Add kernel parameter nr_cpus=N in /etc/grub2.cfg. Please take a backup of the grub configuration before doing the changes.
linux16 /vmlinuz-3.8.13-55.1.6.el7uek.x86_64 root=/dev/mapper/ol-root ro crashkernel=auto rd.lvm.lv=ol/root rd.lvm.lv=ol/swap
rhgb quiet nr_cpus=N
initrd16 /initramfs-3.8.13-55.1.6.el7uek.x86_64.img