Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
Help Center/ Elastic Cloud Server/ Troubleshooting/ Linux ECS Issues/ What Can I Do If the Fork Process Failed and New Threads Cannot Be Created?

What Can I Do If the Fork Process Failed and New Threads Cannot Be Created?

Updated on 2024-08-15 GMT+08:00

Symptom

The following error message is displayed during command execution or log printing on Linux ECSs.

Error message 1:

root@localhost:~# free -g
            total       used       free     shared     buffers   cached 
Mem:         94          43         51        0           0        0
Swap:        19          0         19
root@localhost:~# uname -a
-bash: fork: Cannot allocate memory

Error message 2:

xxxxsshd2[23985]: fatal: setresuid 20054: Resource temporarily unavailable
xxxxsshd2[28377]: Disconnecting: fork failed: Resource temporarily unavailable
xxxxsshd2[4484]: Disconnecting: fork failed: Resource temporarily unavailable

Error message 3:

[root@ecs-xxxx ~]$ sudo docker info
runtime/cgo: pthread_create failed: Resource temporarily unavailable
SIGABRT: abort

Possible Causes

Generally, the preceding errors occur because the thread fails to be created. The possible cause is that the ECS memory is insufficient and the number of current threads reaches the configured maximum value.

Solution

  1. Log in to the management console.
  2. Monitor the ECS memory usage using the server monitoring function. For details, see Viewing ECS Metrics.
  3. Log in to an ECS as the root user and run the following command to check the message and dmesg logs:

    dmesg -T

    cat /var/log/messages
    • If the cgroup error message shown in Figure 1 is displayed, go to 8.
    • If there is no such message, go to 4.
      Figure 1 Log error
  4. Run the following command to check the total number of threads in the current system:

    ps -efL | wc -l

  5. Run the following commands to obtain two values and compare the values with the total number of system threads queried in 4:

    sysctl -a | grep pid_max

    sysctl -a | grep threads-max

    • If the total number of threads in the current system is close to either of the two values, modify the values of pid_max and threads-max. For details, see Modifying the values of pid_max and threads-max.
    • If they do not stay close, go to 6.
  1. Run the following command to determine the PID of the error process:

    ps -ef | grep Error process name

  2. Run the following command to check the limits configuration of the process based on the PID obtained in the last step:

    cat /proc/pid/limits

    Figure 2 Viewing the limits configuration of the process
    • Check the value of Max processes. If the number of threads is close to the value of Max processes, modify the value of limits. For details, see Modifying the value of limits.
    • If they do not stay close, go to 8.
  3. Run the following commands to obtain the values of pid_max and pids.current based on the log error cgroup:

    cat /sys/fs/cgroup/pids/Directory where the error in the combined logs is reported/pids.max

    cat /sys/fs/cgroup/pids/Directory where the error in the combined logs is reported/pids.current

    Figure 3 cgroup directory

    An example is as follows:

    1. Run the following command to search for the cgroup directory based on the PID of the process:

      cat /proc/pid/cgroup

      Figure 4 Searching for the cgroup directory based on the PID

      In the command output, /user.slice/user-0.slice/session-5.scope/ in the pids line can be combined with /sys/fs/cgroup/pids/ to specify the cgroup directory /sys/fs/cgroup/pids/user.slice/user-0.slice/session-5.scope/.

    2. Run the following commands to obtain the values of pid_max and pids.current based on the cgroup directory:

      cat /sys/fs/cgroup/pids/user.slice/user-0.slice/session-5.scope/pids.max

      cat /sys/fs/cgroup/pids/user.slice/user-0.slice/session-5.scope/pids.current

      • If the value of pids.current is close to that of pids.max, modify the value of cgroup. For details, see Modifying the value of cgroup.
      • If they do not stay close, submit a service ticket.

Related Commands

  • Modifying the values of pid_max and threads-max.
    1. Default parameters vary by OS version. Therefore, run the following commands to query how pid_max and threads-max is configured:

      sysctl -a | grep pid_max

      sysctl -a | grep threads-max

    2. Run the following commands to modify the values of pid_max and threads-max:

      echo 'kernel.pid_max = 4194304' >> /etc/sysctl.conf

      echo 'kernel.threads-max = 4194304' >> /etc/sysctl.conf

    3. Run the following command to make the new value be applied:

      sysctl -p

  • Modifying the value of limits
    1. Log in to the ECS as the user who starts the error reporting process and run the following command to query the current configuration of limits:

      ulimit -u

    2. Run the following commands to configure a proper upper limit for nproc based on service requirements and the current value:

      For example, run the following commands to configure 100000 for nproc as the root user:

      echo 'root soft nproc 100000' >> /etc/security/limits.conf

      echo 'root hard nproc 100000' >> /etc/security/limits.conf

    3. Log in to the ECS again and run the following command to check whether the configuration has taken effect:

      ulimit -u

      • If the command output is the value configured in 2, the configuration has taken effect. Restart the service process in this session.
      • If the command output is not the value configured in 2, submit a service ticket.
  • Modifying the value of cgroup
    • Temporary modification solution

      Run the following command to temporarily change the upper limit of the cgroup directory to the maximum value:

      echo max > /sys/fs/cgroup/pids/user.slice/user-0.slice/session-25.scope/pids.max

    • Permanent modification solution:

      Run the following command to set the cgroup directory to infinity and modify the cgroup directory that exceeds the limit:

      The value can be adjusted as required. After the modification, restart the ECS for the configuration to be applied.

      echo DefaultTasksMax=infinity >>/etc/systemd/system.conf

      echo DefaultTasksMax=infinity >>/etc/systemd/user.conf

      echo UserTasksMax=infinity >>/etc/systemd/logind.conf

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback