Pthread_create memory usage (pthread BUG?)

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Pthread_create memory usage (pthread BUG?)

Bin Chen(sunwen_ling)
I wrote a simple program that spawn a lot of threads using pthread,
after ran the program the memory usage of the process increase very
fast, soon it become:

cat /proc/5243/status abcde.

Name:   tthread
State:  S (sleeping)
SleepAVG:       88%
Tgid:   5243
Pid:    5243
PPid:   4804
TracerPid:      0
Uid:    1000    1000    1000    1000
Gid:    1000    1000    1000    1000
FDSize: 256
Groups: 4 20 24 25 29 30 44 46 109 111 114 116 1000
VmPeak:   116404 kB
VmSize:   116404 kB
VmLck:         0 kB
VmHWM:       488 kB
VmRSS:       488 kB
VmData:   114912 kB ***** why so high *****
VmStk:        88 kB
VmExe:         4 kB
VmLib:      1364 kB
VmPTE:        64 kB
Threads:        1
SigQ:   0/4294967295
SigPnd: 0000000000000000
ShdPnd: 0000000000000000
SigBlk: 0000000000000000
SigIgn: 0000000000000000
SigCgt: 0000000180000000
CapInh: 0000000000000000
CapPrm: 0000000000000000
CapEff: 0000000000000000
Cpus_allowed:   ff
Mems_allowed:   1


by cat /proc/<pid>/status.

uname -a
Linux binch-laptop 2.6.17-10-generic #2 SMP Fri Oct 13 18:45:35 UTC 2006
i686 GNU/Linux

 /lib/libc.so.6
GNU C Library development release version 2.4, by Roland McGrath et al.
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
Compiled by GNU CC version 4.1.2 20060928 (prerelease) (Ubuntu
4.1.1-13ubuntu5).
Compiled on a Linux 2.6.17-10 system on 2007-01-24.
Available extensions:
        crypt add-on version 2.1 by Michael Glad and others
        GNU Libidn by Simon Josefsson
        GNU libio by Per Bothner
        NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
        Native POSIX Threads Library by Ulrich Drepper et al
        BIND-8.2.3-T5B
Thread-local storage support included.
For bug reporting instructions, please see:
<http://www.gnu.org/software/libc/bugs.html>.

List program below:

#include <pthread.h>

pthread_t my_thread;

void thread_proc(void)
{
    printf("abcde.\n");
}

int main(void)
{
    int i;

    for (i = 0;i < 1024;i ++)
    {
        if (pthread_create(&my_thread, NULL, &thread_proc, NULL) != 0)
        {
            printf("pthread create error.\n");
            exit(0);
        }
        sleep(1);
    }
}

Reply | Threaded
Open this post in threaded view
|

Re: Pthread_create memory usage (pthread BUG?)

Jakub Jelinek
On Fri, Mar 02, 2007 at 07:18:56PM +0800, Bin Chen wrote:
> I wrote a simple program that spawn a lot of threads using pthread,
> after ran the program the memory usage of the process increase very
> fast, soon it become:
>
> cat /proc/5243/status abcde.

You are using default thread stack sizes, which is derived from ulimit -s
value, typically around 8MB or 10MB.  So if you create 1024 threads, that
would need 10GB of *virtual* memory.  There are several ways how you can
decrease the thread stack size, you can google around to find it out
or just look at man pages, this list is certainly not the right place
for such questions.

        Jakub