更改 cgroup pid.max 值?

Change cgroup pid.max value?

我目前正在跟踪我的 Ubuntu 服务器上的 cannot fork() 错误,我能够将其精确定位到 /sys/fs/cgroup/pids/700pid.max 值. 但是,我只能设置值 /system.slice/pids.max/user.slice/pids.max - 而不是 pids.max。另外,这些在重新启动后重置为值 max,再次强制执行全局 pids.max 值。

是否可以简单地将它从 700 更改为更高的值? root + sudo 没有帮助。

是否有其他方法可以覆盖此值?

我认为您正在寻找来自 /etc/systemd/system.confDefaultTasksMax= 指令。

您可以通过发出 systemctl show -p DefaultTasksMax:

检查运行时值
$ systemctl show -p DefaultTasksMax
DefaultTasksMax=19096

如果您想更改它,只需编辑 /etc/systemd/system.conf 中的相应指令行即可。存在类似的指令 (TasksMax=) 以在每个单元的基础上调整此设置。

相关文档[0][1] 片段:

TasksMax=N

Specify the maximum number of tasks that may be created in the unit. This ensures that the number of tasks accounted for the unit (see above) stays below a specific limit. This either takes an absolute number of tasks or a percentage value that is taken relative to the configured maximum number of tasks on the system. If assigned the special value "infinity", no tasks limit is applied. This controls the "pids.max" control group attribute. For details about this control group attribute, see Process Number Controller.

The system default for this setting may be controlled with DefaultTasksMax= in systemd-system.conf(5).

DefaultTasksMax=

Configure the default value for the per-unit TasksMax= setting. See systemd.resource-control(5) for details. This setting applies to all unit types that support resource control settings, with the exception of slice units. Defaults to 15%, which equals 4915 with the kernel's defaults on the host, but might be smaller in OS containers.

在与我的服务器托管商来回交流了很长时间之后,他们终于泄露了秘密。

我花很少的钱租了一台硬件非常强大的 V-Server。收获?您只能 运行 700 个并发任务。这就是 pids.max 值的来源并否决了 TasksMaxnumprocs 值。