You need to enable JavaScript to run this app.
Elastic Compute Service

Elastic Compute Service

Copy page
Download PDF
Linux operating system issue
When starting a service in the Linux instance, the prompt appears: task: Cannot allocate memory
Copy page
Download PDF
When starting a service in the Linux instance, the prompt appears: task: Cannot allocate memory
You can resolve the error of task: Cannot allocate memory that occurs when an ECS instance starts a certain service process by increasing the value of kernel.pid_max.​
tip​
This operation is only applicable to kernel versions earlier than v4.1. For kernel versions v4.1 and later, you can submit a ticket or contact your account manager to obtain technical support.​
Causes​
It may be caused by the operating system exceeding the limit on the number of processes.​
The Linux kernel limits the number of processes through the kernel configuration argument kernel.pid_max. When the total number of processes running services exceeds the value of kernel.pid_max, creating new processes will result in the system prompting the error task: Cannot allocate memory.​
Procedure​
  1. Log in to the target instance. For operation details, refer to Logging in to Linux instances.​
  1. View whether the number of processes currently running in the system exceeds the maximum number of processes.​
  1. Run the following command to view the number of processes currently running in the system.​
  • ​
    ps -eLf | wc -l​
    ​
  • ​​​
  1. Execute the following command to view the maximum number of processes in the system.​
  • ​
    sysctl kernel.pid_max​
    ​
  • ​​​
  1. If the current number of running processes in the system exceeds the maximum number of processes, please adjust the kernel.pid_max configuration item to a reasonable value according to the actual business situation. Once the adjustment is complete, it will take effect immediately.​
Description​
  • After the kernel.pid_max value adjustment, it will take effect immediately.​
  • If the current number of running processes in the operating system exceeds two-thirds of the maximum number of processes (kernel.pid_max), it is also recommended to immediately increase the value of kernel.pid_max to avoid affecting subsequent business operations.​
  • Temporary Settings: Execute any one of the following commands to temporarily increase the value ofkernel.pid_max. However, it will become invalid after restarting the instance.​
  • ​
    sysctl -w kernel.pid_max=expectedPidMaxValue​
    echo expectedPidMaxValue > /proc/sys/kernel/pid_max​
    ​
tip​
Please replace expectedPidMaxValue in the command with the actual value that kernel.pid_max needs to be raised to.​
  • Permanent Settings: Execute the following command to permanently increase the value ofkernel.pid_max regardless of the instance status.​
  • ​
    echo "kernel.pid_max=expectedPidMaxValue" >> /etc/sysctl.conf​
    sysctl -p​
    ​
tip​
Please replace expectedPidMaxValue in the command with the actual value that kernel.pid_max needs to be increased to.​
Last updated: 2026.04.13 16:50:03