Linux multithreaded Programming-thread exit

Source: Internet
Author: User

Today analysis of the project in the process of virtual storage has been growing problem, running 10 hours virtual storage up to 121G, RSS occupied 16G very scary.

By the way, the Linux single process can create the upper limit of threads, and related content. Memory 32G 64bit System information is as follows:

Linux threads are used by the main process to dynamically create and exit threads based on how much of the request. View the in-process partial memory allocations through the Pmap-x PID:

Found a large number of the following occupancy:

The query shows that [anon] is not actually allocated memory, that is, virtual storage; The following command calculates a total of 11,946, each corresponding to a total size of 10M 119460≈119g

1 cat process_info.txt |grep 10240|wc-l

Good to this probably to locate, is this part of virtual storage occupies too much;

To view system process virtual Storage limits:

From the penultimate, the system has no limit to the process virtual storage. Stack size is 10M and [anon] each item is equal in size, now suspect that the thread is created without releasing memory

Go back to see the code, find that each worker thread has called pthread_exit, and then further analyze the discovery chain thread did not call Pthread_detach before calling Pthread_exit,

Causes the thread to call Pthread_exit, but the system does not actually release the resources that the thread occupies.

Summarize

Two ways of solving this:

1. Create thread set thread properties to

1 pthread_attr_init (&attr);

2 pthread_attr_setdetachstate (&attr, pthread_create_detached);

2. The first line of the thread function is called

1 pthread_detach (pthread_self ());

By the way, the following information is viewed in the following system:

To view the maximum number of system processes and threads:

Process Upper limit is: 32768

The upper limit for threads within the process is: 514960 is calculated as 512g/10m = 512*1024m/10m = 52428.8 and the system shows a large gap, this reason is unknown. There is time for further verification.

Linux multithreaded Programming-thread exit

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.