All Products
Search
Document Center

:What do I do if the task: Cannot allocate memory error message appears when I start a service on a Linux instance?

Last Updated:Jul 05, 2024

Problem description

When you start a service process on a Linux Elastic Compute Service (ECS) instance, the task: Cannot allocate memory error message appears as shown in the following figure.Cannot allocate memory

Cause

The issue may occur because the maximum number of system processes that are allowed to concurrently run is exceeded.

In Linux kernel, the kernel.pid_max parameter specifies the maximum number of processes that are allowed to concurrently run. If the number of processes that are running in the operating system exceeds the value of the kernel.pid_max parameter, the operating system cannot create new processes and displays the following error message: task: Cannot allocate memory.
Note If the number of processes that are concurrently running in the operating system exceeds the two thirds of the value of the kernel.pid_max parameter, we recommend that you increase the value of the kernel.pid_max parameter to ensure that other services can run as expected.

Solution

Perform the following steps to increase the value of the kernel.pid_max parameter based on your business requirements.
Note For 64-bit operating systems, the maximum value of the kernel.pid_max parameter is 222. For 32-bit operating systems, the maximum value of the kernel.pid_max parameter is 32,768.
  1. Connect to the Linux ECS instance.
    For more information, see Connection method overview.
  2. Check whether the number of processes that are running in the operating system exceeds the maximum number allowed.
    • Run the following command to view the number of processes that are running in the operating system:
      ps -eLf | wc -l
    • Run the following command to view the maximum number of processes that are allowed to concurrently run in the operating system:
      sysctl kernel.pid_max

    If the number of processes that are running in the operating system exceeds the maximum number allowed, proceed to Step 3.

  3. Run one of the following commands to increase the value of the kernel.pid_max parameter. In the commands, replace XXXX with a new value.
    • Run one of the following commands to temporarily increase the value of the kernel.pid_max parameter. After the Linux ECS instance is restarted, the kernel.pid_max parameter is automatically set to the original value.
      • sysctl -w kernel.pid_max=XXXX
      • echo XXXX> /proc/sys/kernel/pid_max
    • Run the following commands to permanently increase the value of the kernel.pid_max parameter. The new value remains in effect regardless of the instance status.
      echo "kernel.pid_max=XXXX" >> /etc/sysctl.conf
      sysctl -p
    After you change the value of the kernel.pid_max parameter, the new value immediately takes effect.