在grup启动时传给内核参数: isolcpus=2-15, 这里表示隔离第3到16个CPU, Linux程序只跑在第一和第二个CPU上, 空闲的CPU我们可以指定跑进程了.
这是内核文档里对内核参数的解释:
-
isolcpus= [KNL,SMP] Isolate CPUs from the general scheduler.
-
Format:
-
<cpu number>,...,<cpu number>
-
or
-
<cpu number>-<cpu number>
-
(must be a positive range in ascending order)
-
or a mixture
-
<cpu number>,...,<cpu number>-<cpu number>
-
-
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.
然后我们利用taskset程序来设置运行的程序跑在哪个CPU上, 本例是16个CPU, 用mask表示:
-
Anshion> ./test.sh &
-
[1] 684
-
Anshion> taskset -p 0x8000 684
-
pid 684's current affinity mask: 3
-
pid 684's new affinity mask: 8000
这样在top中就可以看到, 这个进程跑在15号CPU上了, top命令运行按f, 再按j, 可以显示命令运行的cpu.然后用W保存配置.
-
taskset -c 15 ./test.sh &
这样可以直接调用程序时指定跑在哪个CPU上.
阅读(7357) | 评论(0) | 转发(0) |