如何防止使用特定的CPU内核?

是否可以防止Linux中的操作系统使用CPU内核? maxcpus=<n>引导参数可防止在操作系统中看到指定数量的内核。 我希望所有内核都可见,但只有一些内核被操作系统用于调度进程。

编辑:这是必需的,以确保关键的进程可以安排在一个核心,并保持不是绝对重要的,但高度CPU密集型进程可以相互竞争其他核心。 这是在CentOS 6上。

在内核命令行上使用isolcpus参数来隔离某些内核与用户空间任务。 从内核引导参数文档引用:

isolcpus = [KNL,SMP]从通用调度程序中分离出CPU。 格式:,…或 – (必须是升序的正范围)或混合,…, –

  This option can be used to specify one or more CPUs to isolate from the general SMP balancing and scheduling algorithms. You can move a process onto or off an "isolated" CPU via the CPU affinity syscalls or cpuset. <cpu number> begins at 0 and the maximum value is "number of CPUs in system - 1". This option is the preferred way to isolate CPUs. The alternative -- manually setting the CPU mask of all tasks in the system -- can cause problems and suboptimal load balancer performance. 

您可以使用echo 0 > /sys/devices/system/cpu/cpu0/online禁用处理器(core0),并使用echo 1 > /sys/devices/system/cpu/cpu0/online

你可以用cat /proc/cpuinfo来validation状态

通用答案 …直到你提供更多的信息。

您可能希望使用您的发行版的CPU隔离工具。 此外,cgroups可能是相关的,具体取决于你想要完成什么。

taskset和cpuset之间的区别


编辑:

你正在寻找一个CPU屏蔽。 在EL6上,您可能需要阅读cgroups和cgred守护程序和cgconfig软件包。

例如:

/etc/cgconfig.conf:

 mount { cpuset = /cgroup/cpuset; cpu = /cgroup/cpu; cpuacct = /cgroup/cpuacct; memory = /cgroup/memory; devices = /cgroup/devices; freezer = /cgroup/freezer; net_cls = /cgroup/net_cls; blkio = /cgroup/blkio; } group ppro-users { cpuset { cpuset.mems="0-1"; cpuset.cpus="2-7,14-19"; } cpu { cpu.shares = 1000; } memory { memory.limit_in_bytes = 40960m; } } 

上面的代码片段将“ppro-users”cgroup中的进程限制在特定的CPU上。 我通过使用cgred包来识别和pipe理应该属于该cgroup的进程。

/etc/cgrules.conf

 # Example: #<user> <controllers> <destination> #@student cpu,memory usergroup/student/ #peter cpu test1/ #% memory test2/ admin cpu,cpuset,memory ppro-users/ @ppro:dbc cpu,cpuset,memory ppro-users/