在一个多core 服务器上,怎么限制RHEL识别到的cpu的数量?

117 篇文章 0 订阅
68 篇文章 0 订阅

在一个多core 服务器上,怎么限制RHEL识别到的cpu的数量?


来源于:
https://access.redhat.com/solutions/325593
How to limit number of CPU's in Red Hat Enterprise Linux on a multi-core server

适用于:
Red Hat Enterprise Linux (RHEL) 5
Red Hat Enterprise Linux (RHEL) 6
Red Hat Enterprise Linux (RHEL) 7


决议

Note : It is not possible to disable CPU0 on Red Hat Enterprise Linux systems.

There are three ways to restrict number of CPU's

[1] Using maxcpus parameter : Add kernel parameter maxcpus=N in /boot/grub/grub.conf or to the kernel line at boot time.

For Eg : Below entry will restrict server to only 2 CPU's.

Raw
title Red Hat Enterprise Linux Server (2.6.18-238.el5)
    root (hd0,0)
    kernel /vmlinuz-2.6.18-238.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet maxcpus=2
    initrd /initrd-2.6.18-238.el5.img

NOTE : maxcpus kernel parameter is not working as expected as RHEL 7 system still has all CPUs enabled after boot is complete

[2] Using nr_cpus parameter : Add kernel parameter nr_cpus=N in /boot/grub/grub.conf or to the kernel line at boot time.

For Eg : Below entry will restrict server to only 2 CPU's.

Raw
title Red Hat Enterprise Linux Server (2.6.18-238.el5)
    root (hd0,0)
    kernel /vmlinuz-2.6.18-238.el5 ro root=/dev/VolGroup00/LogVol00 rhgb quiet nr_cpus=2
    initrd /initrd-2.6.18-238.el5.img

NOTE : After enabling above parameter it is not possible to HOT plug more CPU's Online.
NOTE : Supported in Red Hat Enterprise Linux 7

[3] Disabling CPU Online : At runtime it is possible to disable cpu cores with the following commands (Assuming a 4 core system):

Raw
# echo 0 > /sys/devices/system/cpu/cpu3/online
# echo 0 > /sys/devices/system/cpu/cpu2/online
# echo 0 > /sys/devices/system/cpu/cpu1/online
  • Number of cores can be verified with the following command :-
Raw
# grep "processor" /proc/cpuinfo
 processor       : 0
  • The cpu cores can be reactivated again by below command. These settings are not persistent across reboot.
Raw
# echo 1 > /sys/devices/system/cpu/cpu3/online
# echo 1 > /sys/devices/system/cpu/cpu2/online
# echo 1 > /sys/devices/system/cpu/cpu1/online


# grep "processor" /proc/cpuinfo
 processor       : 0
 processor       : 1
 processor       : 2
 processor       : 3

NOTE : Supported in Red Hat Enterprise Linux 7

根源

nr_cpus= [SMP] Maximum number of processors that an SMP kernel could support. nr_cpus=n : n >= 1 limits the kernel to supporting 'n' processors. Later in runtime you can not use hotplug cpu feature to put more cpu back to online, just like you compile the kernel NR_CPUS=n.

maxcpus= [SMP] Maximum number of processors that an SMP kernel should make use of. maxcpus=n : n >= 0 limits the kernel to using 'n' processors. n=0 is a special case, it is equivalent to "nosmp", which also disables the IO APIC.

nosmp [SMP] Tells an SMP kernel to act as a UP kernel, and disable the IO APIC. legacy for "maxcpus=0".


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值