Linux Limiting or restricting SMP CPU activation in SMP mode

by on May 10, 2006 · 2 comments· LAST UPDATED November 6, 2007

in , ,

Q. I would like to restrict number of CPU activated for some software licensing issues under Linux kernel 2.6.xx.. How can I limit the number of CPUs activated in SMP mode?

A. Pass a special parameter called maxcpus to kernel. It specify maximum number of processors that an SMP Linux kernel should make use of. For example if you have four cpus and would like to use 2 CPU then pass 2 as a number to maxcpus.
maxcpus=NUMBER

This is useful to test different software performances and configurations. Some commercial software such as ERP software or Oracle are licenced per CPU. In such a case maxcpus is a life saver.

Edit your grub.conf file:
# vi grub.conf
Append parameter maxcpus at the end of Kernel line. A the end it should read as follows:
kernel /boot/vmlinuz-2.6.13-Ora10g root=/dev/sda1 ro maxcpus=2
Save and close the file. Reboot system:
# reboot
Alternatively, you need to enter parameter at grub or lilo boot prompt. For example if you are using Grub as a boot loader, at Grub prompt press 'e' to edit command before booting.

  1. Select second line
  2. Again, press 'e' to edit selected command
  3. Select kernel line
  4. Append maxcpus=2 parameters.
  5. Press b to boot system

See also:

UPDATED for accuracy.

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!
1 Zafar February 1, 2011 at 5:54 am

Hi,

I have a question Here we can limit the number of the CPU to how many we want, My system is having two core I want to run Linux in CPU 0 and my application programme in CPU 1 Is there any way to achieve the same.

2 Robert Ruedisueli February 21, 2014 at 10:05 pm

Yes, you can set the CPU affinity starting with recent Kernel versions.

You can do this with either SchedTools or do it by hand with a multi-purpose tool like htop.

Still, unless you are wanting to reserve one CPU to always be available for certain ultra-high-priority tasks, there is no real performance advantage to setting CPU affinity in Linux. The Linux kernel handles CPU affinity fine on it’s own for modern multi-core processors that have no penalty for non-native memory access.

There are no real desktop applications that can take advantage of CPU affinity, other than as a workaround for multi-threading bugs.

Comments on this FAQ are closed. If you'd like to continue the discussion on this topic, you can do so at our forum.

Tagged as: , , , , , , , ,

Previous post:

Next post: