Red hat 6.1 contains memory leak under pthread?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi all.

Just see the following code I provide:

#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>

void * f(void * arg)
{
     /*
      * Only request 8 bytes. Call free() or not as your
      * will.
      */
     malloc(8);

     /* Prevent the thread exit(). */
     while (1)
        sleep(10000);
}

int main()
{
     pthread_t  id;
     int                i = 0;

     /*
      * Type ENTER key to create one thread. Just
      * watch `top' command to see VIRT column's value
      * change.
      */
     getchar();

     while (1)
     {
        printf ("create %d threads\n", ++i);
        pthread_create(&id, NULL, f, NULL);
        getchar();
     }
     return 0;
}

Complie it: gcc a.c -lpthread -Wall
Run ./a.out, and open `top' command to watch VIRT of a.out.
I saw some difference between RH 6.1 and RH 5.4. its behaviors are different.

1)
CPU: x86_64
OS kernel: Linux  2.6.32-131.0.15.el6.x86_64
OS release: Red Hat Enterprise Linux Server release 6.1 (Santiago)
gcc: gcc (GCC) 4.4.5 20110214 (Red Hat 4.4.5-6)

a) Run ./a.out
b) Every type ENTER key and one thread will be created, the VIRT of a.out will increase about 70MB
c) When I create 16 threads, the VIRT of a.out has already be up to 1190MB
d) But when the number of created thread is up to about 24 threads, and again create thread via typing
    ENTER key, the increase of VIRT of a.out is 10MB.

2)
CPU: x86_64
OS kernel: Linux localhost.localdomain 2.6.18-164.el5
OS release: Red Hat Enterprise Linux Server release 5.4 (Tikanga)
gcc: gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46)

Do the same step as above. But the increase of  the VIRT of a.out is 10MB but not 70MB at any step.

3)
CPU: x86_32
OS kernel: Linux  2.6.32-131.0.15.el6.i686
OS release: Red Hat Enterprise Linux Server release 6.1 (Santiago)
gcc: gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-46)

Do the same step as above. But the increase of  the VIRT of a.out is 10MB but not 70MB at any step.

SO, why the behavior is different. And I think, if the thread only request 8 bytes memory space, the OS
should not give him 70MB. If some applicate need create a thread pool contain 16 threads under x86_64
with RH6.1, and any request has not processed, the virtual memory has already been used 1GB. In fact,
under x86_64 with RH5.4 only 300MB virtual memory is enough at the beginning of the application running.

So any configuration should be done to prevent a thread use much more virtual memory(10MB, but not 70MB).
_______________________________________________
Redhat-devel-list mailing list
Redhat-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/redhat-devel-list

[Index of Archives]     [Kernel Newbies]     [Red Hat General]     [Fedora]     [Red Hat Install]     [Linux Kernel Development]     [Yosemite News]

  Powered by Linux