• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

Reducing/Limiting the CPUs in CentOS/RHEL 5,6

by admin

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 :

  1. Online/Temporary (without reboot)
  2. 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
Note: This method is online and the CPUs are disabled immediately. But the method does not persist across reboots.

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
Note: It is not possible to disable CPU0
How to Enable/Disable CPUs (Limiting CPU count) in CentOS / RHEL

Filed Under: CentOS/RHEL 5, CentOS/RHEL 6, Linux

Some more articles you might also be interested in …

  1. CentOS / RHEL : How to block incoming and outgoing ports using iptables
  2. pngcheck Command Examples in Linux
  3. Features of the “Btrfs” Filesystem
  4. cpufreq-info Command Examples in Linux
  5. bpftool: command not found
  6. How to Back Up and Restore XFS File Systems (xfsdump / xfsrestore)
  7. top Command Examples in Linux
  8. grep Command Examples in Linux (Cheat Sheet)
  9. How to move /var on a separate disk as a separate mount point (Online)
  10. pdfxup: command not found

You May Also Like

Primary Sidebar

Recent Posts

  • qm Command Examples in Linux
  • qm wait Command Examples in Linux
  • qm start Command Examples in Linux
  • qm snapshot Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright