可用处理单元数量少于在线处理器

可用处理单元数量少于在线处理器

在基于 Ubuntu 的 Linux 上,当我运行nproc命令,它打印 2。但是当我运行它时nproc --all,它打印 8。

这意味着 8 个在线处理器中只有 2 个可用?如何让所有 8 个在线处理器都可用?它是由配置控制的吗?

答案1

您可以在运行的同一 shell 中运行以下命令吗nproc

cat /proc/$$/limits

结果:

Limit                     Soft Limit           Hard Limit           Units
Max cpu time              unlimited            unlimited            seconds
Max file size             unlimited            unlimited            bytes
Max data size             unlimited            unlimited            bytes
Max stack size            8388608              unlimited            bytes
Max core file size        0                    unlimited            bytes
Max resident set          unlimited            unlimited            bytes
Max processes             15795                15795                processes
Max open files            65536                65536                files
Max locked memory         65536                65536                bytes
Max address space         unlimited            unlimited            bytes
Max file locks            unlimited            unlimited            locks
Max pending signals       15795                15795                signals
Max msgqueue size         819200               819200               bytes
Max nice priority         0                    0
Max realtime priority     0                    0
Max realtime timeout      unlimited            unlimited            us

您可以尝试此命令来查看是否有任何 cpu 离线吗?

grep "" /sys/devices/system/cpu/cpu*/online

结果:

# grep "" /sys/devices/system/cpu/cpu*/online
/sys/devices/system/cpu/cpu1/online:1
/sys/devices/system/cpu/cpu2/online:1
/sys/devices/system/cpu/cpu3/online:1
/sys/devices/system/cpu/cpu4/online:1
/sys/devices/system/cpu/cpu5/online:1
/sys/devices/system/cpu/cpu6/online:1
/sys/devices/system/cpu/cpu7/online:1

如果任何 CPU 离线,您可以通过(例如 CPU3)将其打开并尝试nproc再次运行:

echo 1 > /sys/devices/system/cpu/cpu3/online

要全部打开它们,您可以尝试:

for x in /sys/devices/system/cpu/cpu*/online; do
  echo 1 >"$x"
done

你能一一独立尝试这8个命令吗(如果permission denied用 尝试的话sudo):

echo 1 > /sys/devices/system/cpu/cpu1/online
echo 1 > /sys/devices/system/cpu/cpu2/online
echo 1 > /sys/devices/system/cpu/cpu3/online
echo 1 > /sys/devices/system/cpu/cpu4/online
echo 1 > /sys/devices/system/cpu/cpu5/online
echo 1 > /sys/devices/system/cpu/cpu6/online
echo 1 > /sys/devices/system/cpu/cpu7/online

相关内容