AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
 View Only
  • 1.  Is it a bug in libpthread.a?

    Posted Wed November 29, 2006 06:29 AM

    Originally posted by: SystemAdmin


    Hi, everyone. I encountered a strong problem. Need your help.

    I wrote a multithread program, it's a very simple one. Because the thread-routine doesn't do anything but only printf char 'a',sleep 2 seconds and then exit, so it supposed to use a fixed memory size.

    When running it, I found the memory that the process used is increasing with 4KB per time. At the beginning, it used 3992KB memory, and after 12 hours, it increased to 5648KB! It can't bear in a 24-hours running system.

    I had debugged it with dbx, this is info of one kthread:
    code
    Info for tid: 10232187
    {
    -Identification & Scheduler Info------------------------------
    ti_tid: 10232187 ti_pid: 1839476
    ti_pri: 60 ti_policy: 0
    ti_state: TSLEEP (before stopping)
    ti_flag: TTERM | TSUSP | TCDEFER | TCDISABLE
    ti_scount: 1 ti_cpu: 0
    ti_cpuid: -1 ti_affinity: 0
    ti_wtype: TWZOMB ti_wchan: 0x00000000

    ----------------Signal Management-----------------------------
    ti_sigmask: HUP INT QUIT ILL TRAP ABRT EMT FPE BUS SEGV SYS PIPE ALRM TERM URG TSTP CONT CHLD TTIN TTOU IO XCPU XFSZ 26 MSG WINCH PWR USR1 USR2 PROF DANGER VTALRM MIGRATE PRE VIRT 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 GRANT RETRACT SOUND SAK 64

    ti_sig: <none>

    ti_code: 0x00000000 ti_scp: 0x00000000
    ti_cursig: KILL
    ti_oldmask: <none>

    ti_stkb: 0x00000000 ti_ucontext: 0x00000000
    ti_sigsp: 0x00000000 ti_sigssz: 0x00000000

    -----------------------------------User Thread Mgmt-----------
    ti_userdata: 0x00000000 ti_errnopp: 0xf0641640
    ti_ustk: 0x2176b180

    ------------------------------------------------Miscellaneous-
    ti_ticks: 0 ti_dispct: 4
    ti_fpuct: 1 ti_watch: <none>
    ti_ru: (use kthread ru) ti_nice: 0x00000014
    [/code] }

    We can see ti_wtype is TWZOMB, and most of kthreads had this status.If it means a detached pthread will be a zomb after call pthread_exit or exit?

    Then I tried to recompile it in a linux platform(Suse10 gcc 4.0.2), and it's totally normal(always take 413032KB or 41616KB). So is there some memory resource couldn't be freed after thread exit in AIX environment?
    Environment: AIX 5.3 XLC 6.0
    complie with: xlC_r thread_test.cpp -o thread_test.cpp
    code
    //thread_test.cpp
    #include <pthread.h>
    #include <stdlib.h>
    #include <unistd.h>
    #include <stdio.h>

    void *thread_function(void *arg) {
    printf("a");
    fflush(stdout);
    sleep(2);
    pthread_exit(NULL);
    return NULL;
    }

    int main(void) {

    pthread_t mythread;
    pthread_attr_t attr ;
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr,PTHREAD_CREATE_DETACHED);

    // for( int i = 0; i<2000; i++)
    while(1)
    {
    for( int j=0; j<200; j++)
    {
    if ( pthread_create( &mythread, &attr, thread_function, NULL) ) {
    printf("error creating thread.");
    exit(-1);
    }
    }
    sleep(5);
    }

    pthread_attr_destroy(&attr);
    exit(0);
    }
    [/code]
    Thanks for any suggestion!!
    #AIX-Forum


  • 2.  Re: Is it a bug in libpthread.a?

    Posted Wed January 24, 2007 06:05 PM

    Originally posted by: dickdunbar


    It may be a bug in AIX 5.3. What maintenance level are you on?

    Your testcase runs fine on my AIX systems.

    $ oslevel -r
    5200-07
    5300-03
    $ lslpp -L bos.rte.libpthreads
    bos.rte.libpthreads 5.2.0.75 C F libpthreads Library
    bos.rte.libpthreads 5.3.0.30 C F libpthreads Library

    The 4K increase in memory is normal. AIX does a fair amount of work
    to build the pthread context. When you thread ends, it leaves the
    context around so it can be reused on the next pthread_create.
    Eventually, this memory growth will (should) stabilize.

    My interest in your problem is two-fold:
    1. I've seen this problem before, around AIX 5.1 timeframe, I think.
    My test case looks very much like yours.
    2. I'm seeing a similar problem for AIX 5.3 ML04, but I don't have
    a matching system to test.

    $ /usr/sbin/prtconf | grep Type
    Processor Type: PowerPC_POWER3
    CPU Type: 64-bit
    Kernel Type: 64-bit
    #AIX-Forum