Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
From: root <root@wizard.mit.edu>
Subject: pthread_create and memory limits
Date: 1998/03/16	[thread overview]
Message-ID: <6ejr56$3k3@senator-bedfellow.MIT.EDU> (raw)


The following code terminates on DU 4.0B 
with an ENOMEM in pthread_create
after generating 7 threads

#include <iostream.h>
#include <pthread.h>

#define MB 1048576

void *
do_something(void* ptr)
{
  sleep(2);
  return 0;
}

int
main(int argc, char** argv)
{
  const int nthreads = 8;
  int i;
  pthread_t* pthrd = new pthread_t[nthreads];

  char* buf = new char[140*MB];

  for( i=0; i<nthreads; i++)
    cout << "try to create thread " << i << endl;
  if(pthread_create(&(pthrd[i]), NULL, do_something, (void*)buf)){
    cout << errno << endl;
    return 1;
  }

  for(i=0; i<nthreads; i++)
    if(!pthread_join(pthrd[i],NULL))
      cout<<"thread "<<pthrd[i]<<" finished"<<endl;
}


Allocating 120MB instead of 140MB does 'solve' the problem.
The default ulimit (bash) output looks like:

bash$ ulimit -a
core file size (blocks)  unlimited
data seg size (kbytes)   131072
file size (blocks)       unlimited
max memory size (kbytes) 4123280
stack size (kbytes)      2048
cpu time (seconds)       unlimited
pipe size (512 bytes)    8
open files               4096
virtual memory (kbytes)  133120

however for this process the data seg size has been increased
(otherwise the new[140*MB] would already fail)

core file size (blocks)  unlimited
data seg size (kbytes)   1000000
file size (blocks)       unlimited
max memory size (kbytes) 4123280
stack size (kbytes)      30000
cpu time (seconds)       unlimited
pipe size (512 bytes)    8
open files               4096
virtual memory (kbytes)  1030000


The relevant parts of an strace on the process:

execve("./pthr-test", ["./pthr-test"], [/* 18 vars */]) = 0
getpagesize()                           = 0x2000
getpagesize()                           = 0x2000
getrlimit(RLIMIT_DATA, {rlim_cur=1000000*1024, rlim_max=1048576*1024}) = 0
mmap(0x3ffc0004000, 8192, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0) = 0x3ffc0004000
getrlimit(RLIMIT_DATA, {rlim_cur=1000000*1024, rlim_max=1048576*1024}) = 0
mmap(0x3ffc0006000, 16384, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANONYMOUS|MAP_PRIVATE, -1, 0) = 0x3ffc0006000
[...]
getpagesize()                           = 0x2000
obreak(0x14000e340)                     = 0
getpagesize()                           = 0x2000
getsysinfo(0x37, 0x11ffffba0, 0x4, 0, 0) = 1
obreak(0x14001c340)                     = 0
mprotect(0x140012000, 8192, PROT_NONE)  = 0
obreak(0x14002a340)                     = 0
mprotect(0x14001e000, 8192, PROT_NONE)  = 0
[...]
write(1, "try to create thread 5\n", 23try to create thread 5) = 23
write(1, "try to create thread 6\n", 23try to create thread 6) = 23
write(1, "try to create thread 7\n", 23try to create thread 7) = 23
obreak(0x149ac0340)                     = 0
mprotect(0x148cae000, 8192, PROT_NONE)  = -1 ENOMEM (Not enough space)

So it looks like if pthread_create forgot about the increased limits
on RLIMIT_DATA.

   Any comments, hints?

                 Wolfgang



             reply	other threads:[~1998-03-16  5:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-03-16  5:00 root [this message]
1998-03-17  5:00 ` pthread_create and memory limits linnartz
1998-03-19  5:00 ` Dave Butenhof
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox